Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C that allows two human players to play Nim against each other. Nim is a strategy game between two players. 1.Start

Write a program in C that allows two human players to play Nim against each other.

Nim is a strategy game between two players.

1.Start by placing counters (coins or toothpicks or something) into 3 piles.

Those 3 counters could have a value between 5 and 10.

It is up to you to choose those 3 values.Mine shown in demo below are 3, 4, 5.

2.Player #1 picks a pile, then removes one or more counters from that pile. (It's okay to take the whole pile.)

3.Player #2 picks a pile, then removes one or more counters from that pile.

4.Player #1 plays again. (It's okay to choose a different pile this time.)

5.Whichever player is forced to take the last counter is theloser

Write a program that allows two human players to play Nim against eac

The program should detect when the last counter has been taken and declare a winner.

Here is an example game, with starting piles of 3, 4, and 5 counters.

Player 1, enter your name: Alice Player 2, enter your name: Bob A: 3 B: 4 C: 5 Alice, choose a pile: A How many to remove from pile A: 2 A: 1 B: 4 C: 5 Bob, choose a pile: C How many to remove from pile C: 3 A: 1 B: 4 C: 2 Alice, choose a pile: B How many to remove from pile B: 1 A: 1 B: 3 C: 2 Bob, choose a pile: B How many to remove from pile B: 1 A: 1 B: 2 C: 2 Alice, choose a pile: A How many to remove from pile A: 1 A: 0 B: 2 C: 2 Bob, choose a pile: B How many to remove from pile B: 1 A: 0 B: 1 C: 2 Alice, choose a pile: C How many to remove from pile C: 2 A: 0 B: 1 C: 0 Bob, choose a pile: B How many to remove from pile B: 1 A: 0 B: 0 C: 0 Alice, there are no counters left, so you WIN! 

Bonus #1 - Cheat Protection

For +30 bonus points, prevent the users from doing anything bad:

...a game already in progress. A: 0 B: 1 C: 0 Bob, choose a pile: A Nice try, Bob. That pile is empty. Choose again: B How many to remove from pile B: 0 You must choose at least 1. How many? 1 A: 0 B: 0 C: 0 

And what about this?

A: 1 B: 4 C: 5 Bob, choose a pile: C How many to remove from pile C: 8 Pile C doesn't have that many. Try again: 3 A: 1 B: 4 C: 2 

And don't forget this:

A: 1 B: 4 C: 5 Bob, choose a pile: C How many to remove from pile C: -2 You must choose at least 1. How many? 3 A: 1 B: 4 C: 2 

Bonus #2 - Dignity

For +10 bonus points, make your program detect when there is only one counter left and declare the winner one turn earlier.

...a game already in progress. A: 0 B: 2 C: 2 Bob, choose a pile: B How many to remove from pile B: 1 A: 0 B: 1 C: 2 Alice, choose a pile: C How many to remove from pile C: 2 A: 0 B: 1 C: 0 Bob, you must take the last remaining counter, so you lose. Alice wins! 

Bonus #3 - Fancy Display (Rows)

For +15 bonus points, visually display the counters in rows instead of just showing a number. You must use loops for this.

A: *** B: **** C: ***** Alice, choose a pile: A How many to remove from pile A: 2 A: * B: **** C: ***** Bob, choose a pile: C How many to remove from pile C: 3 A: * B: **** C: ** 

Bonus #4 - Fancy Display (Columns)

For +25 bonus points, visually display the counters in columns. You must use a loop for this.

This is quite difficult.

 * * * * * * * * * * * * A B C Alice, choose a pile: A How many to remove from pile A: 2 * * * * * * * * * * A B C Bob, choose a pile: C How many to remove from pile C: 3 * * * * * * * A B C

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago