Java 是否可以在某个条件下减小计数器?

Java 是否可以在某个条件下减小计数器?,java,algorithm,if-statement,conditional-statements,poker,Java,Algorithm,If Statement,Conditional Statements,Poker,我试图在分析扑克牌时发现一个小丑。 我需要在这只手工作的地方添加一个功能8sjk 6sjk 4S。JK是小丑。我使用的代码逻辑与 cardsTable表示手牌中的牌列的分布。此数组的每个元素表示手上该等级的牌数(从1到13,1为ace)。因此,对于8sjk6sjk4s,分布将是 0 0 0 1 0 1 0 0 0 0 0 0 注意,位置1代表ace(因为它更简单) 我需要找到一种方法来检测cardsTable[I]==1是否失败,并减少用于检测小丑traightflush的小丑数量(number

我试图在分析扑克牌时发现一个小丑。 我需要在这只手工作的地方添加一个功能
8sjk 6sjk 4S
JK
是小丑。我使用的代码逻辑与

cardsTable
表示手牌中的牌列的分布。此数组的每个元素表示手上该等级的牌数(从1到13,1为ace)。因此,对于
8sjk6sjk4s
,分布将是

0 0 0 1 0 1 0 0 0 0 0 0

注意,位置1代表ace(因为它更简单)

我需要找到一种方法来检测cardsTable[I]==1是否失败,并减少用于检测小丑traightflush的小丑数量(
numberOfJokers
),因为在这段不完整的代码中,
numberOfJokers
不减少,我不知道如何以一种好的方式编写它。我在这里做的是检查这个级别的卡是否存在
cardsTable[i]==1
或者它是否是一个小丑。。。但我不知道如何在其他连续排名中找到一个小丑

我不知道我是否清楚,这是一个扭曲的局面。。如果我不知道,请告诉我

stright=false;//不直截了当
int numberOfJokers=2//(一只手最多有2个小丑)
对于(int i=1;i 0){
if(cardsTable[i+2]==1 | | numberOfJokers>0){
if(cardsTable[i+3]==1 | | numberOfJokers>0){
if(cardsTable[i+4]==1 | | numberOfJokers>0){
直=真;
打破
}
}
}
}
}
}

从概念上讲,您只需要5个插槽中的3个插槽等于1,另外2个插槽等于0。你可以这样做:

for (int i = 1; i <= 9; i++) { 
    boolean straight = true;
    int numberOfJokers = 2;
    for (int j = i; j <= i + 5; j++) {  // I used a for loop instead of writing the statement 5 times
        if (cardsTable[j] > 1) {  // Can't have straight if more than one of a kind
           straight = false;
        }
        if (cardsTable[j] == 0) {
            numberOfJokers--;
        }
    }
    if (numberOfJokers >= 0 && straight == true) {
        break;
    }
}

for(int i=1;i从概念上讲,您只需要5个插槽中的3个插槽等于1,另外2个插槽等于0。您可以这样做:

for (int i = 1; i <= 9; i++) { 
    boolean straight = true;
    int numberOfJokers = 2;
    for (int j = i; j <= i + 5; j++) {  // I used a for loop instead of writing the statement 5 times
        if (cardsTable[j] > 1) {  // Can't have straight if more than one of a kind
           straight = false;
        }
        if (cardsTable[j] == 0) {
            numberOfJokers--;
        }
    }
    if (numberOfJokers >= 0 && straight == true) {
        break;
    }
}

for(int i=1;invm我在我的条件中使用了一个函数..我不知道这是否正确,但对我来说是逻辑x)


nvm我在我的条件下使用了一个函数……我不知道这是否正确,但对我来说这是逻辑(x)

由于,您不需要
检测
|
导致
为真的
的左操作数:仅当左操作数为
为假时,才计算右操作数。
(cardsTable[i+c]==1 | | numberOfJokers-->0)
可以工作;注意
(numberOfJokers-->0 | | cardsTable[i+c]==1)
不会

此类代码是否可维护或可读是一个独立的考虑因素,问题和解决方案的整体方法的质量也是一个独立的考虑因素。

由于,您不需要
检测
|
导致
为真的
的左操作数:仅当左操作数为
为假时,才计算右操作数。
(cardsTable[i+c]==1 | | numberOfJokers-->0)
可以工作;注意
(numberOfJokers-->0 | | cardsTable[i+c]==1)
不会


此类代码是否可维护或可读是一个独立的考虑因素,问题和解决方案的整体方法的质量也是一个独立的考虑因素。

也就是说,在循环条件下提升控制变量的值足以使其可读。也就是说,在循环条件下提升控制变量的值足够常见,从而使其可读。
straight = false; // assume no straight
for (int i = 1; i <= 9; i++) // can't have straight with lowest value of more than 10
{
            remainingJokers=jokers;
            System.out.println("resetjokers : "+jokers);
            if (cardsTable[i] == 1 || useJoker()) {
                if (cardsTable[i + 1] == 1 || useJoker()) {
                    if (cardsTable[i + 2] == 1 || useJoker()) {
                        if (cardsTable[i + 3] == 1 || useJoker()) {
                            if (cardsTable[i + 4] == 1 || useJoker()) {
                                System.out.println("straight");
                                straight = true;
                                topStraightValue = i + 4; // 4 above bottom value
                                break;

                            }

                        }

                    }
                }

            }
        }
}