config = $config; $this->shoe = new Shoe($config); $this->tableState = BJ_TABLE_TURN_PLAYER; $playerHand = new Hand(); $dealerHand = new Hand(); $playerHand->AddCard($this->shoe->PickCard()); $playerHand->AddCard($this->shoe->PickCard()); $dealerHand->AddCard($this->shoe->PickCard()); $this->player = new Player($config, $playerHand, $playerName); $this->dealer = new Dealer($config, $dealerHand, $this->shoe->PickCard()); } public function GetShoe() { return $this->shoe; } public function UpdateTableState($playerHandIndex) { if($this->player->GetHand($playerHandIndex)->IsBusted()) { //Player bust, dealer wins. return Dealer Object. $this->player->GetHand($playerHandIndex)->SetState(BJ_HAND_LOST); $this->dealer->SetState(BJ_HAND_WON); } elseif($this->tableState == BJ_TABLE_TURN_DEALER) { $playerHand = $this->player->GetHand($playerHandIndex); $playerSum = $playerHand->GetSum(); $dealerSum = $this->dealer->GetSum(); while($dealerSum < 17) { $isHitSuccessful = $this->dealer->Hit($this->shoe->PickCard()); if($isHitSuccessful instanceof Error) return $isHitSuccessful; $dealerSum = $this->dealer->GetSum(); } if($dealerSum > 21) { //dealer bust, player wins $playerHand->SetState(BJ_HAND_WON); $this->dealer->SetState(BJ_HAND_LOST); } elseif($playerSum < $dealerSum) { $playerHand->SetState(BJ_HAND_LOST); $this->dealer->SetState(BJ_HAND_WON); } elseif($playerSum > $dealerSum) { $playerHand->SetState(BJ_HAND_WON); $this->dealer->SetState(BJ_HAND_LOST); } elseif($playerSum == $dealerSum) { $playerHand->SetState(BJ_HAND_DRAW); $this->dealer->SetState(BJ_HAND_DRAW); } } } public function GetTableState() { //Make sure none of the hands of the player is in Stand state. If it is, game has not ended. foreach($this->player->hands as $hand) { if($hand->GetState() == BJ_HAND_IN_PROGRESS || $hand->GetState() == BJ_HAND_STAND) return BJ_TABLE_IN_PROGRESS; } return BJ_TABLE_ENDED; } public function SetDealerTurn() { $this->tableState = BJ_TABLE_TURN_DEALER; } }