Esempio n. 1
0
 public function __set($name, $value)
 {
     switch ($name) {
         case 'CommunityCards':
             $this->_communityCards = $value;
             break;
         case 'TrashCards':
             $this->_trashCards = $value;
             break;
         default:
             parent::__set($name, $value);
             break;
     }
 }
Esempio n. 2
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT pt.idgame, pt.title, pp.idplayer, pt.d, pt.sb, pt.bb, pt.seats, pt.blind, pt.iduser, pt.idspot\n                  FROM poker_tables AS pt\n             LEFT JOIN poker_players AS pp ON (pp.idtable = pt.idtable AND pp.pactive = 1)\n                 WHERE pt.idtable = '{$id}'\n              ORDER BY pp.position";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         $players = array();
         if ($result->idplayer != '') {
             $prev = false;
             do {
                 $player = PokerPlayer::getInstance($result->idplayer);
                 $player->prev = $prev;
                 if (is_object($prev)) {
                     $prev->next = $player;
                 }
                 $players[$player->position] = $player;
                 $prev = $player;
             } while ($result->next());
             $first = reset($players);
             $first->prev = $prev;
             $prev->next = $first;
         }
         // general information
         $this->info = array("game" => $result->idgame != 0 && $result->idgame != '' ? Poker::getInstance($result->idgame) : FALSE, "spot" => $result->idspot != 0 && $result->idspot != '' ? PokerSpot::getInstance($result->idspot) : FALSE, 'title' => $result->title, 'players' => $players, 'positions' => array('smallblind' => $result->sb, 'bigblind' => $result->bb, 'dealer' => $result->d), 'blinds' => array('big' => 2 * $result->blind, 'small' => $result->blind), 'seats' => $result->seats, 'user' => $result->iduser);
         $this->info['free'] = $this->info['seats'] - count($this->info['players']);
         $this->id = $id;
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT pa.idgame, pa.action, pa.params, pa.idtable, pa.idplayer, UNIX_TIMESTAMP(pa.timestamp) AS timestamp\n                  FROM poker_actions AS pa \n                 WHERE pa.idaction = '{$id}'";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         // general information
         $this->info = array("action" => $result->action, 'params' => unserialize($result->params), 'player' => $result->idplayer != '' && $result->idplayer != 0 ? PokerPlayer::getInstance($result->idplayer) : false, 'game' => Poker::getInstance($result->idgame), 'table' => PokerTable::getInstance($result->idtable), 'time' => $result->timestamp);
         $this->id = $id;
         return true;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Start a new game.
  */
 private function gameNew($table)
 {
     $player_change = FALSE;
     $new_game = $table->game == FALSE ? TRUE : FALSE;
     $players = array();
     // check for player leaves and joins
     foreach ($table->players as $key => $player) {
         if ($player->leave == TRUE || $player->stack == 0 && !is_object($table->spot)) {
             $table->removePlayer($key);
             $player->delete();
             $player_change = TRUE;
             // only one (or no) player left, so don't start a new game
             if (count($table->players) <= 1) {
                 $table->game = FALSE;
                 $table->save();
                 return FALSE;
             }
         } elseif ($player->join == TRUE) {
             $player->join = FALSE;
             $table->addPlayer($key);
             $player_change = TRUE;
         }
     }
     // create card deck and deal cards
     $objDeck = new PokerDeck();
     $objDeck->shuffle();
     foreach ($table->players as $player) {
         // erase last action
         $player->last_action = NULL;
         // spot: reset player stack
         if (is_object($table->spot)) {
             $player->stack = $table->spot->stacks[$player->position - 1] * $table->blinds['big'];
         }
         // deal cards: get card from range, if spot is set for this table
         if (is_object($table->spot) && count($table->spot->ranges[$player->position - 1]) > 0) {
             $range = new PokerRange($table->spot->ranges[$player->position - 1], $objDeck);
             $player->cards = $range->getRandomPair();
             foreach ($player->cards as $key => $value) {
                 $objDeck->removeCard($value);
             }
         } else {
             $player->cards = array($objDeck->next(), $objDeck->next());
         }
         $player->pot = 0;
         $player->save();
         $players[] = array('position' => $player->position, 'stack' => $player->stack, 'name' => $player->user->realname);
     }
     // create new game object.
     $game = new Poker($table);
     $game->flop = array($objDeck->next(), $objDeck->next(), $objDeck->next());
     $game->turn = $objDeck->next();
     $game->river = $objDeck->next();
     $game->save();
     // register game in table object
     $table->game = $game;
     // move D / SB / BB
     if (!is_object($table->spot)) {
         // normal: no spot set
         $table->movePositions($new_game);
     } else {
         // spot: move positions, until button is at the right player
         $table->movePositions($new_game);
         while ($table->positions['dealer'] != $table->spot->button + 1) {
             $table->movePositions(false);
         }
     }
     $table->save();
     // create corresponding action
     $action = new PokerAction($game, 'new', array('button' => $table->positions['dealer'], 'players' => $players));
     $action->save();
     // Blinds
     $this->postBlind($table->players[$table->positions['smallblind']], 'small');
     $this->postBlind($table->players[$table->positions['bigblind']], 'big');
     $this->gameDealCards($table, 'deal');
     // Transfer Spot Actions
     if (is_object($table->spot) && count($table->spot->actions) > 0) {
         foreach ($table->spot->actions as $saction) {
             // transform params (BB to real value)
             $params = array();
             foreach ($saction->params as $key => $value) {
                 $params[$key] = $table->blinds['big'] * $value;
             }
             $this->saveAction($table->players[$saction->player + 1], $saction->action, $params);
         }
     }
 }
Esempio n. 5
0
<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();
}
?>
</body>
</html>