Пример #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';
Пример #2
0
<body class="show-winners">

<?php 
$arrPublic = $arrPlayers = array();
for ($i = 1; $i <= $iPlayers; $i++) {
    $arrPlayers[$i] = array();
    array_push($arrPlayers[$i], $objDeck->next());
    array_push($arrPlayers[$i], $objDeck->next());
}
while (5 > count($arrPublic)) {
    array_push($arrPublic, $objDeck->next());
}
$arrHands = array();
foreach ($arrPlayers as $s => $cards) {
    $arrHands[$s] = pokertexasholdem::score(array_merge($arrPublic, $cards));
}
$fWinner = max($arrHands);
$arrWinners = array_keys($arrHands, $fWinner);
list($arrWinnerCards, $szWinnerSuit) = pokertexasholdem::winnerCardsAndSuit($fWinner);
?>
<table>
	<tr valign="middle">
		<?php 
printSeat(5);
?>
		<?php 
printSeat(1);
?>
		<?php 
printSeat(6);
Пример #3
0
	new Card(0),
	new Card(3),
	new Card(7),
	new Card(6),
);
$arrPlayers[0] = array(
	new Card(5),
	new Card(4),
);
/* test */
require_once 'inc.cls.pokertexasholdem.php';
$bNothingWorthy = true;
$fMaxHand = 0;
$arrHands = array();
foreach ($arrPlayers as $k => $arrPlayer) {
    $fHand = pokertexasholdem::score(array_merge($arrPublic, $arrPlayer));
    $arrHands[$k] = $fHand;
    if ((double) $fHand > $fMaxHand) {
        $fMaxHand = (double) $fHand;
    }
    if ((double) LOWEST_WORTHY_HAND <= (double) $fHand) {
        $bNothingWorthy = false;
    }
}
if (!empty($_GET['plain'])) {
    if ($bNothingWorthy) {
        echo '<meta http-equiv="refresh" content="0" />';
    }
    echo '<title>' . $fMaxHand . '</title>';
    echo '<pre>' . $fMaxHand . '</pre>';
    echo '<pre>' . number_format(microtime(1) - $fUtcStart, 4) . '</pre>';
Пример #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);
Пример #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;
}