需要帮助为 Poker AI 迭代数组,检索两种可能性,不重复

发布于 2024-09-01 06:31:40 字数 1039 浏览 2 评论 0原文

我真的想不出一个好方法来表达这个问题,也想不出一个好的标题,也许答案是如此简单得可笑,以至于我错过了它。我正在研究扑克人工智能,我想计算存在的比我更好的牌的数量。我知道如何做到这一点,但我不知道迭代一组卡片的最佳方法。

所以我在翻牌圈,我知道我的两张牌是什么,并且牌面上有 3 张牌。所以,有 47 张未知的牌,我想迭代这 47 张牌的所有可能组合,假设有两张牌被淘汰,所以你不能有两张相同点数和花色的牌,并且如果你之前计算过设置你不想再做一遍,因为我会浪费时间,而且这会被调用很多次。如果您不明白我要问的问题,请告诉我,我会澄清更多。所以,我可以这样设置,如果该元素等于 1,则意味着它不在我手中,也不在棋盘上,每种花色 4 个,每个等级 13 个。 setOfCards[4][13]

If I do a simple set of for loops like this: (pseudocode)

//remove cards I know are in play from setOfCards by setting values to zero
for(int i = 0; i < 4; i++)
    for(int j = 0; j < 13; j++)
        for(int k = 0; k < 4; k++)
            for(int l = 0; l < 4; l++)
                //skip if values equal zero
                card1 = setOfCards[i][j]
                card2 = setOfCards[k][l]
                //now compare card1, card2 and set of board cards

因此,这实际上会重复许多值,例如:card1 = AceOfHearts, card2 = KingOfHearts 与 card1 = KingOfHearts, card2 = AceOfHearts 相同。它也会改变我的计算。我应该如何避免这种情况?另外,这种技术有名字吗?谢谢。

I can't really think of a good way to word this question, nor a good title, and maybe the answer is so ridiculously simple that I am missing it. I am working on a poker AI, and I want to calculate the number of hands that exist which are better than mine. I understand how to that, but what I can't figure out is the best way to iterate over a group of cards.

So I am at the flop, I know what my two cards are, and there are 3 cards on the board. So, there are 47 unknown cards and I want to iterate over all possible combinations of those 47 cards assuming that two are passed out, so you can't have two cards of the same rank and suit, and you if you have previously calculated a set you don't want to do it over again, because I will being wasting time, and this will be called many times. If you don't understand want I am asking please tell me and I will clarify more. So, I can set something up like this, if that element equals one, it means it is not in my hand and not on the board, 4 for each suit, and 13 for each rank. setOfCards[4][13].

If I do a simple set of for loops like this: (pseudocode)


//remove cards I know are in play from setOfCards by setting values to zero
for(int i = 0; i < 4; i++)
    for(int j = 0; j < 13; j++)
        for(int k = 0; k < 4; k++)
            for(int l = 0; l < 4; l++)
                //skip if values equal zero
                card1 = setOfCards[i][j]
                card2 = setOfCards[k][l]
                //now compare card1, card2 and set of board cards

So, this is actually going to repeat many values, for example: card1 = AceOfHearts, card2 = KingOfHearts is the same as card1 = KingOfHearts, card2 = AceOfHearts. It will also alter my calculations. How should I go about avoiding this? Also, is there a name for this technique? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽心 2024-09-08 06:31:40

如果只有 52 张卡片的单个数组会更容易,那么你可以说

for (int i=0; i<52; i++)
    for (int j=i+1; j<52; j++)

现在j将始终高于i,所以你不会得到重复的信息。您可以对二维数组执行类似的操作,但有点棘手:

for (int k=i; ...) 
    for (int l=j+1; ...)

在内部两个循环中应该执行此操作。

It'd be easier to just have a single array of 52 cards, then you can say

for (int i=0; i<52; i++)
    for (int j=i+1; j<52; j++)

Now j will always be higher than i, so you get no repeats. You could do a similar thing for the 2-d array, but it's a bit trickier:

for (int k=i; ...) 
    for (int l=j+1; ...)

in the inner two loops ought to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文