unified table cell logic between frontend and backend; unified autoplay; implemented autoplay on frontend
parent
0c2ef25b17
commit
6b707f9441
@ -0,0 +1,11 @@ |
||||
export const updateWithQueryParams = (targetUrl: URL, data: Iterable<[string, FormDataEntryValue]>) => { |
||||
for (const [key, value] of data) { |
||||
if (typeof value !== "string") { |
||||
throw new Error("File fields are not supported; falling back to regular form submission"); |
||||
} |
||||
|
||||
targetUrl.searchParams.set(key, value); |
||||
} |
||||
|
||||
return targetUrl; |
||||
}; |
@ -0,0 +1,28 @@ |
||||
import { BoardgameState } from "./boardgame-state.ts"; |
||||
import { CurrentOutcome, GameRules } from "./datatypes.ts"; |
||||
import { createOpponent } from "./opponent.ts"; |
||||
import { getAllSolutions } from "./solver-cache.ts"; |
||||
|
||||
export const getTargetGameState = (state: BoardgameState, rules: GameRules) => { |
||||
if (!state.board) { |
||||
return state; |
||||
} |
||||
|
||||
if (!state.currentPlayer) { |
||||
return state; |
||||
} |
||||
|
||||
if (!state.autoPlayers.has(state.currentPlayer)) { |
||||
return state; |
||||
} |
||||
|
||||
const currentOutcome = rules.getBoardOutcome(state.board); |
||||
if (currentOutcome !== CurrentOutcome.Undecided) { |
||||
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; |
||||
}; |
Loading…
Reference in new issue