gpt4 book ai didi

Java HiLow 百分比机会计算器 - 明显的逻辑问题

转载 作者:行者123 更新时间:2023-12-02 06:09:42 34 4
gpt4 key购买 nike

我在使用基于 Java 的概率计算器进行 HiLow 游戏迭代时遇到了一些困难(特别是这个: http://bitino.com/hi-lo/ )。该程序的目标是在给定 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();

}
}
}
}

一如既往,非常感谢您的帮助。提前谢谢您。

最佳答案

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

其次剩余的卡牌还不够。这一次,您不应该计算相同值(value)的剩余牌 - 这些牌没有更高或更低,只是相同。

无需计算整个大/小牌数组,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);

关于Java HiLow 百分比机会计算器 - 明显的逻辑问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21993053/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com