php poker generated random results do not match what is expected-Collection of common programming errors
I have made a research on poker equities. What I did is use pokerstove program with some selected. And with that program calculated the equities using enumerate all method. So pokerstove results:
I also made a table where I store the random results:
CREATE TABLE poker_results
(
id int NOT NULL AUTO_INCREMENT,
matches_id int NOT NULL, -- just for filtering in case I will want another starting hands.
result varchar(255) NOT NULL,
winner_hands varchar(255) NOT NULL,
PRIMARY KEY (id)
)
The result column data looks like this: Jd,9d,Qh,5c,Kc – this represents the cards on board.
Winner_hands column data look like this: Ks-Ac,6c-Ad,3c-Ah (can be 1 hand won, can be all 8 hands won).
Here is the code which generates the results to database. Its on codeigniter framework. And also to not copy the whole poker.php, I just copy couple of functions which are used from it:
protected function get_probabilities($hands, $board_cards = array()) {
$players = count($hands);
$board = implode('', $board_cards);
$board = trim($board);
if (empty($board)) {
$board = '-';
}
$hx = '';
$hand_counter = 1;
foreach ($hands as $hand) {
$hx .= '&h' . $hand_counter++ . '=' . $hand[0] . $hand[1];
}
$url = 'http://' . $this->poker_server . '/?board=' . $board . $hx . '&auth=' . $this->auth;
//Output exm. string '0.1342, 0.2042, 0.13525, 0.52635'
//WAR!! check if alive
$result = $this->parse_url_link($url);
if (substr($result, 0, 3) == 'Err') {
$this->utils->logging('ERROR', 'Poker server authorization failed!');
}
//echo $result;
return array(
'hands' => $hands,
'prob' => explode(', ', $result),
'board' => $board_cards
);
}
// protected because in child class needed
protected function get_poker_winner($table_winners) {
$to_return = array();
foreach($table_winners['prob'] as $key => $val) {
if ($val > 0) {
$to_return[] = $table_winners['hands'][$key][0] . '-' . $table_winners['hands'][$key][1];
}
}
return $to_return;
}
poker_tests.php