How to resolve the algorithm 21 game step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 21 game step by step in the Quackery programming language
Table of Contents
Problem Statement
21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly 21. The running total starts at zero. One player will be the computer. Players alternate supplying a number to be added to the running total.
Write a computer program that will:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 21 game step by step in the Quackery programming language
Source code in the quackery programming language
[ say
"Who goes first: Computer, Player"
say " or Random?" cr
[ $ "Enter C, P or R: " input
dup size 1 != iff drop again
0 peek
dup char C = iff [ drop 0 ] done
dup char P = iff [ drop 1 ] done
char R = iff [ 2 random ] done
again ]
cr
dup iff [ say "You go first." ]
else [ say "I will go first." ]
cr ] is chooseplayer ( --> n )
forward is player ( n --> n x )
[ [ dup 17 > iff 1 done
4 over 4 mod
dup 0 = if [ drop 3 ]
- ]
dup say "Computer chooses " echo
say "." cr
+ ' player ] is computer ( n --> n x )
[ say "Choose 1 2 or 3 (running "
$ "total must not exceed 21, Q to quit): " input
dup $ "Q" = iff [ drop 21 999 ] done
trim reverse trim reverse
$->n not iff drop again
dup 1 4 within not iff drop again
2dup + 21 > iff drop again
+ ' computer ] resolves player ( n --> n x )
[ say "The player who makes 21 loses." cr
0 chooseplayer
iff [ ' player ] else [ ' computer ]
[ say "Running total is "
over echo say "." cr cr
do
over 21 = until ]
cr
dup 999 = iff
[ drop 2drop say "Quitter!" ] done
' computer = iff
[ say "The computer won!" ]
else [ say "You won! Well done!" ]
drop ] is play ( --> )
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Racket programming language
You may also check:How to resolve the algorithm Anonymous recursion step by step in the Swift programming language
You may also check:How to resolve the algorithm Metronome step by step in the Pure Data programming language
You may also check:How to resolve the algorithm Greedy algorithm for Egyptian fractions step by step in the Microsoft Small Basic programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Elixir programming language