[0.69.420-PUBLIC#1911] Zheng Shi blackjack postRoundDialog() logic errors

Status
Not open for further replies.

one_two

Well-Known Member
Jan 20, 2022
457
130
Two issues in blackjack.jsx function postRoundDialog():

#1
JavaScript:
postRoundDialog(playerScore, dealerScore)
{
// ...
            if (dealerScore == 21)
            {
                dialogTitle = `You Lose`;
                dialogBody = `The House has Blackjack; you lose.`;
                this.setState({ roundsWon: this.state.roundsWon + 1 }); // should be roundsLost
            }
// ...

The game recognizes dealer's 21 as a loss for the player, but records it as player's win

#2
JavaScript:
// ...
        else // dealerScore <= playerScore
        {
            if (playerScore == 21)
            {
                dialogTitle = `You Win`;
                dialogBody = `Blackjack! You win!`;
                this.setState({ roundsWon: this.state.roundsWon + 1 });
            }
            else
            {
                // Player wins
                dialogTitle = `You Win`;
                dialogBody = `You have a better hand than the House; you win!`;
                this.setState({ roundsWon: this.state.roundsWon + 1 });
            }
// ...

This branch executes when neither side busts, and the player's score is higher but also when it's a tie. (there's no check for ties in the logic ladder, except for both sides hitting 21) As a result, ties with score below 21 count as win for the player, although it should be their loss.

Fix suggestion: relax conditions of earlier check else if (playerScore == 21 && dealerScore == 21) to just else if (playerScore == dealerScore) and adjust dialogBody in that branch based on whether the tied score is 21 or not. This also allows the final else quoted above to be simplified down to content of final sub-branch. Alternatively, put the tie in earlier else if (dealerScore > playerScore) branch, by changing the comparison to >=
 
Last edited:
Status
Not open for further replies.