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.