Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE Write a class 'Board' (in Python), representing the board 3x3 in tic-tac-toe, in which each field can be empty or occupied by the

PYTHON CODE

Write a class 'Board' (in Python), representing the board 3x3 in tic-tac-toe, in which each field can be empty or occupied by the symbol of one of the players (O or X).

Class should include:

1. __init__(self) - creates an initial empty board

2. move(self,x,y) - makes the active player move (i.e. X if there are fewer X on the board than a O or O otherwise; move consists of placing the active player symbol on the board field in column X and row y)

(i) if the field is already taken, the method throws an exception

(ii) if the move was successful for the active player, the method returns the player's symbol or None otherwise

(iii) if the move is made on a board where one of the players has already won, the method throws an exception

3. reset(self) - removes all symbols from the board (condition at the beginning of the game )

4. __str__(self) - returns a string representing the board

Test:

board = Board( ) board .move ( 2 , 2) board .move ( 2 , 1) board .move ( 1 , 2) board .move ( 3 , 1)

res = board .move ( 3 , 2) assert res == O

# board .move (2 , 2) #EXPECT board.reset( )

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

=+Is the sex appropriate for the organization?

Answered: 1 week ago

Question

assess the infl uence of national culture on the workplace

Answered: 1 week ago