Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Subject Outline In this assignment, your task in to design a game of Nim in Python. In this game Two players take turns removing objects

Subject Outline In this assignment, your task in to design a game of Nim in Python. In this game "Two players take turns removing objects from distinct heaps or piles. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap/pile. The goal of the game is to avoid taking the last object." (Wikipedia)

In your implementation of the game, there will be 3 piles of objects. At the start of the game, each of the three piles will be initialized by a random number of objects. Random number should be between 5 and 15. The players will take turn picking up objects from the piles. A player can even pick up all items from a single pile. The player that picks up last object (across all piles) loses.

You should use functions in the program. Functions must follow a good programming style, that is, any well-defined task which needs to be executed often, can be moved into its own function.

Following is a sample run of the program. You should follow same display style. You have to handle invalid inputs as well, as demonstrated by several examples in the sample run. IN the given example, initially the game starts with randomly chosen number of objects (7,13,9). The program prompts both players to select a pile and choose how many objects to remove.

Using the above information Select three sets of test data that will demonstrate the 'normal' operation of your program; that is, test data that will demonstrate what happens when a VALID input is entered. Select two sets of test data that will demonstrate the 'abnormal' operation of your program.

Set it out in a tabular form as follows. It is important that the output listings (i.e., screenshots) are not edited in any way.table form is given below...

Subject Outline ===== Welcome to Nim Game ===== Here are the three piles. A: B: ************* C: ********* (7, 13, 9) ******* Player 1, choose your pile (A, B, C): C Choose how many objects to remove: 5 A: ******* B: C: **** (7, 13, 4) ************* Player 2, choose your pile (A, B, C): krypton ERR: Sorry, that is not a valid pile. Player 2, choose your pile (A, B, C): A Choose how many objects to remove: 7 OK A: B: C: (0, 13, 4) ************* **** Player 1, choose your pile (A, B, C): B Choose how many objects to remove: alpha ERR: Sorry, that is not number. a valid Subject Outline Player 1, choose your pile (A, B, C): B Choose how many objects to remove: alpha ERR: Sorry, that is not a valid number. Choose how many objects to remove: 10 A: B: C: **** (0, 3, 4) *** Player 2, choose your pile (A, B, C): C Choose how many objects to remove: 8 ERR: Sorry, there is not enough objects to remove in this pile. Choose how many objects to remove: 4 A: B: C: (0, 3, 0) B *** Player 1, choose your pile (A, B, C): C ERR: Sorry, this pile is already empty. Player 1, choose your pile (A, B, C): Choose how many objects to remove: 1 A: B: C: (0, 2, 0) ** A: LTE Subject Outline Player 2, choose your pile (A, B, C): B B: C: (0, 0, 0) 46 37% 6:58 pm 4G Choose how many objects to remove: 2 OK Player 2 picked up the last object. < < < Player 1 >>> is the WINNER. Thanks for playing. Goodbye. Test data type Normal Normal Normal Abnormal Abnormal Test Data Table The Test reason data it was selected The output expected due to the use of the test data The screenshot of actual output when the test data is used

Step by Step Solution

There are 3 Steps involved in it

Step: 1

nimpy Nim Game program in Python import random print Welcome to Nim Game ary n3 reading random integers in the range of 5 and 15 for j in rangen aryap... 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

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions