Simulating Blackjack Game
Added on 2019-09-30
7 Pages1690 Words109 Views
|
|
|
Pontoon ProgramPROGRAM DESIGN – pseudocode(With line numbers)001 *** Design of pack of cards.002 *** This will include:003 *** Each card in the pack as an element of an array;004 *** The index of the next card in the pack.005 *** Design of each hand of cards.006 *** This will include:007 *** Each card in the hand as an element of an array;008 *** The number of cards in the hand;009 *** A boolean indicating whether aces are in the hand;010 *** A boolean indicating whether the hand is a Pontoon;011 *** The max. point count of the hand (<22 if possible);012 *** The min. point count of the hand (each ace is 1).013 *** Pontoon Program014 BEGIN015 set games played to 0016 CALL initialise_pack (returns pack of cards)017 LOOP018 CALL initial_deal (passing pack, returns the 2 hands)019 increment games played020 IF games played > 8021 THEN022 CALL random_pack_generator (returns shuffled pack)023 ENDIF024 CALL human_plays (passing Human’s hand & pack, returns ‘human bust’ flag)025 IF human is bust026 THEN027 DISPLAY “You lose”028 ELSE029 CALL computer_plays (passing Computer’s hand & pack)030 IF minimum point count of Computer’s hand > 21031 THEN032 DISPLAY “You win – Computer is bust”033 ELSE034 CALL compare_scores (passing the two hands)035 IF winner is human036 THEN037 DISPLAY “You win – congratulations”038 ELSE039 DISPLAY “You lose”040 ENDIF
041 DISPLAY “Computer held: “042 CALL display_cards (Computer’s hand)043 ENDIF044 ENDIF045 increment games played046 CALL restore_pack (passing pack & the 2 hands)047 DISPLAY “Play another game?”048 READ answer049 ENDLOOP when human does not want another game050 CALL write_pack_to_file (passing pack)051 END052 initialise_pack:053 BEGIN054 READ user choice (from radio button)055 IF user choses random generation056 THEN057 CALL random_pack_generator (returns pack of cards)058 ELSE *** user choses to read pack from file059 CALL read_pack_from_file (returns pack of cards & success indicator)060 IF cards could not be successfully read from file061 THEN062 CALL random_pack_generator (returns pack of cards)063 ENDIF064 ENDIF065 set index of next card in pack to the first card in pack066 RETURN pack of cards067 END068 initial deal:069 *** Input is pack of cards070 BEGIN071 add first card in pack to Human’s hand072 add second card in pack to Computer’s hand073 add third card in pack to Human’s hand074 add fourth card in pack to Computer’s hand075 add 4 to index of next card in pack076 set number of cards in Human’s hand to 2077 set number of cards in Computer’s hand to 2078 CALL assess_hand (passing Human’s hand)079 CALL assess_hand (passing Computer’s hand)080 RETURN Human’s hand, Computer’s hand & updated pack081 END
082 human_plays:083 *** Inputs are Human’s hand & pack084 BEGIN085 LOOP086 DISPLAY “Your hand”087 CALL display_cards (Human’s hand)088 DISPLAY “Stick or twist?”089 READ response (from radio button)090 IF response is ‘stick’ AND [maximum point count of hand < 16 AND cards held < 5]091 THEN092 DISPLAY “You have less than 16 points - must twist”093 set response to ‘twist’094 ENDIF095 IF response is ‘twist’096 THEN097 CALL deal_card (passing Human’s hand & the pack)098 CALL display_cards (passing Human’s hand)099 IF minimum value of cards in human’s hand is > 21100 THEN101 DISPLAY “You are bust”102 ENDIF103 ENDIF104 ENDLOOP when human allowed to stick OR when human is bust105 RETURN Human’s hand, updated pack & flag indicating whether Human is bust106 END107 computer_plays:108 *** Inputs are Computer’s hand & pack109 BEGIN110 LOOP while computer does not have pontoon AND computer has less than 5 cards AND [maximum value of hand is < 17 OR minimum value of hand is <12]111 CALL deal_card (passing Computer’s hand & the pack)112 DISPLAY “Computer twists”113 ENDLOOP114 RETURN updated Computer’s hand & the pack115 END
End of preview
Want to access all the pages? Upload your documents or become a member.