Блэкджек отсутствует алгоритм - PullRequest
0 голосов
/ 03 мая 2018

В процессе завершения моего приложения Блэк Джек. В настоящее время я тестирую ошибки, и примерно в 1 из 20 попыток я сталкиваюсь со сценарием, в котором Он раздает карты дилера, но это все, что он делает. Тогда рука заканчивается. По какой-то причине Кажется, что он не соответствует действительному условию. Вот алгоритм, который я использовал. Пожалуйста, скажите мне, если вы найдете какой-либо результат / алгоритм, который я мог бы пропустить.

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);
                            }
               } 
        }
   }
...