Я пытаюсь расшифровать этот код: 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
}