When the code is complete it should run with the code I provided…do NOT alter any completed functions, just add in the function that will make the code work.

Write a program that plays the subtraction game (Nim). We have written a simplied version before….as a reminder, The game is such that there are initially 21 stones. Each player takes turns removing 1-3 stones on their turn (their choice). Play alternates back and forth. 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 a degree, 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.

code:

import random

def main():

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()

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.