Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sample output: --------------------------------------- Starting new Numerical Tic Tac Toe game --------------------------------------- 0 1 2 0 | | ----------- 1 | | ----------- 2 | |

image text in transcribedimage text in transcribed

Sample output:

--------------------------------------- Starting new Numerical Tic Tac Toe game ---------------------------------------

0 1 2 0 | | ----------- 1 | | ----------- 2 | | Player 1, please enter an odd number (1-9): 5 Player 1, please enter a row: 1 Player 1, please enter a column: 1

0 1 2 0 | | ----------- 1 | 5 | ----------- 2 | | Player 2, please enter an even number (2-8): 2 Player 2, please enter a row: 1 Player 2, please enter a column: 0

0 1 2 0 | | ----------- 1 2 | 5 | ----------- 2 | | Player 1, please enter an odd number (1-9): 1 Player 1, please enter a row: 0 Player 1, please enter a column: 2

0 1 2 0 | | 1 ----------- 1 2 | 5 | ----------- 2 | | Player 2, please enter an even number (2-8): 8 Player 2, please enter a row: 1 Player 2, please enter a column: 2

0 1 2 0 | | 1 ----------- 1 2 | 5 | 8 ----------- 2 | | Player 2 wins. Congrats! Do you want to play another game? (Y/N) n Thanks for playing! Goodbye.

Please help me with this, I don't know how to do it

Background Information: Numerical Tic Tac Toe is a game for two players who take turns filling in a 3 by 3 grid with the numbers 1-9. The first player places an odd number in an empty square, and then the second player places an even number in an empty square. The players' turns continue to alternate until: 1) a player completes a line of three squares (horizontal, vertical, or diagonal) that adds up to 15 in which case, the current player wins; or 2) all nine squares on the board are full, but no line adding to 15 is formed - in which case, it's a tie. Note that player 1 must always place an odd number on the board, and player 2 an even number. In addition, each number from 1 to 9 can only appear on the board once. To view a complete sample game, please refer to lab3_sampleOut.txt on eClass. Problem Description: A colleague has already written a program to control the flow of this game, assuming that there was a Numerical Tic Tac Toe class. However, no such class currently exists. It is up to you to write the class, so that an instance of it can then be used in your colleague's program. Part 1: Download and save a copy of lab3_NumTicTacToe.py. This file contains the skeleton code for a class called NumTicTac Toe, which you will complete. 1. The init_method has been completed for you. Notice that it initializes two attributes: board and size. The size attribute defines how many rows (and columns) are on the board. The board attribute represents an empty 3 by 3 board it is a list of lists, where each internal list represents a row on the board. The value 0 is used to represent an empty square. Run the test provided (i.e. by running lab3_Num Tic Tac Toe.py) to test this method before moving on: self.board should be [[0, 0, 0], [0, 0, 0], [0, 0, 0]] 2. Complete the drawBoard method so that it displays the current state of the board, along with the column indices on top of the board, and the row indices to the left of the board. If the content of a given square is 0, an empty space should be displayed. Test your method before moving on: When self.board is [[0, 0, 0], [0, 0, 0], [0, 0, 0]], the following should be printed: 0 1 2 1 0 1 1 1 2 1 3. Complete the squarelsEmpty(row, col) method. This method checks the contents of the board at the given row index (integer) and column index (integer). If the board at that square is empty, the method returns True. Otherwise, the method returns False. Test your method before moving on. 4. Complete the update(row, col, num) method. This method should check if the square at the provided row index (integer) and column index (integer) is empty. (Hint: do you already have a method you can invoke to check this?) If it is "empty, the contents of the board at that square should be changed to num (integer). If the square is successfully updated, this method should return True. If the square is not empty, the contents of the board should not be changed, and the method should return False. Test your method. 5. Complete the boardFull() method. This method returns True if there are no empty squares, False otherwise. Test this method. Which cases should you consider? 6. Complete the is Winner() method. This method returns True if there is one line of three squares (horizontal, vertical, or diagonal) that adds up to 15. Otherwise, it returns False. Test this method. Which cases should you consider? Demo your completed class to your TA, along with your tests. Be ready to explain which aspects you tested and why

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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago