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.
claimsquare
Override the claimsquare method. Invoke the parent's claimsquare 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 you might append "Steve selects square
getwinner
Override the getwinner method. Invoke the parent's getwinner method and store the result in a variable. If there was a winner, append a string to the log attribute recording the winner eg "Steve wins" Finally, return the result of the parent method.
gameover
Override the gameover method. Invoke the parent's gameover 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 of
tictactoe.py says
from board import Board
To try your code, replace this line with
from loggingboard import LoggingBoard as Board
This assumes your script is called loggingboard.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 stepbystep playback of the choices made by players in the game.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
