Question: Hi this is the Game for C program. This assignment is a variation of a very old game, Nim. In our version of this game,

Hi this is the Game for C program.

This assignment is a variation of a very old game, Nim. In our version of this game, there are 7 matches and 2 players. The players take turns removing 1, 2 or 3 matches from the pile. The player that removes the last match loses.

Have a play with an example game of Nim below. Your final version will be very similar!

Click matches to take them

Click "End Move" To finish the move of the current player

Hi this is the Game for C program. This assignment is a

In this next section, we want to scan in whether Player 1 or Player 2 is to move first.

Recall in Week 1 how we got you to print the following:

Would you like Player 1 to go first? (y) 

This section follows on from that. As a result, your task here is to scan in a character to be used later.

variation of a very old game, Nim. In our version of this

game, there are 7 matches and 2 players. The players take turns

two situations

removing 1, 2 or 3 matches from the pile. The player that

if incorrect input is entered

removes the last match loses. Have a play with an example game

also number is entered

of Nim below. Your final version will be very similar! Click matches

next,

There are three things you will need to do to make a move for the first player:

Get the number of matches to remove from the user

Player 1 move: 1

Let the user know what move has been made

Player 1 removed 1 matches!

Update the number of matches left in the game

There are 6 remaining matches!

to take them Click "End Move" To finish the move of the

current player In this next section, we want to scan in whether

Next we need to limit the number of invalid moves

Currently, the first user can input any number for the matches they want to remove. This could lead to some "useless" inputs such as 0 or 1000. In stage 3, we will have users playing against each other and it would be beneficial if we restricted the moves.

As a result, we only want to consider a move "valid" if 1, 2 or 3 matches are to be removed.

In all other cases, your program to follow on from the examples below.

Player 1 or Player 2 is to move first. Recall in Week

1 how we got you to print the following: Would you like

thank you !!

Example Nim Game Player 1's Turn Matches taken this turn: 0 - Example 2.1.1: Example 1 \$./cs_matches ///comP1511 - CS Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) y You Entered: ' y ' - Example 2.1.2: Example 2 \$./cs_matches ///comP1511 - CS Matches V/ In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) n You Entered: ' n ' In this section, we will use the functionality of the previous section to determine which player will move first. Recall in the previous section how we had this functionality: Would you like Player 1 to go first? (y) y You Entered: ' y ' Your next task here is print which player goes first, based on this input. - If the user inputs, then you should print out Player 1 will go first!. - If the user inputs , then you should print out Player 2 will go first! . You will also need to handle the error case, when the user inputs a different character. As a result, if the user does not enter or then You did not enter ' y ' or ' n ', program now should be printed and your program should end by calling Make sure to look at the examples below for the full output of this section! - Example 2.2.1: Player 1 is first $./ cs_matches /// comP1511 - CS Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) y You Entered: ' y ' Player 1 will go first! The game begins! There are 7 remaining matches! - Example 2.2.2: Player 2 is first $./ cs_matches /// COMP1511 - CS Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) n You Entered: ' n ' Player 2 will go first! The game begins! There are 7 remaining matches! $./ Cs_matches // COMP1511 - CS Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) t You Entered: ' t ' You did not enter ' y ' or " n ', program now exiting... \$./cs_matches /// COMP1511 - CS Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) 5 You Entered: ' 5 ' You did not enter ' y ' or ' n ', program now exiting... - Example 2.3.1: Basic Example $./ cs_matches /// comp1511 - cs Matches V/// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) y You Entered: ' y ' Player 1 will go first! The game begins! There are 7 remaining matches! Player 1 move: 1 Player 1 removed 1 matches! There are 6 remaining matches! $./ cs_matches // COMP1511 - CS Matches /// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? ( y) y You Entered: ' y ' Player 1 will go first! The game begins! There are 7 remaining matches! Player 1 move: 3 Player 1 removed 3 matches! There are 4 remaining matches! - Example 2.3.3: Player 2 starts $./cs_matches // comP1511 - CS Matches V// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) n You Entered: 'n' Player 2 will go first! The game begins! There are 7 remaining matches! Player 2 move: 2 Player 2 removed 2 matches! There are 5 remaining matches! $./ cs_matches V / / COMP1511 - cs Matches // In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? ( y) y You Entered: ' y ' Player 1 will go first! The game begins! There are 7 remaining matches! Player 1 move: 0 Player 1 is not allowed to remove matches! There are 7 remaining matches! - Example 2.4.2: Attempt to remove 4 matches $./cs_matches / \ COMP1511 - cs Matches // In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? ( y) y You Entered: ' y ' Player 1 will go first! The game begins! There are 7 remaining matches! Player 1 move: 4 Player 1 is not allowed to remove 4 matches! There are 7 remaining matches! - Example 2.4.3: Attempt to remove 1000 matches \$./cs_matches /// comp1511 - cS Matches /// In this game, 2 players will take turns removing matches. Each player can remove 1,2 or 3 matches in any turn. Would you like Player 1 to go first? (y) n You Entered: ' n ' Player 2 will go first! The game begins! There are 7 remaining matches! Player 2 move: 1600 Player 2 is not allowed to remove 1000 matches! There are 7 remaining matches

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!