Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use python 3.6 to finish the work Use the initial code below: #Display the rules of the game print( Welcome to the game of Nim!
Use python 3.6 to finish the work
Use the initial code below:
#Display the rules of the game print(" Welcome to the game of Nim! I'm probably going to win...") print('''Nim is a simple two-player game based on removing stones. The game begins with two piles of stones, numbered 1 and 2. Players alternate turns. Each turn, a player chooses to remove one, two, or three stones from some single pile. The player who removes the last stone wins the game.''') play_str=input("Would you like to play? (0=no, 1=yes) ") while int(play_str) != 0: # Fill in the good stuff here instead of the following print print("Testing:",play_str) play_str = input(" Would you like to play again? (0=no, 1=yes) ") else: print(" Thanks for playing! See you again soon!")Assignment Background Nim is a mathematical game of strategy in which two players take turns removing objects from distindt piles. The game will be played between the human player and the computer player. In this project, you will handle the computer player while a user plays the game. Choosing the optimal game strategy is complicated and will likely require you to do things that we have not covered yet. We will use a simplified version here The rules: Given two piles, numbered 1 and 2, in which each pile contains some numbers of stones In each turn, a player can choose only one pile and remove one, two, or three stones from that pile. The player who cannot move is considered to lose the game (i.e., the one who takes the last stone is the winner). " Project Description Your program must meet the following specifications. Note that control gets complex to play this game: (one instructor used 4 while loops and 7 if statements) The program begins by offering a welcome message and display the rules of the game. Then, asking the player if he wants to play the game. That control is provided in the starting code provided 1. Initialize both piles to have 5 stones each. 2. You will need a while loop to play the game (this will be in addition to the while loop in the provided code that is used to ask whether the human player wants to play another game.) What Boolean expression should control this loop? Hint: think about the size of piles Play alternates between the human and computer. Use a Boolean variable to keep track of who is playing. The human player starts 3. 4. Within this while loop: a. When it is the human player's turn i. First prompt for the pile (1 or 2). Continue prompting until valid pile number is entered. A valid pile is non-empty and numbered 1 or 2. Next prompt for a number of stones to be removed from that pile. Continue prompting until a valid number of stones is entered. ii. b. When it is the computer's turn: Assignment Background Nim is a mathematical game of strategy in which two players take turns removing objects from distindt piles. The game will be played between the human player and the computer player. In this project, you will handle the computer player while a user plays the game. Choosing the optimal game strategy is complicated and will likely require you to do things that we have not covered yet. We will use a simplified version here The rules: Given two piles, numbered 1 and 2, in which each pile contains some numbers of stones In each turn, a player can choose only one pile and remove one, two, or three stones from that pile. The player who cannot move is considered to lose the game (i.e., the one who takes the last stone is the winner). " Project Description Your program must meet the following specifications. Note that control gets complex to play this game: (one instructor used 4 while loops and 7 if statements) The program begins by offering a welcome message and display the rules of the game. Then, asking the player if he wants to play the game. That control is provided in the starting code provided 1. Initialize both piles to have 5 stones each. 2. You will need a while loop to play the game (this will be in addition to the while loop in the provided code that is used to ask whether the human player wants to play another game.) What Boolean expression should control this loop? Hint: think about the size of piles Play alternates between the human and computer. Use a Boolean variable to keep track of who is playing. The human player starts 3. 4. Within this while loop: a. When it is the human player's turn i. First prompt for the pile (1 or 2). Continue prompting until valid pile number is entered. A valid pile is non-empty and numbered 1 or 2. Next prompt for a number of stones to be removed from that pile. Continue prompting until a valid number of stones is entered. ii. b. When it is the computer's turn
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started