You are on page 1of 4

--Pseudocode for Blackjack.

java Initialise Initialise Initialise Initialise win


variable (0) lose variable (0) round result variable (0) round number variable (0)

Initialise stand variable (false) Initialise surrender variable (false) Initialise


player input variable ("") Initialise player hand array [0, 0, 0, 0, 0] Initialise
dealer hand array [0, 0, 0, 0, 0] Initialise card value array [11, 2, 3, 4, 5, 6,
7, 8, 9, 10, 10, 10, 10] while(true): // The main program loop. while(true): // The
round loop. Increase the round number by one. Deal two cards to the dealer. If the
dealer has a blackjack: // The player loses instantly. Set round result to 2. Break
the round loop. Else: // The dealer keeps drawing until his score 17 or he busts.
for(3): // The dealer drawing loop. Draw a card for the dealer. If the dealer is at
22 or higher: // The dealer busts. Set round result to 1. Break the for loop. Else
if the dealer is at 17 or higher: // The dealer stands. The dealer stands. Break
the for loop. If the round result is 1: // Breaking the round loop if the player h
as won already. Break the round loop. for(3): // The player drawing loop.
while(true): // The player input checking loop. Prompt the player for input ("Your
cards are X and Y (total of Z
). What will you do?"). If the input is "hit": Draw a card for the player. Break
the input checking loop. Else if the input is "stand": Set stand to true. Break the
input checking loop. Else if the input is "surrender": If the player only has two
cards in their hand: Set surrender to true. Break the input checking loop. Else:
Notify the player that they can't surrender now. Else: // The player has entered
something other than the set opt ions. Tell the player to stop being silly and
enter a real command . If stand or surrender is true, or the player's hand is 21 or
higher: Break the drawing loop. // The players have both finished their hands, time
to find out who wins ! If surrender is true: // End the game without a win or a
loss. Break the round loop. Else if the player's hand is 22 or higher: // The
player loses. Set round result to 2. Break the round loop. Else: // Compare the
player's scores. If the player's score is higher than the dealer's: Set round
result to 1. Break the round loop. Else: Set round result to 2.
Break the round loop. If round result is 1: Increase wins by one. Congratulate the
player! Else if round result is 2: Increase losses by one. Notify the player of
their failure. Set round result to 0. Reset the hands of the player and the dealer.
while(true): // Another player input loop, this time for replaying the game. Ask
for player input ("Do you want to play again?"). If input is "yes" or "no": Break
the input loop. Else: Tell the player to stop being silly and enter a proper
command. If input is "no": Break the main program loop and exit the program. ---

You might also like