ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; //TODO: Double the bet. $isSuccessfullyAdded = $this->hands[$handIndex]->AddCard($card); if($isSuccessfullyAdded) $this->hands[$handIndex]->Lock(); return $isSuccessfullyAdded; } public function CanSplit($handIndex) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; $maxHandsPerPlayer = $this->config->maxHandsPerPlayer; if(count($this->hands) < $maxHandsPerPlayer && $this->hands[$handIndex]->CanSplit()) return true; return false; } public function SplitHand($handIndex, Card $newCard1, Card $newCard2) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; if(!$this->CanSplit($handIndex)) return new Error(E_BJ_CANNOT_SPLIT); list($newHand1, $newHand2) = $this->hands[$handIndex]->Split(); if(get_class($newHand2) == BJ_ERROR_CLASS_NAME) return $newHand2; //Add one card into each hand now. $isSuccessfullyAddedToHand1 = $newHand1->AddCard($newCard1); if($isSuccessfullyAddedToHand1) { $isSuccessfullyAddedToHand2 = $newHand2->AddCard($newCard2); if($isSuccessfullyAddedToHand2) { $this->hands[$handIndex] = $newHand1; array_push($this->hands, $newHand2); } else { return $isSuccessfullyAddedToHand2; } } //Control would reach here with $isSuccessfullyAddedToHand1 as true only if we could add to both //hands successfully. return $isSuccessfullyAddedToHand1; } public function GetHand($handIndex) { $isHandValid = $this->ValidateHandIndex($handIndex); if($isHandValid instanceof Error) return $isHandValid; return $this->hands[$handIndex]; } public function DeleteHand($handIndex) { unset($this->hands[$handIndex]); } }