Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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.

image text in transcribed

image text in transcribed

two situations

image text in transcribed

if incorrect input is entered

image text in transcribed

also number is entered

image text in transcribed

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!

image text in transcribed

image text in transcribed

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.

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago