A mobile game team at NovaPlay wants a simple Tic-Tac-Toe engine that supports gameplay, tracks the running score, and allows resetting either the board or the full match. Implement the core game logic.
Write a function that processes a sequence of commands for a 3x3 Tic-Tac-Toe game. Players alternate as X then O. Valid move commands place the current player's mark on the board. When a player wins, that player's score increases by 1 and the board automatically resets for the next round, starting again with X. A draw also resets the board with no score change. Invalid moves are ignored.
Input: commands, a list of commands where each command is one of:
{"type": "move", "row": int, "col": int}{"type": "reset_board"}{"type": "reset_all"}Output: a dictionary with:
board: final 3x3 board as a list of lists containing "X", "O", or ""current_player: "X" or "O"score: { "X": int, "O": int }Example 1
Input: commands = [{"type":"move","row":0,"col":0},{"type":"move","row":1,"col":0},{"type":"move","row":0,"col":1},{"type":"move","row":1,"col":1},{"type":"move","row":0,"col":2}]
Output: {"board":[["","",""] ,["","",""] ,["","",""]],"current_player":"X","score":{"X":1,"O":0}}
Explanation: X wins across the top row, so the score updates and the board resets.
Example 2
Input: commands = [{"type":"move","row":0,"col":0},{"type":"move","row":0,"col":0},{"type":"reset_board"}]
Output: {"board":[["","",""] ,["","",""] ,["","",""]],"current_player":"X","score":{"X":0,"O":0}}
Explanation: The second move is invalid because the cell is occupied. reset_board clears the board and sets the next player to X.
1 <= len(commands) <= 10^40 <= row, col < 3 for move commands