Example #1
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';
Example #2
0
function printSeat($s)
{
    global $arrPlayers, $arrPublic, $arrHands, $arrWinners;
    if (isset($arrPlayers[$s])) {
        $szCards = cardImgs($arrPlayers[$s]);
        $szTitle = ' (' . pokertexasholdem::readable_hand($arrHands[$s]) . ' (' . $arrHands[$s] . '))';
        $szClass = in_array($s, $arrWinners) ? 'winner' : '';
    } else {
        $szCards = '';
        $szTitle = '';
        $szClass = '';
    }
    echo '<td class="seat ' . $szClass . '" title="Seat ' . $s . $szTitle . '">' . $szCards . '</td>' . "\n";
}
Example #3
0
    if (0 == $k) {
        echo '<td rowspan="' . count($arrPlayers) . '">' . implode(', ', $arrPublic) . '</td>';
        echo '<td rowspan="' . count($arrPlayers) . '">&nbsp;+&nbsp;</td>';
    }
    $fHand = $arrHands[$k];
    $szHand = $fHand;
    if ((double) LOWEST_WORTHY_HAND <= (double) $fHand) {
        $szHand = '<b class="worthy h' . str_replace('.', '_', (double) $fHand) . '">' . $szHand . '</b>';
    }
    echo '<td>' . implode(', ', $arrPlayer) . '</td>';
    echo '<td>&nbsp;=&nbsp;</td>';
    echo '<td>' . $szHand . '</td>';
    echo '<td>&nbsp;=&nbsp;</td>';
    echo '<td>' . pokertexasholdem::readable_hand($fHand) . '</td></tr>';
}
echo '<tr><td colspan="7" align="center"><b' . ($bNothingWorthy ? '' : ' style="color:yellow;"') . '>Winner</b>: ' . pokertexasholdem::readable_hand($m = max($arrHands)) . ' (' . $m . ')</td></tr>';
echo '</table>';
?>
<style type="text/css">.worthy{color:red;}table tr td b.h<?php 
echo str_replace('.', '_', (double) $m);
?>
{color:yellow;}</style><?php 
if ($bNothingWorthy) {
    echo '<meta http-equiv="refresh" content="0" />';
}
echo '<p>' . number_format($fTime = microtime(true) - $fUtcStart, 4) . '</p>';
?>
</body>

<title><?php 
echo $fMaxHand;
Example #4
0
<pre><?php 
require_once 'inc.cls.cardgame.php';
require_once 'inc.cls.pokertexasholdem.php';
card::$__tostring = function ($c) {
    return '<img title="' . $c->id . '" src="images/' . $c->suit . '_' . $c->short . '.gif" />';
};
if (!isset($_GET['cards']) || count($arrCards = array_map('intval', explode(',', $_GET['cards']))) < 3) {
    $arrCards = array(1, 40, 25, 38, 14, 12, 31);
}
$arrCards = array_map(function ($c) {
    return new Card($c);
}, $arrCards);
echo implode(' ', array_map('strval', $arrCards)) . "\n\n";
$hand = pokertexasholdem::score($arrCards, $o);
echo $hand . ' (' . pokertexasholdem::readable_hand($hand) . ")\n\n";
echo 'one pair     ' . ($o->one_pair() ? 'Y' : 'N') . "\n";
echo 'two pair     ' . ($o->two_pair() ? 'Y' : 'N') . "\n";
echo '3 of a kind  ' . ($o->three_of_a_kind() ? 'Y' : 'N') . "\n";
echo 'straight     ' . ($o->straight() ? 'Y' : 'N') . "\n";
echo 'flush        ' . ($o->flush() ? 'Y' : 'N') . "\n";
echo 'full house   ' . ($o->full_house() ? 'Y' : 'N') . "\n";
echo '4 of a kind  ' . ($o->four_of_a_kind() ? 'Y' : 'N') . "\n";
echo "\n";
print_r($o);
Example #5
0
function checkAndActOnAllSameBets($f_arrTable)
{
    $arrBets = getUserBets();
    if (1 == count($arrBets)) {
        // Only one player left
        $fTotalPot = db_select_one(TABLE_BETS . ' b, ' . TABLE_POOLS . ' po', 'SUM(bet)', 'b.pool_id = po.id AND po.table_id = ' . TABLE_ID);
        $iUserId = key($arrBets);
        db_update(TABLE_PLAYERS, 'balance = balance+' . $iUserId . ', last_action = \'Won ' . (double) $fTotalPot . '\' due to fold', 'table_id = ' . TABLE_ID . ' AND user_id = ' . $iUserId);
        db_update(TABLE_TABLES, 'state = 0', 'id = ' . TABLE_ID);
        return true;
    }
    $iReady = db_count(TABLE_PLAYERS, 'table_id = ' . TABLE_ID . ' AND in_or_out = \'in\'');
    if ($iReady == count($arrBets) && 1 == count(array_flip($arrBets))) {
        if (6 === (int) $f_arrTable['state']) {
            // Showdown
            $fTotalPot = db_select_one(TABLE_BETS . ' b, ' . TABLE_POOLS . ' po', 'SUM(bet)', 'b.pool_id = po.id AND po.table_id = ' . TABLE_ID);
            $arrPubCards = array(new Card($f_arrTable['public_card_1']), new Card($f_arrTable['public_card_2']), new Card($f_arrTable['public_card_3']), new Card($f_arrTable['public_card_4']), new Card($f_arrTable['public_card_5']));
            $arrWinners = array();
            $fMaxScore = 0.0;
            foreach ($arrBets as $iUserId => $b) {
                $p = db_select(TABLE_PLAYERS, 'table_id = ' . TABLE_ID . ' AND user_id = ' . $iUserId);
                $arrPrivCards = array(new Card($p[0]['private_card_1']), new Card($p[0]['private_card_2']));
                $fScore = pokertexasholdem::score(array_merge($arrPubCards, $arrPrivCards));
                if ($fScore > (double) $fMaxScore) {
                    $fMaxScore = $fScore;
                    $arrWinners = array();
                }
                if ((double) $fScore === (double) $fMaxScore) {
                    $arrWinners[] = $iUserId;
                }
            }
            $fUserWinnings = floor($fTotalPot * 100 / count($arrWinners)) / 100;
            db_update(TABLE_PLAYERS, 'balance = balance+' . $fUserWinnings . ', last_action = \'Won [' . $fUserWinnings . '] with a [' . pokertexasholdem::readable_hand($fMaxScore) . ']\'', 'table_id = ' . TABLE_ID . ' AND user_id IN (' . implode(',', $arrWinners) . ')');
            db_update(TABLE_TABLES, 'state = 0', 'id = ' . TABLE_ID);
            return true;
        }
        db_update(TABLE_PLAYERS, 'ready_for_next_round = \'0\'', 'table_id = ' . TABLE_ID);
        $f_arrTable['current_seat'] = $f_arrTable['dealer_seat'];
        saveNextSeat($f_arrTable, 'state+1');
        return true;
    }
    return false;
}