Homework 3, My Solution.
Main Algorithm: (game)
Get player information
while no player has won the game
play a round
print the standings
Print the standings
Print the winner
---------------------------------
Get Player Information: (player)
Input: none
output: Array of players
for each player
ask if the player is human or computer
if human
Get human
else
Get computer
Add the player to the array
---------------------------------
Get Human (player)
Input: none
Output: A player record filled in for human
Ask for the player's name
Ask for the player's age
Set player name
Set player age
Set cherries in tree to 10
Set player type to human.
---------------------------------
Get Computer (player)
Input: number of computer players so far
Output: A player record filled in for a computer,
The updated number of computer players
Pick a computer name
Set the player name
Set cherries in tree to MAX_CHERRIES
Set player type to computer
Increment computer players
---------------------------------
Get Computer Name (player)
Input: number of computer players
Output: a name
count value | return
0 Alphie
1 Bettie
2 Deltie
3 Gammie
other UNKNOWN
---------------------------------
Print Player
Input: a player record
Output: nothing
print name,
print (cherry count)
print is a
if human
print human
else
print computer
print .
Print cherry line
---------------------------------
Print Cherry Line (player)
input: number of cherries in basket
output: none
print a * for each cherry in basket
print a O for each cherry on tree
---------------------------------
Spinner to String (spinner)
input: SpinnerT
output: string
return the string matching the spinner type.
---------------------------------
Spinner to Count (spinner)
input: SpinnerT
output: An integer
case | return
one 1
two 2
three 3
four 4
bird -2
dog -2
bucket -BUCKET_SIZE
---------------------------------
Spin
input: none
output: a spin result
generate a random integer between 0 and SPIN_CASES
return the corresponding spinner type.
---------------------------------
Play A Round (game)
Input: Array of players
Output: Array of players
flag indicating a player has won (bool)
for each player
if no player has won
Take Turn
---------------------------------
Take Turn
Input player record
player number
Output modified player record
flag indicating the player has won.
if the player is human
Take Human Turn
else
Take Computer turn
playerWon = the player has picked
if playerWon
print "Hi Ho Cherry-O!, you win"
---------------------------------
Take Human Turn
Input: player record
Output: updated player record
Print human verbiage.
Press enter to continue
Take Real Turn
---------------------------------
Take Computer Turn
Input: player Record
Output: updated player recorded
Print computer verbiage.
Take Real Turn
---------------------------------
Take Real Turn
Input: player Record
Output: updated player record
generate a spinner result
get the cherries moved based on the spinner result
if cherriesMoved + currentCherries > MAX_CHERRIES
invalid spin
print this
else if cherriesMoved + currentCherries < 0
currentCherries = 0
print this
else
currentCherries = cherriesMoved + currentCherries
print this
---------------------------------
Print Standings
Input: the array of players
Output: none
for each player
print "Player " number
Print Player
Get Continue
---------------------------------
Print Winner
Input: the winning player
the round number
if human
print congratulation for human
else
print congratulations for computer