ITC558 Programming Principles - Assessment item 2 - Assignment 2 - Assignment Help

Task

In this assignment, your task in to design a game ofNim (https://en.wikipedia.org/wiki/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.

===== 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

OK

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 a valid number.

Choose how many objects to remove: 10

OK

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

OK

A:

B: ***

C: (0, 3, 0)

Player 1, choose your pile (A, B, C): C

ERR: Sorry, this pile is already empty.

Player 1, choose your pile (A, B, C): B

Choose how many objects to remove: 1

OK

A:

B: **

C: (0, 2, 0)

Player 2, choose your pile (A, B, C): B

Choose how many objects to remove: 2

OK

A:

B:

C: (0, 0, 0)

Player 2 picked up the last object. <<< Player 1 >>> is the WINNER.

Thanks for playing. Goodbye.

Task 1
Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission. Please ensure that the scanned file and your handwriting are clear and legible. However, it is preferable to draw flowcharts using a drawing software. Here are links to some free drawing tools
• https://www.draw.io/

• www.lucidchart.com

• http://dia-installer.de/

• https://pencil.evolus.vn/


Task 2
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.

Task 3
Implement your algorithm in Python. Comment on your code as necessary to explain it clearly. Run your program using the test data you have selected and complete the final column of test data table above.
Your submission will consist of:
1. Your algorithm through Flowchart/s

2. The table recording your chosen test data and results (it should be a PDF file)

3. Source code for your Python implementation


Create a Word document containing your flowchart (task 1) and test data table (task 2). Your python source code (task 3) must be saved in a file name assA2.py. ATTACH the python code file into the word document and then upload the word file to Turnitin.
It is critically important that your test runs are unmodified outputs from your program, and that these results should be reproducible by the marker running your saved .py python program.

Rationale

This assessment task will work towards assessing the following learning outcome/s:

• be able to analyse the steps involved in a disciplined approach to problem-solving, aglorithm development and coding.

• be able to demonstrate and explain elements of good programming style.

• be able to identify, isolate and correct errors; and evaluate the corrections in all phases of the programming process.

• be able to interpret and implement algorithms and program code.

• be able to apply sound program analysis, design, coding, debugging, testing and documentation techniques to simple programming problems.

• be able to write code in an appropriate coding language.

 

 

 

Order Now