Java 扑克电动计算器:计算手的价值?
我正在尝试编写一个程序,帮助用户为每只手进行正确的EV播放。然而,目前我正在使用卡片价值(即总共两张卡片)作为我决策的基础。例如9=9,10=10,j=11,q=12。。。。我希望使用能够进入他们的实际手中,例如ADK(钻石王牌,黑桃之王)。这将更准确,因为它将考虑到手的合适价值等。有谁能给我建议最好的方式纳入这一点?非常感谢!我的cuurent代码在下面Java 扑克电动计算器:计算手的价值?,java,if-statement,switch-statement,poker,Java,If Statement,Switch Statement,Poker,我正在尝试编写一个程序,帮助用户为每只手进行正确的EV播放。然而,目前我正在使用卡片价值(即总共两张卡片)作为我决策的基础。例如9=9,10=10,j=11,q=12。。。。我希望使用能够进入他们的实际手中,例如ADK(钻石王牌,黑桃之王)。这将更准确,因为它将考虑到手的合适价值等。有谁能给我建议最好的方式纳入这一点?非常感谢!我的cuurent代码在下面 package uk.ac.qub.lectures; //importing resources (scanner) import ja
package uk.ac.qub.lectures;
//importing resources (scanner)
import java.util.Scanner;
public class PokeGame {
public static final int MIN_POSITION = 1;
public static final int MAX_POSITION = 8;
public static void main(String[] args) {
// declaring user position
int userPosition = 0;
// setting up scanner
Scanner scanner = new Scanner(System.in);
// integer referring to use again or not
int useAgain = 0;
// boolean getting valid input for repeat
boolean repeat = false;
// declaring number value of each card
int cards;
do {
// getting user position
do {
System.out.printf("Please enter position between %d and %d\n",MIN_POSITION, MAX_POSITION);
userPosition = scanner.nextInt();
} while ((userPosition < MIN_POSITION) || (userPosition > MAX_POSITION));
// getting hand hand strength
System.out.println("Enter card value");
cards = scanner.nextInt();
switch (userPosition) {
case 1:
case 2:
if (cards > 10) {
System.out.println("SHOVE");
} else
System.out.println("FOLD");
break;
case 3:
case 4:
case 5:
if (cards > 13) {
System.out.println("SHOVE");
} else
System.out.println("FOLD");
break;
case 6:
case 7:
case 8:
if (cards > 17) {
System.out.println("SHOVE");
} else
System.out.println("FOLD");
break;
default:
System.out.println("ENTER VALID POSITION");
}
do {
System.out.println("Do you advice on another Hand?");
System.out.println("Enter 1 for Yes, Enter 0 for No");
useAgain = scanner.nextInt();
if ((useAgain == 1) || (useAgain == 0)) {
repeat = false;
} else {
System.out.println("Invalid Input, please enter 1 or 0");
repeat = true;
}
} while (repeat);
} while (useAgain != 0);
// clean up resources
scanner.close();
}// method end
}// class end
package uk.ac.qub.讲座;
//导入资源(扫描仪)
导入java.util.Scanner;
公共级PokeGame{
公共静态最终内部最小位置=1;
公共静态最终int最大位置=8;
公共静态void main(字符串[]args){
//声明用户位置
int userPosition=0;
//设置扫描仪
扫描仪=新的扫描仪(System.in);
//指是否再次使用的整数
int=0;
//布尔值获取重复的有效输入
布尔重复=假;
//声明每张卡的数字值
int卡;
做{
//获取用户位置
做{
System.out.printf(“请输入%d和%d之间的位置”,最小位置,最大位置);
userPosition=scanner.nextInt();
}而((用户位置<最小位置)| |(用户位置>最大位置));
//获得手的力量
System.out.println(“输入卡值”);
cards=scanner.nextInt();
开关(用户位置){
案例1:
案例2:
如果(卡片>10){
System.out.println(“推”);
}否则
System.out.println(“折叠”);
打破
案例3:
案例4:
案例5:
如果(卡片>13){
System.out.println(“推”);
}否则
System.out.println(“折叠”);
打破
案例6:
案例7:
案例8:
如果(卡片>17){
System.out.println(“推”);
}否则
System.out.println(“折叠”);
打破
违约:
System.out.println(“输入有效位置”);
}
做{
System.out.println(“你有另一方面的建议吗?”);
System.out.println(“输入1表示是,输入0表示否”);
再次使用=scanner.nextInt();
如果((再次使用==1)| |(再次使用==0)){
重复=错误;
}否则{
System.out.println(“输入无效,请输入1或0”);
重复=正确;
}
}同时(重复);
}while(再次使用!=0);
//清理资源
scanner.close();
}//方法端
}//班尾
如果您像这样接受卡片输入;“AA”、“9T”或“9T”,然后您可以使用输入卡根据适合性和差距计算手牌价值:
import java.util.Arrays;
import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
String[] hand = (scanner.nextLine() + 'u').toUpperCase().split("");
String values = " 23456789TJQKA";
int[] cards = new int[] {values.indexOf(hand[1]), values.indexOf(hand[2])};
Arrays.sort(cards);
int gap = cards[1] - cards[0] - 1;
boolean pair = gap == -1;
boolean suited = hand[3].equals("S");
char[] cards = new char[] {(char)values.charAt(cards[0]), (char)values.charAt(cards[1])};
int handValue = 0;
// adjust value based on pairs, suitedness or connectedness
if (pair) // hand is a pair
handValue += 10; //or whatever you want
else if (suited) // hand is suited
handValue += 3; //or whatever you want
if (gap == 0) // hand is no gap
handValue += 5; //or whatever you want.
if (gap == 1) // hand is one gap
handValue += 3; //or whatever you want.
if (cards[1] == 'A' && cards[0] == 'K' && suited) // AK suited
System.out.println("AK Suited!");
else if (cards[1] == 'A' && suited) // Ax suited
System.out.println("Ax Suited!");
忘记添加userPosition是指用户坐在桌子上的位置(即早期位置、经销商等)!谢谢与编程无关,但与扑克有关,您还应考虑两张牌的数字差异。这不是一个答案,而是一个更高明的建议:遵循[CLEAN CODE][1]说明一些是:-使用带有有意义名称的常量-将代码分成多个小方法(每个大约5条语句)并正确地命名方法——每个方法都应该只有一个职责——有更多的规则,但要使用它们,这样你的代码就更容易阅读和理解,即使是你自己。[1] :非常感谢,这非常有帮助!是否有任何可能的方法来确定正确的发挥基于个人的手,而不是手的价值。即,如果卡是“k10”呼叫,但如果是“k9”折叠?ThanksIt应该是“kt”而不是“k10”。这取决于为什么一只手比另一只更好。KT是一个双间隙手,其中k9是一个三间隙手。与上面的示例类似,您可以执行
if(Math.abs(card1-card2)==4)//折叠来检测3间隙手。如果你想玩的唯一3个gap是在你做的If(Math.abs(card1-card2)==4&!(card1+card2==25))//fold
你帮了大忙,谢谢!你认为这种应用/程序有市场吗?在大学里,我们的任务就是做这样一个项目!你能看一下下面的代码吗(它使用了你从上面给我的代码):(card1 | |(card2)=(values.indexOf(hand[12])| |(values.indexOf(hand[13])和&(hand[3].equalsIgnoreCase(“s”)