Java HiLow百分比计算器 - 表观逻辑问题

时间:2014-02-24 16:16:46

标签: java probability playing-cards

对于HiLow游戏的迭代(特别是这一个:http://bitino.com/hi-lo/),我在使用基于Java的概率计算器时遇到了一些困难。该计划的目标是统计建议给出CHANCE_THRESHOLD值的赌注。该程序还跟踪播放的卡片。我遇到的问题与机会计算有关。到目前为止,我已经成功地解决了'A'(一个Ace)的值,但是已经遇到了测试其他值的问题。显然,机会百分比估值背后的逻辑确实存在问题。

import java.util.Scanner;

public class HiLow {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String flip = "";
        double flipInt = 0.0;

        final double CHANCE_THRESHOLD = 0.75;
        double chanceLower = 0;
        double chanceHigher = 0;

        String cardArray[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
        int cardValue[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

        int cardCounter[] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };

        int remainingCards = 0;

        while (!(flip.equalsIgnoreCase("e"))) {

            for (int x = 0; x < cardCounter.length; x++) {
                cardCounter[x] = 4;
            }

            chanceLower = 0;
            chanceHigher = 0;

            System.out.print(" > ");
            flip = scan.next();

            while (!(flip.equalsIgnoreCase("r")) && !(flip.equalsIgnoreCase("e"))) {

                for (int x = 0; x < 13; x++) {
                    if (flip.equalsIgnoreCase(cardArray[x])) {
                        flipInt = cardValue[x];
                        cardCounter[x]--;
                    }
                }

                remainingCards = 0;
                for (int x = 0; x < cardCounter.length; x++) {
                        remainingCards = remainingCards + cardCounter[x];
                }

                chanceLower = (((flipInt) - 1) + cardCounter[(int) (flipInt - 1)]) / remainingCards;
                System.out.println((((flipInt) - 1) + cardCounter[(int) (flipInt - 1)]) + " / " + remainingCards + " = " + chanceLower);

                // This line should output 0.98039215686 given the input of 'a'
                //chanceHigher = ((13 - (flipInt)) + cardCounter[(int) (flipInt - 1)]) / remainingCards;
                //System.out.println(((13 - (flipInt)) + cardCounter[(int) (flipInt - 1)]) + " / " + remainingCards + " = " + chanceHigher);

                chanceHigher = Math.abs(1 - chanceLower);
                System.out.println(Math.abs((((flipInt) - 1) + cardCounter[(int) (flipInt - 1)]) - remainingCards) + " / " + remainingCards + " = " + chanceHigher);


                if (chanceLower > chanceHigher) {
                    if (chanceLower >= CHANCE_THRESHOLD) {
                        System.out.println("Bet Lower.");
                    } else if (chanceLower > (CHANCE_THRESHOLD - 0.10)){
                        System.out.println("Bet with Caution.");
                    } else {
                        System.out.println("Risk Outside Threshold.");
                    }

                } else {
                    if (chanceHigher >= CHANCE_THRESHOLD) {
                        System.out.println("Bet Higher.");
                    } else if (chanceHigher > (CHANCE_THRESHOLD - 0.10)){
                        System.out.println("Bet with Caution.");
                    } else {
                        System.out.println("Risk Outside Threshold.");
                    }
                }

                for (int x = 0; x < cardCounter.length; x++) {
                    System.out.print(cardCounter[x] + ":" + cardArray[x] + " ");
                }
                System.out.print("\n");

                System.out.print(" > ");
                flip = scan.next();

            }
        }
    }
}

与往常一样,非常感谢帮助。提前谢谢你。

2 个答案:

答案 0 :(得分:1)

你需要得到你所拥有的卡值以下剩余卡数的总和(不仅仅是确定剩余卡的总数)。例如,您可以使用类似

的内容
int[] cardsBelow = new int[13];
for (int i=0; i < cardsBelow.length; i++) {
  if (i == 0) {
     cardsBelow[i] = cardCounter[i];
  } else {
     cardsBelow[i] = cardsBelow[i-1] + cardCounter[i];
  }
}

这样,单元格cardsBelow[i-1]包含“i”卡下面的卡数。

答案 1 :(得分:1)

首先,你没有关闭扫描仪,但我猜它只是被忽略了。

其余的剩余卡片是不够的。一次,你不应该计算相同值的剩余卡 - 这些卡不是更高也不是更低,只是相同。

没有必要计算整个数组的大/小卡,2个变量就够了

remainingLowerCards = 0;
remainingHigherCards = 0;
for (int x = 0; x < cardCounter.length; x++) {
    remainingCards = remainingCards + cardCounter[x];
    if (x < flipInt - 1) {
        remainingLowerCards += cardCounter[x];
    } else if (x >= flipInt) {
        remainingHigherCards += cardCounter[x];
    }
}

chanceLower = ((double) remainingLowerCards) / remainingCards;
System.out.println("Lower: " + remainingLowerCards + " / " + remainingCards + " = " + chanceLower);

// This line should output 0.98039215686 given the input of 'a'
chanceHigher = ((double) remainingHigherCards) / remainingCards;
System.out.println("Higher: " + remainingHigherCards + " / " + remainingCards + " = "
        + chanceHigher);