Python Code Write Class Board Python Representing Board 3×3 Tic Tac Toe Field Empty Occupi Q43840331
PYTHON CODE
Write a class ‘Board’ (in Python), representing the board 3×3 intic-tac-toe, in which each field can be empty or occupied by thesymbol 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 ifthere are fewer X on the board than a O or O otherwise; moveconsists of placing the active player symbol on the board field incolumn X and row y)
(i) if the field is already taken, the method throws anexception
(ii) if the move was successful for the active player, themethod returns the player’s symbol or None otherwise
(iii) if the move is made on a board where one of the playershas already won, the method throws an exception
3. reset(self) – removes all symbols from the board (conditionat 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( )
Expert Answer
Answer to PYTHON CODE Write a class ‘Board’ (in Python), representing the board 3×3 in tic-tac-toe, in which each field can be emp…
OR