do not crash on large boards, fall back to manual play

feature/modern-browsers
Inga 🏳‍🌈 1 month ago
parent d6f2d6e407
commit 3745313fb9
  1. 14
      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;
}
};

Loading…
Cancel
Save