破译RayW扑克手牌评估器

Deciphering RayW Poker Hand Evaluator

本文关键字:评估器 扑克 RayW 破译      更新时间:2023-10-16

我正在尝试破译这段代码:https://github.com/tangentforks/TwoPlusTwoHandEvaluator/blob/master/generate_table.cpp

该代码用于生成一个巨大的查找表,然后用于查找 7 手牌的手牌排名。我很难准确破译为什么主方法以这种方式编写。据我所知,第一个 for 循环会暴力破解每个卡片组合,并在必要时替换适当的花色抽象,但我不确定为什么在下一节中重复这样做,或者为什么它按 53 倍缩放然后加 53。谁能对此有所了解?

这是有问题的代码:

printf("nGetting Card IDs!n");
// Jmd: Okay, this loop is going to fill up the IDs[] array which has
// 612,967 slots. as this loops through and find new combinations it
// adds them to the end. I need this list to be stable when I set the
// handranks (next set)  (I do the insertion sort on new IDs these)
// so I had to get the IDs first and then set the handranks
for (IDnum = 0; IDs[IDnum] || IDnum == 0; IDnum++) {
// start at 1 so I have a zero catching entry (just in case)
for (card = 1; card < 53; card++) {
// the ids above contain cards upto the current card.  Now add a new card
ID = MakeID(IDs[IDnum], card);   // get the new ID for it
// and save it in the list if I am not on the 7th card
if (numcards < 7) holdid = SaveID(ID);
}
printf("rID - %d", IDnum);   // show progress -- this counts up to 612976
}
// main()
printf("nSetting HandRanks!n");
// this is as above, but will not add anything to the ID list, so it is stable
for (IDnum = 0; IDs[IDnum] || IDnum == 0; IDnum++) {
// start at 1 so I have a zero catching entry (just in case)
for (card = 1; card < 53; card++) {
ID = MakeID(IDs[IDnum], card);
if (numcards < 7) {
// when in the index mode (< 7 cards) get the id to save
IDslot = SaveID(ID) * 53 + 53;
} else {
// if I am at the 7th card, get the equivalence class ("hand rank") to save
IDslot = DoEval(ID);
}
maxHR = IDnum * 53 + card + 53;   // find where to put it
HR[maxHR] = IDslot; // and save the pointer to the next card or the handrank
}
if (numcards == 6 || numcards == 7) {
// an extra, If you want to know what the handrank when there is 5 or 6 cards
// you can just do HR[u3] or HR[u4] from below code for Handrank of the 5 or
// 6 card hand
// this puts the above handrank into the array
HR[IDnum * 53 + 53] = DoEval(IDs[IDnum]);
}
printf("rID - %d", IDnum); // show the progress -- counts to 612976 again
} 

目前也在做同样的事情。它被移动了 53,因为有 52 张牌。指向无效状态后,将转换为 0。从那里开始,您选择的任何卡仍然必须导致无效状态,因此前 53 个条目 0 + 52 排名指向 0。第一个有意义的条目出现在 53..(53+53(。

首先尝试理解概念。该表是一个巨大的有向图,其中每个节点有 52 个子节点和一个索引 0 处的"评估当前-手-排名节点"。poker-ai.org 和原始线程提供了许多有用的信息。另请查看CactusKevs的想法,通过使用质数获得牌上的手牌排名顺序。天才。这一切都涉及到这一点。