确定扑克中的获胜金额而不创建边池

时间:2011-03-28 17:14:52

标签: algorithm poker

我正在尝试进行扑克模拟并获得有关扑克桌的以下数据

  • 每个玩家贡献了多少钱
  • 每个玩家的“手牌得分”(翻牌后)(即player[0].score == player[1].score,他们并列)

我很难计算每个玩家应该赢得多少,而不需要创建副圈并为每个玩家分配玩家。

例如,

player[0].contributed = 100
player[1].contributed = 80
player[2].contributed = 20

player[0].score = 10
player[1].score = 2
player[2].score = 10

total_pot = 200;

在这个例子中,我首先需要返回player[0] 20并将其从底池中删除吗?

然后,由于player[0]player[2]并列第一位, 并且player[1]已丢失,如果将该分区划分为:

player[0].received = 170
player[1].received = 0
player[2].received = 30

随后,如果player[1]赢了,那么这个底池应该分成:

player[0].received = 20
player[1].received = 180
player[2].received = 0

2 个答案:

答案 0 :(得分:10)

首先按分数降序排序,因此您最终会得到两个组: {0,2},{1}。

然后,按照他们提升的顺序对每个组进行排序: {2(20),0(100)},{1(80)}。

现在,按顺序划分底池:

  1. 首先你将从每个玩家的贡献中拿走(最多)20来创造第一个底池。并将其均匀分配为2和0.第一个底池将是(20 + 20 + 20 = 60.因此0和2都将被赋予30)。在那之后,第一个玩家的奖金就完成了,你剩下的就是:{0(80)},{1(60)}。

  2. 现在,你将从每个玩家的贡献中取出(最多)80来创建下一个底池(80 + 60 = 140)。并将其赋予0(不需要除法,因为顶部组中不超过一个,所以0将接收整个140)。你将留下:{1(0)}。

  3. 不再有任何贡献,所以你已经完成了。

  4. 所以,总的来说,在你的例子中,0将获得170而2将获得30。

答案 1 :(得分:2)

以下代码包含大量断言,但要小心,因为我没有仔细测试过。目前还不清楚如何处理奇数芯片;我把它们交给出现在集合中的玩家。

import java.util.*;

public class Player {
    int contributed, score, received;

    static void winnings(Collection<Player> players) {
        for (Player player : players) {
            assert player.contributed >= 0;
            player.received = 0;
        }
        int potCutoff = 0;
        while (true) {
            int playerCount = 0;
            int nextPotCutoff = Integer.MAX_VALUE;
            int scoreMax = Integer.MIN_VALUE;
            int winnerCount = 0;
            for (Player player : players) {
                if (player.contributed <= potCutoff) {
                    continue;
                }
                playerCount++;
                assert playerCount > 0;
                nextPotCutoff = Math.min(nextPotCutoff, player.contributed);
                if (player.score > scoreMax) {
                    scoreMax = player.score;
                    winnerCount = 1;
                } else if (player.score == scoreMax) {
                    winnerCount++;
                    assert winnerCount > 0;
                } else {
                    assert player.score < scoreMax;
                }
            }
            if (playerCount == 0) {
                break;
            }
            assert playerCount > 0;
            assert nextPotCutoff > potCutoff;
            assert potCutoff >= 0;
            assert Integer.MAX_VALUE / (nextPotCutoff - potCutoff) >= playerCount;
            int potTotal = playerCount * (nextPotCutoff - potCutoff);
            assert potTotal > 0;
            assert winnerCount > 0;
            assert winnerCount <= playerCount;
            for (Player player : players) {
                if (player.contributed <= potCutoff) {
                    continue;
                }
                assert player.contributed >= nextPotCutoff;
                if (player.score == scoreMax) {
                    assert winnerCount > 0;
                    int winnerShare = potTotal / winnerCount;
                    winnerCount--;
                    assert winnerShare > 0;
                    assert potTotal >= winnerShare;
                    potTotal -= winnerShare;
                    player.received += winnerShare;
                    assert player.received > 0;
                } else {
                    assert player.score < scoreMax;
                }
            }
            assert winnerCount == 0;
            assert potTotal == 0;
            potCutoff = nextPotCutoff;
        }
    }

    public static void main(String[] args) {
        Player p0 = new Player(), p1 = new Player(), p2 = new Player();
        p0.contributed = 100;
        p1.contributed = 80;
        p2.contributed = 20;
        p0.score = 10;
        p1.score = 2;
        p2.score = 10;
        Collection<Player> players = new ArrayList<Player>();
        players.add(p0);
        players.add(p1);
        players.add(p2);
        winnings(players);
        for (Player player : players) {
            System.out.println(player.received);
        }
    }
}