Question: Please do not use AI TO SOLVE THIS Exercise: Tic Tac Toe Inheritance Background In the context of programming, logging means recording important events as

Please do not use AI TO SOLVE THIS
Exercise: Tic Tac Toe Inheritance
Background
In the context of programming, logging means recording important events as they take place, often for debugging purposes. For this exercise, you'll write a subclass of the Board class from the example tic tac toe program called LoggingBoard which logs a player's moves. When a round finishes, it prints the log.
Instructions
Create a module that imports the Board class from the board module.
Define a subclass of Board called LoggingBoard . Override the following methods from the Board class. For each of the methods below, use the same parameters that the parent methods use.
()
Override the () method. Invoke the parent's () method to initialize the board. Then initialize an attribute called log to an empty list.
claim_square()
Override the claim_square() method. Invoke the parent's claim_square() method to claim the requested square. (Note that if the player made an invalid request, the parent method will raise an error. You don't have to catch this error; just let it percolate up the call stack.) Append a string to the log attribute recording the player's choice (for example, if the player's name is "Steve" and the player selected the square at index 3, you might append "Steve selects square 3").
get_winner()
Override the get_winner() method. Invoke the parent's get_winner() method and store the result in a variable. If there was a winner, append a string to the log attribute recording the winner (e.g., "Steve wins"). Finally, return the result of the parent method.
game_over()
Override the game_over() method. Invoke the parent's game_over() method and store the result in a variable. If the game is over, print the strings in the log (one string per line). Finally, return the result of the parent method.
Trying your code
Line 8 of
tictactoe.py says
from board import Board
To try your code, replace this line with
from logging_board import LoggingBoard as Board
(This assumes your script is called logging_board.py . Please adjust the import statement as needed to match your actual script name.)
Then, run tictactoe. py. If your code works properly, at the end of a round of tic tac toe, you should be presented with a step-by-step playback of the choices made by players in the game.
Please do not use AI TO SOLVE THIS Exercise: Tic

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!