public function __tostring()
 {
     if (null === self::$__tostring || !is_callable(self::$__tostring)) {
         self::$__tostring = create_function('$c', 'return \'<img src="/images/\'.$c->suit.\'_\'.$c->short.\'.gif" />\';');
     }
     return call_user_func(self::$__tostring, $this);
 }
Exemple #2
0
<pre><?php 
require 'inc.cls.cardgame.php';
require 'inc.cls.pokertexasholdem.php';
Card::$__tostring = function ($c) {
    return '<img suit="' . $c->suit . '" src="images/' . $c->suit . '_' . $c->short . '.gif" />';
};
$fStart = microtime(true);
$iRounds = isset($_GET['rounds']) ? max(10, (int) $_GET['rounds']) : 1500;
echo $iRounds . " rounds\n\n";
$objDeck = new Deck();
$arrPlayers = array(array(new Card(26), new Card(0)), array(new Card(40), new Card(45)));
$arrWinner = array(0, 0);
for ($i = 0; $i < $iRounds; $i++) {
    $objDeck->replenish();
    $arrPublic = array_slice($objDeck->cards, 0, 5);
    $arrPublic[5] = $arrPlayers[0][0];
    $arrPublic[6] = $arrPlayers[0][1];
    $a = pokertexasholdem::score($arrPublic);
    $arrPublic[5] = $arrPlayers[1][0];
    $arrPublic[6] = $arrPlayers[1][1];
    $b = pokertexasholdem::score($arrPublic);
    $arrWinner[$a > $b ? 0 : 1]++;
}
echo implode(' ', $arrPlayers[0]) . ' vs ' . implode(' ', $arrPlayers[1]) . "\n\n";
echo $arrWinner[0] . ' (' . round($arrWinner[0] / $iRounds * 100, 2) . ' %) vs ' . $arrWinner[1] . ' (' . round($arrWinner[1] / $iRounds * 100, 2) . " %)\n\n";
$fParseTime = microtime(true) - $fStart;
echo number_format($fParseTime, 4) . ' s';
Exemple #3
0
<?php

// BLACKJACK COUNTING CARDS
require_once 'inc.cls.cardgame.php';
Card::$__tostring = function ($objCard) use(&$iCount, &$arrCardPoints) {
    return '<img class="future" src="/images/' . $objCard->suit . '_' . $objCard->short . '.gif" data-pt="' . $arrCardPoints[$objCard->short] . '" count="' . $iCount . '" title="So far: ' . $iCount . '" />';
};
$arrCardPoints = array('2' => 1, '3' => 1, '4' => 1, '5' => 1, '6' => 1, '7' => 0, '8' => 0, '9' => 0, '10' => -1, 'j' => -1, 'q' => -1, 'k' => -1, 'a' => -1);
$g_fStartUtc = microtime(1);
$iDecks = 6;
$deck = new Deck();
while (count($deck->cards) < $iDecks * 52) {
    $deck->add_deck(new Deck());
}
$deck->shuffle();
echo "<p>{$iDecks} decks, randomly ordered:</p>\n";
$iCount = 0;
foreach ($deck->cards as $i => $objCard) {
    $iCount += $arrCardPoints[$objCard->short];
    echo $objCard . "\n";
}
?>

<style>
img.future { display: none; }
img.present { display: inline; visibility: visible; }
img.past { visibility: hidden; }

body.show-past img.past { visibility: visible; }
body.show-all img { display: inline; visibility: visible; }