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

main
Inga 🏳‍🌈 4 days 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; return state;
} }
const solutions = getAllSolutions(state.rows, state.columns, rules); try {
const nextMove = createOpponent(solutions).getNextMove(state.board, state.currentPlayer); const solutions = getAllSolutions(state.rows, state.columns, rules);
const newState = state.withMove(nextMove.row, nextMove.column); const nextMove = createOpponent(solutions).getNextMove(state.board, state.currentPlayer);
return newState; 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