gpt4 book ai didi

php poker 生成的随机结果与预期不符

转载 作者:可可西里 更新时间:2023-11-01 12:20:12 25 4
gpt4 key购买 nike

我对扑克股票进行了研究。我所做的是使用 pokerstove 程序选择一些。并使用该程序使用枚举所有方法计算股票。所以扑克炉结果:

enter image description here

我还制作了一个表格来存储随机结果:

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)
)

结果列数据如下所示:Jd,9d,Qh,5c,Kc - 这代表板上的牌。

Winner_hands 列数据如下所示:Ks-Ac,6c-Ad,3c-Ah(可以是 1 手获胜,也可以是全部 8 手获胜)。

这是将结果生成到数据库的代码。它在 codeigniter 框架上。而且为了不复制整个 poker.php,我只复制了几个从中使用的函数:

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

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


include_once(APPPATH . 'controllers/poker.php');
require_once APPPATH . "libraries/downloaded/Mersenne_twister.php";
use mersenne_twister\twister;

class Poker_tests extends Poker {

public function __construct() {
parent::__construct();
}

/**
* Generates data in database with such structure:
* CREATE TABLE matches
* (
* id int NOT NULL AUTO_INCREMENT,
* player_cards varchar(255) NOT NULL,
*
* PRIMARY KEY (ID)
* )
*
* CREATE TABLE poker_results
* (
* id int NOT NULL AUTO_INCREMENT,
* result varchar(255) NOT NULL,
* PRIMARY KEY (id)
* )
*
*
* Here 1 match will have many results, because we use same preflop cards.
*
* Text results appended to pokerstove.txt
*
* 376,992 games 0.013 secs 28,999,384 games/sec
*
* Board:
* Dead:
*
* equity win tie pots won pots tied
* Hand 0: 20.925% 20.53% 00.40% 77382 1504.50 { KhQs }
* Hand 1: 06.215% 03.50% 02.72% 13190 10239.00 { 9c4d }
* Hand 2: 06.396% 04.08% 02.32% 15379 8734.00 { 8d4c }
* Hand 3: 18.906% 18.15% 00.76% 68426 2847.50 { AcKs }
* Hand 4: 08.767% 06.91% 01.86% 26032 7019.50 { 9h2c }
* Hand 5: 10.204% 09.83% 00.38% 37044 1424.00 { Ad6c }
* Hand 6: 09.046% 08.67% 00.38% 32678 1424.00 { Ah3c }
* Hand 7: 19.541% 18.08% 01.46% 68154 5514.50 { 8c7c }
*
*
* ---
*
*
*/
public function run() {

$this->benchmark->mark('start');

$this->output->enable_profiler(TRUE);

//close the current connection, because its not needed
$this->db->close();

$db_poker = $this->load->database('poker_test', TRUE);

$sql = "INSERT INTO poker_results (result, winner_hands, matches_id) VALUES (?, ?, ?)";

// matches_id = 1. Insert new match
$table8_hands = 'Kh,Qs,4d,9c,4c,8d,Ks,Ac,2c,9h,6c,Ad,3c,Ah,7c,8c'; // do test with this. Do those win the right amount of time?

for ($i=0; $i < 400000; $i++) { // pradejus id 100194

$flop = $this->poker_flop($table8_hands);
$turn = $this->poker_turn($flop, $table8_hands);
$river = $this->poker_stop($turn, $table8_hands);
//echo json_encode($river) . '<br>';

$db_poker->query($sql, array($river['river_board'], implode(',', $river['winner_hands8']), 2));
}

$db_poker->close();

$this->benchmark->mark('end');
echo $this->benchmark->elapsed_time('start', 'end') . '<br>';
}





/**
*
* Override - remove unneeded things for test from that function in poker.php
* Generates 3 flop cards
*/
public function poker_flop($table8_hands) {


$table8_cards = explode(',', $table8_hands);

$table8_results = $this->random_result($table8_cards, 3);

return $table8_results;

}

/**
* Generates 1 turn card
* @param $table8_hands - same as match score in database. But here we have hardcoded in run function
*
*/
public function poker_turn($table8_flop, $table8_hands) {

$table8_cards = explode(',', $table8_hands);

//Join players cards and opened board cards
$table8_reserved_cards = array_merge($table8_cards, $table8_flop);

//Pass all opened cards and get one new board card
$table8_results = $this->random_result($table8_reserved_cards, 1);

//Merge all opened board cards
$table8_results = array_merge($table8_flop, $table8_results);

// this is flop and turn both
return $table8_results;

}

/**
*
* Generates 1 river card
*/
public function poker_stop($table8_flop_turn, $table8_hands) {

$table8_cards = explode(',', $table8_hands);

$table8_reserved_cards = array_merge($table8_cards, $table8_flop_turn);

$table8_results = $this->random_result($table8_reserved_cards, 1);

$table8_results = array_merge($table8_flop_turn, $table8_results);


$table8_hands = $this->array_to_hands_array($table8_cards);

$flop_turn_results = implode(',', $table8_results);

// $this->benchmark->mark('code_start');
//Get new probabilities - they will be needed to determine if hand has won or not. When prob. > 0 - then won
$table8_prob = $this->get_probabilities($table8_hands, $table8_results);

// $this->benchmark->mark('code_end');
// echo $this->benchmark->elapsed_time('code_start', 'code_end');

return array(
'winner_hands8' => $this->get_poker_winner($table8_prob),
'river_board' => $flop_turn_results
);

}


/**
* for second generation - new random function
* @param array $reserved_cards
* @param integer $cards_amount
* @return array
*/
protected function random_result($reserved_cards, $cards_amount = 5) {

$card_types = array('s', 'c', 'h', 'd');
$card_values = array('A', 2, 3, 4, 5, 6, 7, 8, 9, 'T', 'J', 'Q', 'K');

$deck = array();
foreach ($card_values as $value) {
foreach ($card_types as $type) {
$deck[] = $value . $type;
}
}

$remaining_deck = array_diff($deck, $reserved_cards);
// make keys sequence:
$remaining_deck = array_values($remaining_deck);

$results = array();

while (count($results) != $cards_amount) {

$rand_card_key = $this->random(0, (count($remaining_deck) - 1));

$results[] = $remaining_deck[$rand_card_key];

// remove from deck
unset($remaining_deck[$rand_card_key]);
// make keys sequence:
$remaining_deck = array_values($remaining_deck);
}

return $results;
}


/**
* Picks random element from range
* @param integer $from
* @param integer $to
* @return integer
*/
private function random($from, $to) {

if (file_exists('/dev/urandom')) {
$twister4 = new twister;
$twister4->init_with_file("/dev/urandom", twister::N);

return $twister4->rangeint($from, $to);
}
else {
return mt_rand($from, $to);
}
}
}

