Explain solidity>state cleanup

State Cleanup

Before a new game starts, we need to clean up old state while keeping ended games inspectable.

Another Helper Function:

Create function _resetGame() private to handle cleanup.

This keeps the code organized and reusable.



What to Reset Before a New Game:

Clear the board with a loop: for (uint i = 0; i < 9; i++) { board[i] = Cell.Empty; }

Reset pending-game fields:
gameAccepted = false;
acceptDeadline = 0;
lastMoveAt = 0;



Calling Helpers:

Keep _endGame focused on the payout and lifecycle flags: gameAccepted = false; , acceptDeadline = 0; , and lastMoveAt = 0; .

Then update startGame to call _resetGame before setting the accept deadline.

This ensures every new game starts with a clean slate, while the last completed board remains readable after GameEnded.



Create _resetGame and integrate it into startGame without clearing the final board in _endGame.

Create _resetGame helper and preserve the final board
8%
1 of 13 requirements passed.
Requirements:
Declares _resetGame function
_resetGame is private
Clears board with loop
Resets gameAccepted to false
Resets acceptDeadline to 0
Resets lastMoveAt to 0
_endGame resets gameAccepted to false
_endGame resets acceptDeadline to 0
_endGame resets lastMoveAt to 0
_endGame leaves board inspectable
startGame calls _resetGame
startGame sets deadline after reset
startGame removes old board loop