Microsoft Word - Assignment 2 - Dominoes Assignment 2 – Dominoes 175 style Due Date: Wednesday, March 24th 2021 at 23:55 (Edmonton time) Percentage overall grade: 7% Penalties: No late assignments...

dominoes python program


Microsoft Word - Assignment 2 - Dominoes Assignment 2 – Dominoes 175 style Due Date: Wednesday, March 24th 2021 at 23:55 (Edmonton time) Percentage overall grade: 7% Penalties: No late assignments allowed Maximum marks: 100 Assignment Specification You are tasked with creating a one-player tile-matching game, played with one standard "double-six" set of dominoes. A domino is a tile with two ends, where each end has 0 to 6 dots on it. For example, a domino with 3 dots on one end and 4 dots on the other end is shown below: A standard double-six domino set contains the 28 unique dominoes illustrated below: The game will start with all 28 dominoes face down in a grid with 7 columns and 4 rows. (i.e. by face down, we mean that the player can only see the back of the domino, not the side with all of the dots.) The player will choose a domino from the grid and turn it over. The player will then attempt to play the domino by adding it to the top of one of three stacks of dominoes in the play area. If a stack is empty (i.e. it does not currently contain any dominoes), any domino can be added to it and the player can decide on the orientation of the domino (i.e. which end is at the top and which end is at the bottom). If a stack has at least one domino currently in it, a new domino can only be added to the top of the stack if one of its ends has the same number of dots as the top end of the domino that is currently on the top of the domino stack. In that case, the domino must be added to the stack so that the end of the domino with the matching number of dots is oriented to the bottom (i.e. touching the side with the matching number of dots on the domino already on the stack), as illustrated below: This domino can be added to the top of Stack 0 or Stack 2, but not Stack 1. Stack 0 Stack 1 Stack 2 or (before domino is played) (after domino is played) The player continues to draw dominoes from the grid and adding them to a stack in the play area until one of the stacks reaches a height of 6 dominoes (win) or the player cannot play the domino on any of the 3 stacks in the play area (lose). Task 1: Domino class Create a Python file called domino175.py. Inside this file, create and test a Domino class according to the description below. Note that the following methods form the public interface for this class – you must complete them all as specified, and cannot add additional methods to the public interface. However, you can include additional private helper methods that are only called within this class, if you wish. Domino(dotsA, dotsB) – creates a domino, where the number of dots on each end of the domino are described by the integers dotsA and dotsB. After asserting that the input parameters are valid, dotsA and dotsB should be used to initialize two private attributes: top and bottom. Both of these attributes are integers, and the top is the end with the most dots on it. A third private attribute, faceDown, should also be created which indicates if the tile is facing down (True) or facing up (False). A domino should be facing up when it is first created. setTop(dots) – updates which end of the Domino is at the top, according to the dots parameter. The integer dots must match one of the existing ends of the Domino instance (otherwise an AssertionError is raised). Nothing is returned. turnOver() – updates the Domino instance so that if it was facing up, it will now be facing down. Similarly, if it was facing down, it will now be facing up. Nothing is returned. getTop() – returns the integer number of dots on the top end of the Domino instance. getBottom() – returns the integer number of dots on the bottom end of the Domino instance. isFaceDown() – returns the Boolean value indicating whether the Domino instance is facing down (True) or up (False). __str__() – returns the string representation of the Domino instance. The format of this string should be '[bottom number of dots|top number of dots]' if it is facing up. For example, a domino with 3 dots on the bottom and 4 dots on top will return the string '[3|4]'. Any domino that is facing down will have question marks, '?', instead of the numbers: '[?|?]' Test your Domino class thoroughly before moving on. You may wish to use assertions to verify expected behaviour, like in Lab 7 (Linked Lists), though you don’t have to. Place these tests under if __name__ == "__main__": in domino175.py for the marker to see. Task 2: DominoDeck class Create and test a DominoDeck class in domino175.py, according to the description below. Note that the following methods form the public interface for this class – you must complete them all as specified, and cannot add additional methods to the public interface. However, you can include additional private helper methods that are only called within this class, if you wish. DominoDeck() – creates an empty deck of dominoes, capable of holding the 28 dominoes in a standard "double-six" set. Notice that this deck acts very much like a queue, where we deal the front domino and add new dominoes to the rear of the deck. In the __init__ method, create a single private attribute that is the most time-efficient queue with a maximum capacity that we covered in the lectures. You should import the queues.py file provided with Lab 6 to accomplish this. (You do not need to submit the queues.py file since your marker will also have access to that file.) populate(useFile) – modifies the deck by adding new dominoes face up to the rear of the deck. Nothing is returned.  If useFile is True, the user should be prompted to provide the name of an input text file. If any problem occurs when opening the file, an error message should be displayed and the user should be re-prompted to provide the name of another input text file, until the file can be opened successfully. (See output_testWin.txt.) The input text file should contain information about the dominoes that will be added to the deck, in the same order as indicated in the file. (i.e. The first line of the text file corresponds to the first domino that should be added to the deck.) Each valid line of the text file will contain an integer, followed by a forward slash ('/'), followed by another integer, where the integers represent the number of dots on each end of the domino. (See the sample testWin.txt provided.) You cannot assume that all lines in the file will be valid, and you cannot assume that there will be information for exactly 28 dominoes in the file. If there is invalid data in the file or not 28 dominoes, you should raise an Exception with the argument "Cannot populate deck: invalid data in xx" (where xx is replaced with the filename), ensure the deck is empty, and close the file before leaving this method. If there is information about exactly 28 valid dominoes in the file, you can assume that those dominoes will form a full "double-six" set which should be added to the deck, in the same order that they appear in the file.  If useFile is False, a complete "double-six" set of dominoes should be created, shuffled, and used to populate the deck.  If useFile is not True or False, an AssertionError should be raised with the argument "Cannot populate deck: invalid argument provided." Nothing should be added to the deck in this case. deal() – modifies the deck by removing the domino from the front of the deck, and returns that front domino, face down. Raise an Exception if the deck is empty, with the argument 'Cannot deal domino from empty deck'. This method should have an O(1) time efficiency. isEmpty() – returns a Boolean value indicating whether there are no dominoes in the deck (True) or if there is at least one domino in the deck (False). size() – returns the integer number of dominoes currently in the deck. __str__() – returns the string representation of all of the dominoes in the deck. You can decide how this string should be formatted, but make it clear which is the front domino and be sure to show the number of dots on each domino (i.e. do not just show all dominoes as face down) Test your DominoDeck class thoroughly before moving on. Again, place these tests under if __name__ == "__main__": in domino175.py for the marker to see. Task 3: DominoStack class Create and test a DominoStack class in domino175.py, according to the description below. Note that the following methods form the public interface for this class – you must complete them all as specified, and cannot add additional methods to the public interface. However, you can include additional private helper methods that are only called within this class, if you wish. DominoStack() – creates an empty stack that will ultimately hold Domino instances. Nothing is returned. Note that you may use inheritance (in which case you should include the code for the Stack class that you are inheriting from in the domino175.py file), or you can implement from
Mar 16, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here