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; }
/** * @return Card|bool */ public function dealCard() { $ranks = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K']; $suits = ['♠', '♥', '♦', '♣']; //return $this->newCard('2', '♣'); if ($this->Hand->hasCards()) { do { $Card = $this->newCard($ranks[mt_rand(0, 12)], $suits[mt_rand(0, 3)]); } while ($this->Hand->countCardInstances($Card) < $this->no_decks); $this->Hand->removeCard($Card); return $Card; } return false; }
/** * @return Hand */ public function nextHand() { if (!$this->won) { $this->prevHand = Hand::getHand(mt_rand(0, 2)); } return $this->prevHand; }
/** * 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; } }
/** * @return Hand */ public function nextHand() { $bet = mt_rand(0, $this->getSum($this->currentHandValue)); if ($bet < $this->history[$this->currentHandValue][0]) { $handValue = Hand::GUU; } elseif ($bet < $this->history[$this->currentHandValue][0] + $this->history[$this->currentHandValue][1]) { $handValue = Hand::CHO; } else { $handValue = Hand::PAA; } $this->prevHandValue = $this->currentHandValue; $this->currentHandValue = $handValue; return Hand::getHand($handValue); }
/** * 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; } }
<link rel="stylesheet" media="screen" type="text/css" href="poker.css" /> </head> <body> <?php /** * *@author bibby <*****@*****.**> $Id$ ** //*/ require_once 'Poker.class.php'; $quota = 4; while ($quota--) { //** $D = new Deck(); $Hand = new Hand(); foreach (range(1, 7) as $i) { $Hand->add($D->draw()); } //*/ /** $Hand = new Hand(); $Hand->add( new Card(2,1) ); $Hand->add( new Card(3,1) ); $Hand->add( new Card(4,1) ); $Hand->add( new Card(5,1) ); $Hand->add( new Card(6,1) ); $Hand->add( new Card(7,2) ); $Hand->add( new Card(8,1) ); //*/ $div = new HTMLTag("div", $Hand->rank(), array("class" => "row"));
public function testCompareTo() { // standard win/loss $hand1 = new Hand(); $hand1->add(new Card(new Rank(5))); $hand1->add(new Card(new Rank(7))); $hand2 = new Hand(); $hand2->add(new Card(new Rank(9))); $hand2->add(new Card(new Rank(9))); $this->assertTrue($hand1->compareTo($hand2) == Hand::LOSE); $this->assertTrue($hand2->compareTo($hand1) == Hand::WIN); // with soft ace $hand1 = new Hand(); $hand1->add(new Card(new Rank(RANK::ACE))); $hand1->add(new Card(new Rank(8))); $hand2 = new Hand(); $hand2->add(new Card(new Rank(9))); $hand2->add(new Card(new Rank(9))); $this->assertTrue($hand1->compareTo($hand2) == Hand::WIN); $this->assertTrue($hand2->compareTo($hand1) == Hand::LOSE); // another with soft ace $hand1 = new Hand(); $hand1->add(new Card(new Rank(4))); $hand1->add(new Card(new Rank(RANK::QUEEN))); $hand1->add(new Card(new Rank(RANK::ACE))); $hand1->add(new Card(new Rank(3))); $hand2 = new Hand(); $hand2->add(new Card(new Rank(8))); $hand2->add(new Card(new Rank(3))); $hand2->add(new Card(new Rank(5))); $this->assertTrue($hand1->compareTo($hand2) == Hand::WIN); $this->assertTrue($hand2->compareTo($hand1) == Hand::LOSE); // push with soft ace $hand1 = new Hand(); $hand1->add(new Card(new Rank(4))); $hand1->add(new Card(new Rank(RANK::ACE))); $hand1->add(new Card(new Rank(3))); $hand2 = new Hand(); $hand2->add(new Card(new Rank(8))); $hand2->add(new Card(new Rank(3))); $hand2->add(new Card(new Rank(7))); $this->assertTrue($hand1->compareTo($hand2) == Hand::PUSH); $this->assertTrue($hand2->compareTo($hand1) == Hand::PUSH); // bust $hand1 = new Hand(); $hand1->add(new Card(new Rank(RANK::KING))); $hand1->add(new Card(new Rank(8))); $hand1->add(new Card(new Rank(RANK::KING))); $hand2 = new Hand(); $hand2->add(new Card(new Rank(9))); $hand2->add(new Card(new Rank(9))); $this->assertTrue($hand1->compareTo($hand2) == Hand::LOSE); $this->assertTrue($hand2->compareTo($hand1) == Hand::WIN); }
<head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="poker.css" /> </head> <body> <?php require_once 'Poker.class.php'; $D = new Deck(); $Table = new Hand(); foreach (range(1, 5) as $i) { $Table->add($D->draw()); } $players = range(1, 5); foreach ($players as $k => $v) { $hole = new Hand(); $hole->add($D->draw()); $hole->add($D->draw()); $players[$k] = $hole; } $center = new HTMLTag("center", $Table->show()); echo $center->parse(); echo "\n<hr />\n"; $full = array(); $WIN = Poker::rankHands($Table, $players, $full); echo "<h2>" . intval(count($WIN)) . " winner(s)</h2>\n\n"; foreach ($players as $i => $h) { $out = Tpl::string('<div class="container{WINNER}">{HAND}<br />{EVAL}</div>'); $win = in_array($i, $WIN); $out->setAttribs(array('WINNER' => $win ? ' winner' : '', 'HAND' => $h->show(), 'EVAL' => $full[$i]->rankName() . "<br />" . $full[$i]->printRun())); echo $out->parse();
function merge($hand) { $Hand = new Hand(); foreach (array($this, $hand) as $H) { foreach ($H->cards as $c) { $Hand->addCard($c); } } return $Hand; }
function printTable($starter, $hands) { global $players; $starter = Hand::normalizeCards($starter); $out = '<tr><td>Starter:</td><td><input class="resettable" value="' . $starter . '" id="starter" name="starter" type="text" size="1" />'; $out .= "</td><td></td></tr>\n"; for ($p = 0; $p <= $players; $p++) { $score = new Hand($starter, $hands[$p]); $out .= "<tr><td>"; $out .= ($p == 0 ? 'Crib' : "Player {$p}") . ":</td><td>"; $out .= '<input class="resettable" type="text" value="' . $score->printHand() . '" name="hands[' . $p . ']" /></td><td>'; $out .= $score->printScore() . "</td></tr>\n"; } return $out; }
/** * Return the player's Hand score, used to calculate the ranking * * @return integer */ public function getHandScore() { return $this->_hand->getHandScore(); }