{"id":7182,"date":"2014-05-27T08:58:53","date_gmt":"2014-05-27T08:58:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/php-poker-generated-random-results-do-not-match-what-is-expected-collection-of-common-programming-errors\/"},"modified":"2014-05-27T08:58:53","modified_gmt":"2014-05-27T08:58:53","slug":"php-poker-generated-random-results-do-not-match-what-is-expected-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/27\/php-poker-generated-random-results-do-not-match-what-is-expected-collection-of-common-programming-errors\/","title":{"rendered":"php poker generated random results do not match what is expected-Collection of common programming errors"},"content":{"rendered":"<p>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:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/iHViz.png\" \/><\/p>\n<p>I also made a table where I store the random results:<\/p>\n<pre><code>CREATE TABLE poker_results\n(\nid int NOT NULL AUTO_INCREMENT,\nmatches_id int NOT NULL,  -- just for filtering in case I will want another starting hands.\nresult varchar(255) NOT NULL,\nwinner_hands varchar(255) NOT NULL,\nPRIMARY KEY (id)\n) \n<\/code><\/pre>\n<p>The result column data looks like this: Jd,9d,Qh,5c,Kc &#8211; this represents the cards on board.<\/p>\n<p>Winner_hands column data look like this: Ks-Ac,6c-Ad,3c-Ah (can be 1 hand won, can be all 8 hands won).<\/p>\n<p>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:<\/p>\n<pre><code>protected function get_probabilities($hands, $board_cards = array()) {\n        $players = count($hands);\n\n        $board = implode('', $board_cards);\n        $board = trim($board);\n        if (empty($board)) {\n            $board = '-';\n        }\n        $hx = '';\n        $hand_counter = 1;\n\n        foreach ($hands as $hand) {\n            $hx .= '&amp;h' . $hand_counter++ . '=' . $hand[0] . $hand[1];\n        }\n\n        $url = 'http:\/\/' . $this-&gt;poker_server . '\/?board=' . $board . $hx . '&amp;auth=' . $this-&gt;auth;\n\n\n\n        \/\/Output exm. string '0.1342, 0.2042, 0.13525, 0.52635'\n        \/\/WAR!! check if alive\n        $result = $this-&gt;parse_url_link($url);\n\n        if (substr($result, 0, 3) == 'Err') {\n            $this-&gt;utils-&gt;logging('ERROR', 'Poker server authorization failed!');\n        }\n\n        \/\/echo $result;\n\n        return array(\n            'hands' =&gt; $hands,\n            'prob' =&gt; explode(', ', $result),\n            'board' =&gt; $board_cards\n        );\n    }\n\n\n\/\/ protected because in child class needed\n    protected function get_poker_winner($table_winners) {\n        $to_return = array();\n        foreach($table_winners['prob'] as $key =&gt; $val) {\n            if ($val &gt; 0) {\n                $to_return[] = $table_winners['hands'][$key][0] . '-' . $table_winners['hands'][$key][1];\n            }\n        }\n\n        return $to_return;\n    }\n<\/code><\/pre>\n<p>poker_tests.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7182","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7182"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7182\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}