Nim Game with AI Program Project

Write a program that plays the subtraction game (Nim). We have written a simpliedversion before….as a reminder, The game is such that there are initially 21 stones. Eachplayer takes turns removing 1-3 stones on their turn (their choice). Play alternates back andforth. The person who takes the last stone is the loser…Rather than having another player have a computer AI remove 1-3 stones randomly (to adegree, when 4 stones or less hard-coded choices). Create at least two functions, aiMove,and userMove…these functions should return the amount of stones to take from the pot.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

code:

import random

def

main()

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

:

stones = 21;

#TODO:

# – Randomly determine starting player

# – Alternate between AI and User, calling their methods

# – When a player takes the last stone, end the game and state that they lost.

def userTurn(sPile):

“””

A function that asks the user how many stones to take, and returns that amount. It also checks to make sure that

the user enters a valid choice (1-3, or less if the pile of stones doesn’t have 3).

:param sPile the number of stones in the pile

:return the valid number of stones to take —0 is place holder

“””

#TODO: complete the method to ask the user for a number of stones to take (keep asking until valid).

return(0)

def aiTurn(sPile):

“””

A function that randomly generates a number of stones to take…1-3, or use if-statements when 4 or less stones remaining

:param sPile the number of stones in the pile

:return the valid number of stones to take —0 is place holder

“””

#TODO: complete the method to randomly generate the number of stones to take.

return(0)

main()

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER