ALGORITHM
DEFINE validValue( val ):
return val < 1 or > 3:
END
DEFINE inputOption():
Display options
Input option
CHECK if option is 1:
INPUT stones to pick
while not validValue(Stones):
Input stones to pick
OTHERWISE:
Generate random number 1-3 to pick stones
return stones
END
DEFINE playGamePlayer( player, total ):
Display player details
stones = inputOption()
CHECK if total <= stones:
return 0
OTHERWISE:
return total – count;
END
DEFINE playGameAI(total):
CHECK if total is divisible by 3:
stones = 2
OTHERWISE:
stones = 1
CHECK if total <= stones:
return 0
OTHERWISE:
return total – count;
END
DEFINE main():
INPUT player1
INPUT player2
INPUT total number of stones
WHILE total != 0:
total = playGame(player1, total)
CHECK if total is 0:
winner is player 1
break
total = playGame(player2, total)
CHECK if total is 0:
winner is player 2
break
total = playGameAI( total)
CHECK if total is 0:
winner is AI player
break
DISPLAY the winner