正如我们在 random 函数中看到的那样 - 当我在 linux 上进行测试时,我将 twister 库与 linux dev/urnadom 一起使用,而当我在 windows 上进行测试时,我将使用 native mt_rand。没有注意到差异。

所以为了选择结果,我使用这样的查询:

获取结果总数

select count(*) from poker_results where matches_id = 2 and id < 296351 

得到手牌的总赢(赢+平)是多少:

select count(*) from poker_results where matches_id = 2 and id < 296351 and winner_hands like '%Kh-Qs%' 

要得到多少手牌:

select count(*) from poker_results where matches_id = 2 and id < 296351 and winner_hands like '%Kh-Qs%' and winner_hands != 'Kh-Qs'

扑克服务器是为了获取手牌权益。通过河牌胜率,我确定手牌是否赢了 - 当手牌胜率 > 0 时,它赢了。

此工具在另一台服务器上使用 - 有运行 python 程序的 php 代码,但在这里无关紧要。

http://pokersleuth.com/programmable-poker-calculator.shtml

该工具类似于 pokerstove,但它具有命令行版本。顺便说一句,不要买这个工具,我们买了但他们没有发送许可证 key ,就像他们不在乎一样。

现在结果:

https://docs.google.com/spreadsheet/pub?key=0ArMZCQvNc-oQdEs0a1UyMkFGazVoN09KZmU1Q0FCU0E&output=html&richtext=true

现在,如果我们进行比较,手牌获胜 + 平手的次数比 pokerstove 或 pokersleuth 显示的胜率更高。当我看 ant tie % - 它比扑克炉显示大得多。样本不是那么小。 Pokerstove 使用了将近 40 万场比赛,虽然少了一点,但趋势保持不变。首先,我尝试了更小的样本,比如 10K 游戏——同样的趋势。因此,当我再生成 100K 时,如果结果保持大致相同,我并不感到惊讶。此示例也是在 linux 上生成的。但是在 Windows 上也生成了大约相同的样本,但获胜次数仍然多于扑克牌显示,获胜百分比的总和也是 110-112%。

所以我们不理解 - 我是不是生成了错误的东西或者那些程序显示错误?显示错误 Assets 的程序不太可能,因为它们被广泛使用并且可能应该已经进行了大量测试。

更新:

I think I finally understood :) Pokersleuth computes the chances of ahand (two cards) winning knowing the 5 cards on the board. You arethen comparing these chances to the real outcome (knowing the hands ofall the other players). Right?

没错。我不得不写在这里,因为它不允许在评论中进行扩展讨论。

更新:

生成了更多行 - 当前在 Linux 服务器上为 515989,% 仍然与以前大致相同。所以不动

最佳答案

您生成了 296350 个结果,但 332911 次获胜和平局。

这个过程的任何部分是否调和了这样一个事实,即当出现平局时,它是在两只或更多只手之间?看起来领带被高估了。

计算您的总赢率和平局百分比,112.3371014%。相乘(生成的结果除以胜负数)。你会得到恰好 100%。这说明什么?

另外,看看 Ad6c 和 Ah3c。他们的平手数完全相同,而且很可能是同一手牌(获胜的是一对 A)。

但对于打平的手牌,该手牌会计算/加权两次(一次用于 Ad6c,一次用于 Ah3c)。这就是为什么您的领带百分比至少是应有的两倍。您必须根据打平的手数将平局计数归一化

关于php poker 生成的随机结果与预期不符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21982542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com