-
-
Notifications
You must be signed in to change notification settings - Fork 136
Description
Improvement Summary
We currently have async and synchronous versions of checkGameStateForWin(). We should combine these single, synchronous version that's used everywhere, adding additional processing to the consumers of the current async check-game-state-for-win method to individually handle the side effects added by the async version
Detailed Description
checkGameStateForWin() (the async version) handles side effects of:
- Adding the game to its match
- Updating the game's status to
GameStatus.FINISHEDand setting thewinnerfield if the game is over
It works this way because the method already computes whether a player has won and this is the key info needed to decide whether to clean up the game record as described.
The only place that those side effects really should be applied are in the move and ai-move controller endpoints e.g. when a new move is made, if it ends the game, we should then clean up.
This means we should remove the existing implementation of checkWinGameState() and rename checkWinGameStateSync() to simply checkWinGameState() (keeping it sync without the cleanup side effects), then update all consumers of either method to call checkWinGameState() and for the places that use the previously async version to conditionally execute the cleanup logic (setting game status + winner) in the endpoint itself