使用 pokerstove 库提高性能
Improving performance using pokerstove library
我最近开始使用 pokerstove 库 (https://github.com/andrewprock/pokerstove) 并成功地用它进行了一些基本的手牌/赢率评估。不幸的是,当我尝试编写计算量更大的程序时,我 运行 陷入了无法弄清楚如何处理的大量性能问题。
作为示例,我提供了以下程序来计算黑桃 A-6 手牌对抗完全 运行dom 手牌的平均赢率:
#include <iostream>
#include <vector>
#include <pokerstove/penum/ShowdownEnumerator.h>
int main() {
using namespace pokerstove;
using namespace std;
CardSet completeDeck;
completeDeck.fill();
cout << "The whole deck has " << completeDeck.size() << " cards" << endl;
CardDistribution anyTwo;
anyTwo.fill(completeDeck, 2);
cout << "There are " << anyTwo.size() << " two card combinations" << endl;
CardDistribution holeCards;
holeCards.parse("As6s");
ShowdownEnumerator showdown;
vector<EquityResult> result = showdown.calculateEquity(
vector<CardDistribution>{anyTwo, holeCards},
CardSet(""),
PokerHandEvaluator::alloc("h")
);
double shareRandom = result.at(0).winShares + result.at(0).tieShares;
double shareHand = result.at(1).winShares + result.at(1).tieShares;
double total = shareRandom + shareHand;
cout << "A random hand has " << shareRandom / total * 100 << " % equity (" << result.at(0).str() << ")" << endl;
cout << "The hand As6s has " << shareHand / total * 100 << " % equity (" << result.at(1).str() << ")" << endl;
}
一旦它最终停止,它输出
The whole deck has 52 cards
There are 1326 two card combinations
A random hand has 40.0942 % equity (804780676 36223609 0 0)
The hand As6s has 59.9058 % equity (1220344506 36223609 0 0)
在我的机器上(我承认它不是特别快)这个计算大约需要 4 分钟!由于这看起来太长了,我相信这个实现一定有问题(性能方面)。
因此,如果有人能指出我哪里做错了/效率低下,我将不胜感激。
我怀疑可以将 运行dom 牌的数量从 1326 减少到 169(由于花色相同),但我没有找到实现该行为的方法。
感谢任何帮助!
简短的回答是:这就是速度。
更长的答案是,这个版本是一个通用评估器,能够评估任何类型的游戏。它不会做任何花哨的事情,比如缓存结果、预计算大表、使用套装同构或其他任何东西。
我最近开始使用 pokerstove 库 (https://github.com/andrewprock/pokerstove) 并成功地用它进行了一些基本的手牌/赢率评估。不幸的是,当我尝试编写计算量更大的程序时,我 运行 陷入了无法弄清楚如何处理的大量性能问题。
作为示例,我提供了以下程序来计算黑桃 A-6 手牌对抗完全 运行dom 手牌的平均赢率:
#include <iostream>
#include <vector>
#include <pokerstove/penum/ShowdownEnumerator.h>
int main() {
using namespace pokerstove;
using namespace std;
CardSet completeDeck;
completeDeck.fill();
cout << "The whole deck has " << completeDeck.size() << " cards" << endl;
CardDistribution anyTwo;
anyTwo.fill(completeDeck, 2);
cout << "There are " << anyTwo.size() << " two card combinations" << endl;
CardDistribution holeCards;
holeCards.parse("As6s");
ShowdownEnumerator showdown;
vector<EquityResult> result = showdown.calculateEquity(
vector<CardDistribution>{anyTwo, holeCards},
CardSet(""),
PokerHandEvaluator::alloc("h")
);
double shareRandom = result.at(0).winShares + result.at(0).tieShares;
double shareHand = result.at(1).winShares + result.at(1).tieShares;
double total = shareRandom + shareHand;
cout << "A random hand has " << shareRandom / total * 100 << " % equity (" << result.at(0).str() << ")" << endl;
cout << "The hand As6s has " << shareHand / total * 100 << " % equity (" << result.at(1).str() << ")" << endl;
}
一旦它最终停止,它输出
The whole deck has 52 cards
There are 1326 two card combinations
A random hand has 40.0942 % equity (804780676 36223609 0 0)
The hand As6s has 59.9058 % equity (1220344506 36223609 0 0)
在我的机器上(我承认它不是特别快)这个计算大约需要 4 分钟!由于这看起来太长了,我相信这个实现一定有问题(性能方面)。
因此,如果有人能指出我哪里做错了/效率低下,我将不胜感激。
我怀疑可以将 运行dom 牌的数量从 1326 减少到 169(由于花色相同),但我没有找到实现该行为的方法。
感谢任何帮助!
简短的回答是:这就是速度。
更长的答案是,这个版本是一个通用评估器,能够评估任何类型的游戏。它不会做任何花哨的事情,比如缓存结果、预计算大表、使用套装同构或其他任何东西。