在完成我的二十一点申请的过程中。所以我目前正在进行错误测试,大约有 20 次尝试我会遇到这样的场景,它会处理庄家的牌,但仅此而已。然后手结束。由于某种原因,它似乎没有满足有效的 if 条件。这是我使用的算法。如果您发现我可能遗漏的任何结果/算法,请告诉我。
if(HitOrStand.equals("Stand")) {
// if user stands, we know need to focus on the dealer's hand
System.out.println("-----------------------------------------------------------------------------------");
//Deal dealers first 2 cards
String dCard1 = dealCard();
String dCard2 = dealCard();
//Get value of dealers first 2 cards.
int dValue1 = getCardValue(dCard1);
int dValue2 = getCardValue(dCard2);
//dTotal is the total value of the dealers hand. So we add card1 and card2 to dTotal
int dTotal = dValue1 + dValue2;
System.out.println("Dealer hand is a "+dCard1+","+dCard2);
//Check if dealer hand is greater then player hand, and also less then 21.
if ((dTotal) > (pTotal) && (dTotal) <= 21) {
System.out.println("YOU LOST! The dealer's hand was a "+dCard1+","+dCard2+"(Total:"+dTotal+") You've lost $"+bet);
}
//If dealer is less than player hand and less then 21, let the dealer deal himself another card.
else if((dTotal) <= (pTotal) && (dTotal) < 21) {
//deal 3rd card
String dCard3 = dealCard();
int dValue3 = getCardValue(dCard3);
//Add value of card3 to dTotal
dTotal += dValue3;
//Check if 3rd card made dealer bust
if(dTotal > 21) {
System.out.println("Dealer draws a......."+dCard3);
System.out.println("YOU WIN!!! Dealer drew a "+dCard3+" and BUSTED! Congrats you've won $"+bet * 2);
balance += (bet * 2);
}
//Check if dealer hand is greater then player hand, and also less then 21.
else if((dTotal) > (pTotal) && (dTotal) <= 21) {
System.out.println("Dealer draws a......."+dCard3);
System.out.println("YOU LOST! The dealer's hand was a "+dCard1+","+dCard2+","+dCard3+".(Total:"+dTotal+") You've lost $"+bet);
}
//If dealer is less than player hand and less then 21, let the dealer deal himself another card.
else if((dTotal) <= (pTotal) && (dTotal) < 21) {
//deal 4th card
String dCard4 = dealCard();
int dValue4 = getCardValue(dCard4);
//Add value of card4 to dTotal
dTotal += dValue4;
if(dTotal > 21) {
System.out.println("Dealer draws a......."+dCard4);
System.out.println("YOU WIN!!! Dealer drew a "+dCard4+" and BUSTED! Congrats you've won $"+bet * 2);
balance += (bet * 2);
}
//Check if dealer hand is greater then player hand, and also less then 21.
else if((dTotal) > (pTotal) && (dTotal) <= 21) {
System.out.println("Dealer draws a......."+dCard4);
System.out.println("YOU LOST! The dealer's hand was a "+dCard1+","+dCard2+","+dCard3+","+dCard4+".(Total:"+dTotal+") You've lost $"+bet);
}
}
}
}