public function testCanBeNegated() { $hand = new Hand(); for ($i = 0; $i < 13; $i++) { $hand->addCard($deck->dealCard()); } print $hand->getHandCount(); }
/** * @param \Application\Model\Hand $hand * @return \Application\Model\GameSession */ public function addCard(Hand $hand) { if (!$hand->isCompleted() && !$this->isFinished()) { $card = array_shift($this->deck); $value = $this->cards[$card]; $hand->addCard($card, $value); } return $this; }
/** * Give the player one card. Check if the hand value is now over 21. * If so, return true, otherwise return false. * @param class Deck $deck * @return boolean */ public function hitMe($deck) { parent::addCard($deck); $value = parent::calcValue(); if ($value > 21) { return true; } else { return false; } }
/** * Deck constructor. * @param $no_decks * @param Hand|NULL $dealt_cards */ public function __construct($no_decks, Hand $dealt_cards = NULL) { $ranks = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K']; $suits = ['♠', '♥', '♦', '♣']; $this->no_decks = $no_decks; $this->Hand = $this->newHand(); for ($deck = 1; $deck <= $no_decks; $deck++) { foreach ($suits as $suit) { foreach ($ranks as $rank) { $Card = $this->newCard($rank, $suit); if (isset($dealt_cards)) { if ($this->Hand->countCardInstances($Card) < $no_decks - $dealt_cards->countCardInstances($Card)) { $this->Hand->addCard($Card); } } else { $this->Hand->addCard($Card); } } } } }
/** * Give the dealer cards until hand value is 17 or higher. * Check if the hand value is now over 21. * If so, return true, otherwise return false. * @param class Deck $deck * @return boolean */ public function hitDealer($deck) { // Add cards to the hand while (parent::calcValue() < 17) { parent::addCard($deck); } // Check if dealer busts $value = parent::calcValue(); if ($value > 21) { return true; } else { return false; } }
function merge($hand) { $Hand = new Hand(); foreach (array($this, $hand) as $H) { foreach ($H->cards as $c) { $Hand->addCard($c); } } return $Hand; }