CSE5APG-Semester 2, 2020 Assignment 1 Build a Naughts and Crosses game 1 Assignment requirements • Due: 11:55pm, 30/9/ 2020 • This is an individual assignment, and it covers 20% of the final mark for...

Python Assignment in files


CSE5APG-Semester 2, 2020 Assignment 1 Build a Naughts and Crosses game 1 Assignment requirements • Due: 11:55pm, 30/9/ 2020 • This is an individual assignment, and it covers 20% of the final mark for CSE5APG. • Your work should be submitted by the due date online via the LMS. • All submissions will be checked by TURNITIN plagiarism software . Any copy-paste will be referred to LTU academic integrity. So please avoid copy-paste from other or any website. • You should write a piece of code for each process. Do not MANUALLY add, delete, or make any sort of calculation. 2 Assignment description The Assignment 1 will test your understanding and ability to apply what you have learnt throughout the lectures. • Python basics - Lecture 1 and 2 • Data structures - Lecture 3 • Function - Lecture 4 • OOP - Lecture 5 • Exception Handling - Lecture 6 Naughts and Crosses game (aka Tic-Tac-Toe) is a well-known and very simple two-player game. The game consists of a playing grid (3x3 or higher) and two players. The playing grid has a set of squares. The squares will be filled by the players. The two players are known as the Naughts player which will be 1 detonated as ”O” and the Crosses player which will be denoted as ”X”. The playing rules are : • The Naughts player plays with ”O”. • The Crosses player plays with ”X”. • Players take turns by placing ”O” or ”X” on the playing grid square. • Only one player can play at a time- either ”O” or ”X”. • The player makes their selection by entering the location of grid square they want to go (the square they want to fill) • If any of the two players have filled a grid square, then the other player and the same player cannot filled that square. • If any player gets three of their marks (”O” or ”X”.) on the board in a row, column or one of the two diagonals, this player will be the winner. • When the playing grid square fills up with neither player winning, the game terminates with no winner. 2 3 Steps you must complete Please see and run attached code: test.py. You need to convert test.py into a new code using: function, OOP and exception handling. The code should ask the user to key-in the size of playing grid (e.g., 3x3, 6x6, ..etc). For example, current grid and final should be printed using function. In addition, invalid input should be handled. You need to develop three main classes: Board, Player, GameState. Each class must be implemented and tested. It is ex- pected that your program can accept various grid sizes, so all input should be set automatically based on the gird size. The main steps are: 1. Once you run the program, the user will be prompted with a menu. 2. The user will need to enter their choice. 3. This choice will be to either begin the game, or quit. 4. If the user enters an invalid choice, the user should be prompted appro- priately letting them choose once more. 5. The program should not end unless the user chooses otherwise. 6. If the user begins the game, the game will be terminated if one player win the game or all playing grid square have been filled up with neither player winning. 3.1 Main Menu In the main menu, the user will be prompt with a menu consisting two choices. • Begin the game • Quit the game This will menu will be printed out to the screen. Pseudo Code print ("introduction message") print ("choices for the user") 3.2 User enter choice The user will enter their choice. Which will result in the following. • Begin game should prompt with The game has begun then return to the main menu. • The quit game, should break out of the loop and stop the program. 3 Pseudo Code userinput = input("ask user to input") 3.3 Check User Input The users choice should be checked to see if it is valid. If not then throws a custom error. Pseudo Code if invalid input: raise InputValidError() 3.4 Throw custom error if user input is invalid Please implement a custom error. This custom error should be caught be a try catch error. Pseudo Code class InvalidInputError(Exception): pass 4 Overview of flow of code Pseudo Code # 1. Prompt the user with the main menu while True: # 2. Infinite loop until user exits. if check if user quits: # 2. if the user quits, break out of loop elif is choice valid: # execute users choice # back to main menu else: raise InvalidError() 5 Classes Information The Assignment 1 will consist of developing three main classes: Board, Player, GameState. 4 Note Helper classes can be designed to support the 3 main classes. These classes will not be graded. These support classes do not have to be tested. 6 The Main Three Below is a detailed UML diagrams explaining how the classes are related to each other. Note The UML diagram is a guide. If you wish to design your structure, you may do so. However, you must test your classes to prove that it works and follow the guide lines to receive top marks. 6.1 Overview of class relationship �Main� main Board GameState Player 7 Board 7.1 Relationship Board – display board(board: list) + check board(board: list, gameover: bool) 5 7.2 Class Pseudo Code class Board: def display_board(board): pass def check_board(board, gameover): pass 8 Player 8.1 Relationship Player – interaction(board: list) + update board(board: list, gameover: bool) 8.2 Class Pseudo Code class Player: def __init__(self, symbol): pass def _interaction(self): pass def update_board(self, board): pass def __str__(self): pass 9 GameState 9.1 Relationship GameState – interaction(board: list) + update board(board: list, gameover: bool) 6 9.2 Class Pseudo Code class GameState: def __init__(self, p1, p2): pass def turn(self, board): pass def place(self, player, old_board): pass def game_loop(self, board): pass 7 Assignment requirements Assignment description Steps you must complete Main Menu User enter choice Check User Input Throw custom error if user input is invalid Overview of flow of code Classes Information The Main Three Overview of class relationship Board Relationship Class Player Relationship Class GameState Relationship Class
Sep 30, 2021CSE5APGLa Trobe University
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here