From 3745313fb9e73e8f3229fc2f50c7b77bda373880 Mon Sep 17 00:00:00 2001 From: Inga Date: Tue, 19 Nov 2024 20:53:33 +0000 Subject: [PATCH] do not crash on large boards, fall back to manual play --- src/shared/gameplay/boardgame.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shared/gameplay/boardgame.ts b/src/shared/gameplay/boardgame.ts index 9655ca0..fcf2cc7 100644 --- a/src/shared/gameplay/boardgame.ts +++ b/src/shared/gameplay/boardgame.ts @@ -21,8 +21,14 @@ export const getTargetGameState = (state: BoardgameState, rules: GameRules) => { return state; } - const solutions = getAllSolutions(state.rows, state.columns, rules); - const nextMove = createOpponent(solutions).getNextMove(state.board, state.currentPlayer); - const newState = state.withMove(nextMove.row, nextMove.column); - return newState; + try { + const solutions = getAllSolutions(state.rows, state.columns, rules); + const nextMove = createOpponent(solutions).getNextMove(state.board, state.currentPlayer); + const newState = state.withMove(nextMove.row, nextMove.column); + return newState; + } catch (err) { + // Fall back to non-auto play + console.error(err); + return state; + } };