- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个程序来跟踪每个玩家在扑克中的筹码数量。这不是扑克牌游戏,只是一个可以记录每个玩家筹码数量的程序。但是,我希望能够“下注”“跟注”“弃牌”等并能够自动跟踪。
我的问题是,有没有一种方法可以在不编写每个排列的情况下调整玩家数量?目前,它只能跟踪 2 个人。我将如何制作它以便理论上可以跟踪无限数量的人?我已经写了所有可能的排列,我知道它不是很有效,所以有没有更有效的编码方式?
我是 Java 菜鸟,所以任何帮助将不胜感激。
import java.util.Scanner;
import static java.lang.System.out;
class Chips {
static String move; //first move
static int betVal1, betVal2;
static int pot;
static int P1, P2;
static int roundcount;
static String player;
static Scanner myScanner = new Scanner(System.in);
static int turncount;
static String outcome;
public static void firstP1() { //first move when P1 start
out.print("P1 - will you 'Bet', 'Check' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold'");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? If you've changed your mind: Type '0' to check and '-1' to fold. ");
betVal1 = myScanner.nextInt();
while (betVal1 > P1) {
out.print("You cannot bet more than your chip count. How much will you bet? ");
betVal1 = myScanner.nextInt();
}
if (betVal1 == 0) { //check
P2aftercheck();
}
if (betVal1 == -1) { //fold
P2 += pot;
pot = 0;
roundcount = 0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) { //check to see who begins next turn
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
}
pot += betVal1;
P1 -= betVal1;
//out.println(betVal);
//out.print(pot);
P2afterbet();
break;
case "Check":
P2aftercheck();
break;
case "Fold":
P2 += pot;
pot = 0;
roundcount = 0;
turncount++;
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void firstP2() { //first move when P2 start
out.print("P2 - will you 'Bet', 'Check' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold' ");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? ");
betVal2 = myScanner.nextInt();
while (betVal2 > P2) {
out.print("You can not bet more than your chip count. How much will you bet? ");
betVal2 = myScanner.nextInt();
}
pot += betVal2;
P2 -= betVal2;
//out.println(betVal);
//out.print(pot);
P1afterbet();
break;
case "Check":
P1aftercheck();
break;
case "Fold":
P1 += pot;
pot = 0;
roundcount = 0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void P1afterbet() { //P1 move after P2 bet
out.print("P1 - will you 'Bet', 'Call' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Call") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold' ");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? ");
betVal1 = myScanner.nextInt();
while (betVal1 < betVal2){
out.print("Please bet at least ");
out.print(betVal2);
out.println(" chips.");
out.print("How much will you bet? ");
betVal1 = myScanner.nextInt();
}
pot += betVal1;
P1 -= betVal1;
P2afterbet();
break;
case "Call":
pot += betVal1;
P1 -= betVal1;
roundcount++;
if (roundcount == 4){
roundend();
}
if( player.equals("P1")) {
firstP1();
} else {
firstP2();
}
break;
case "Fold":
P2 += pot;
pot = 0;
roundcount = 0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void P1aftercheck() { //P1 move after P2 check
out.print("P1 - will you 'Bet', 'Check' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold'");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? ");
betVal1 = myScanner.nextInt();
while (betVal1 > P1) {
out.print("You can not bet more than your chip count. How much will you bet? ");
betVal1 = myScanner.nextInt();
}
pot += betVal1;
P1 -= betVal1;
//out.println(betVal);
//out.print(pot);
P2afterbet();
break;
case "Check":
roundcount++;
if (roundcount == 4) {
roundend();
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
case "Fold":
P2 += pot;
pot = 0;
roundcount=0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void P2afterbet() { //P2 move after P1 bet
out.print("P2 - will you 'Bet', 'Call' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Call") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold'");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? ");
betVal2 = myScanner.nextInt();
while (betVal2 > P2) {
out.print("You can not bet more than your chip count. How much will you bet? ");
betVal2 = myScanner.nextInt();
}
while (betVal2 < betVal1) {
out.print("You must bet at least ");
out.print(betVal1);
betVal2 = myScanner.nextInt();
}
pot += betVal2;
P2 -= betVal2;
//out.println(betVal);
//out.print(pot);
P1afterbet();
break;
case "Call":
P2 -= betVal1;
pot += betVal1;
roundcount++;
if (roundcount == 4){
roundend();
}
if( player.equals("P1")) {
firstP1();
} else {
firstP2();
}
break;
case "Fold":
P1 += pot;
pot = 0;
roundcount = 0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void P2aftercheck() { //P2 move after P1 check
out.print("P2 - will you 'Bet', 'Check' or 'Fold'? ");
move = myScanner.next();
while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
out.print("Please type 'Bet', 'Check' or 'Fold'");
move = myScanner.next();
}
switch(move) {
case "Bet":
out.print("How much will you bet? ");
betVal2 = myScanner.nextInt();
while (betVal2 > P1) {
out.print("You can not bet more than your chip count. How much will you bet? ");
betVal2 = myScanner.nextInt();
}
pot += betVal2;
P2 -= betVal2;
//out.println(betVal);
//out.print(pot);
P1afterbet();
break;
case "Check":
roundcount++;
if (roundcount == 4){
roundend();
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
case "Fold":
P1 += pot;
pot = 0;
roundcount=0;
turncount++;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
break;
}
}
public static void roundend() {
out.print("Who won the round? 'P1' or 'P2'? ");
outcome = myScanner.next();
turncount++;
if (turncount % 2 == 0) {
player = "One";
} else {
player = "Two";
}
while (!outcome.equals("P1") && !outcome.equals("P2")){
out.print("Please type 'P1' or 'P2'");
outcome = myScanner.next();
}
if (outcome.equals("P1")){
P1 += pot;
pot = 0;
roundcount = 0;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (P1 != 0 && P2 != 0){
if( player.equals("One")) {
firstP1();
} else {
firstP2();
}
} else if (P1 == 0) {
out.print("P1 is out of chips. P2 Wins!");
} else {
out.print("P2 is out of chips. P2 Wins!");
}
} else {
P2 += pot;
pot = 0;
roundcount = 0;
out.print("P1: ");
out.println(P1);
out.print("P2: ");
out.println(P2);
out.println("Next turn");
if (P1 != 0 && P2 != 0) {
if( player.equals("P1")) {
firstP1();
} else {
firstP2();
}
} else if (P1 == 0) {
out.print("P1 is out of chips. P2 Wins!");
} else {
out.print("P2 is out of chips. P2 Wins!");
}
}
System.exit(0);
}
public static void main(String args[]){
pot = 0;
roundcount = 0; //status within turn i.e. Flop, Turn, River
turncount = 2; //use for who starts
out.print("Please enter starting chip count ");
P1 = myScanner.nextInt();
P2 = P1;
firstP1();
}
最佳答案
是的,但您需要重新考虑程序的设计方式。
最简单的方法是创建一个 Player
类,并将玩家执行的每个 Action 作为此类中的一个方法来实现。为了管理玩家的筹码,您需要一个变量 Player.chips
,它可以全局访问或使用 Player.getChips()
和 Player 等方法进行管理.setChips()
.
对于多个玩家,您将拥有一个 Player
数组,即。
Player[] Players;
Players[0] = new Player();
Players[1] = new Player();
以下帖子可能对您有更多帮助(类似问题,但使用 Blackjack 而不是 Poker)- How to initialize an array of objects in Java .
关于Java排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138238/
我需要在给定的列表上生成排列。我设法这样做 let rec Permute (final, arr) = if List.length arr > 0 then for x i
我正在尝试运行我的代码,以便它打印循环排列,尽管我目前只能让它执行第一个排列。它正确运行到我标记的点,但我看不出出了什么问题。我认为 while 循环中没有中断,但我不确定。确实需要一些帮助。 pac
我正在尝试计算不包含连续字母的排列数。我的代码通过了像“aabb”(答案:8)和“aab”(答案:2)这样的测试,但没有通过像“abcdefa”这样的情况(我的答案:2520;正确答案:3600)。这
比赛在这 B.排列 前言: 笛卡尔树上 dp?这名字很妙啊,但其实不需要笛卡尔树,只不过利用了笛卡尔树的定义 一个性质:我们设一个区间 \([l,r]\) 中的最大值的位置为 \(pos\),
我正在尝试使用 dplyr 的 arrange 根据条件对字符串进行排序。我想在一列上排列,但如果第二列等于一个值,则按升序排列,如果第二列等于另一个值,则按降序排列。 我发现了几个类似的问题(其中一
在 R 中,我使用 dplyr更具体地说 arrange() . 不知何故 arrange功能没有按预期工作。 在下面的示例中,我首先存储列的名称,然后将此变量作为参数传递给名为“my_functio
以下是我的 main.qml : Window { id: window visible: true width: 800 height: 480 title:
很难用谷歌搜索这个问题,因为我不确定这些概念叫什么,并且所有“两个数组/组的组合”SO 帖子都没有给我我期望的输出。 数组示例: var array1 = ['Bob', 'Tina']; var a
实现以下目标的最佳方法是什么?我有两个列表: val l1 = List("a", "b") val l2 = List(1, 2) 我想生成这个: List ( List(('a', 1)
我知道互联网上有很多针对我的具体问题的解决方案,但我一直在尝试以特定的方式解决它,但它不起作用,我真的无法理解出了什么问题。就我而言,我只想打印排列。这是我的代码: a = "abc"; functi
我有这样的代码来创建排列: --unique permutation perm :: [t] -> [[t]] perm [] = [[]] perm (x:xs) = [(y:zs) | (y,ys
有没有比使用基本公式 n!/(n-r)! 更好的方法?就像我们对 nCr(组合) nCr = (n-l)Cr + (n-1)C(r-1) 一样? 最佳答案 这样怎么样:nPr = (n−1)Pr +
此问答的动机是 How to build permutation with some conditions in R . 到目前为止,已经有一些很好的 R 软件包,例如 RcppAlgos 和 arr
我正在修改一本书中的排列示例。以下代码按预期工作。 perms([]) -> [[]]; perms(L) -> [[H|T] || H []; 它返回一个空列表。当我替换时,我得到了这个。
大约一周前,我问了一个关于帮助我解决这个问题的问题 Java permutations ,打印排列方法有问题。我已经整理了我的代码,并有一个现在可以工作的工作示例,尽管如果 5 位于数组中的第五个位置
我有一个包含重复元素的列表,即orig = [1,1,1,2,2,3]。 我想创建一个derangement b = f(orig),使得 b 中的每个位置值都与 orig 中的值不同: b[i] !
我想生成一个 array a 的排列而且我不想使用实用功能,例如 java.util.Collections() . 排列应该是随机的,并且每个排列都应该有可能发生 - 但不需要均等分布的概率。 以下
我有一个作业:用户输入一个字符串,例如 ABCD,程序必须给出所有排列。我不希望整个代码只是一个提示。这是我到目前为止在他们那里得到的,我没有得到任何实现。 以ABCD为例: 在本例中获取字符串长度的
我目前正在编写一个使用 itertools 的程序,其中的一部分似乎无法正常运行。我希望确定排列函数输出列表长度的输入等于它生成输出的列表长度。换句话说,我有 import itertools b =
我有一个列表 x=[1,2,3,4,5] 并且想查看这个列表的不同排列,一次取两个数字。 x=[1,2,3,4,5] from itertools import permutations y=list
我是一名优秀的程序员,十分优秀!