parent
339691baf4
commit
ec1048e603
@ -0,0 +1,22 @@ |
||||
import type { Request } from "express"; |
||||
import { safeGetQueryValue } from "../utils.ts"; |
||||
|
||||
export const getCounterHtml = (req: Request, key: string) => { |
||||
const counter = parseInt(safeGetQueryValue(req, "a") ?? "0", 10); |
||||
return ( |
||||
<> |
||||
<form method="post" is="progressive-form"> |
||||
<button type="submit" name={key} value={`${counter - 1}`} is="reactive-button" track={key} delta="-1"> |
||||
- |
||||
</button>{" "} |
||||
<button type="submit" name={key} value={`${counter + 1}`} is="reactive-button" track={key} delta="+1"> |
||||
+ |
||||
</button> |
||||
</form>{" "} |
||||
Value of "{key}":{" "} |
||||
<span class="counter" is="reactive-span" track={key}> |
||||
{counter} |
||||
</span> |
||||
</> |
||||
); |
||||
}; |
@ -1,7 +1,7 @@ |
||||
import t, { type Test } from "tap"; |
||||
|
||||
import { Board } from "./board.ts"; |
||||
import { SquareState } from "./datatypes.ts"; |
||||
import { SquareState } from "./types.ts"; |
||||
|
||||
void t.test("Serialize / deserialize", async (t) => { |
||||
const createAndCheckBoard = (t: Test, serialized: string) => { |
@ -1,5 +1,5 @@ |
||||
import { repeat } from "./array-utils.ts"; |
||||
import { BoardType, SquareState, formatSquareState, parseSquareState } from "./datatypes.ts"; |
||||
import { repeat } from "../utils/array-utils.ts"; |
||||
import { BoardType, SquareState, formatSquareState, parseSquareState } from "./types.ts"; |
||||
|
||||
export class Board implements BoardType { |
||||
// State should be immutable
|
@ -1,7 +1,7 @@ |
||||
import t, { type Test } from "tap"; |
||||
|
||||
import { BoardgameState } from "./boardgame-state.ts"; |
||||
import { Player, SquareState } from "./datatypes.ts"; |
||||
import { Player, SquareState } from "./types.ts"; |
||||
|
||||
const createAndCheckBoardgameState = (t: Test, serialized: string) => { |
||||
const boardgameState = BoardgameState.fromSerialized(serialized); |
@ -1,4 +1,4 @@ |
||||
import { unreachableString } from "./utils.ts"; |
||||
import { unreachableString } from "../utils/utils.ts"; |
||||
|
||||
export enum SquareState { |
||||
Unoccupied = 1, // so that all SquareState values are truthy
|
@ -1,7 +1,7 @@ |
||||
import t from "tap"; |
||||
|
||||
import { Board } from "./board.ts"; |
||||
import { CurrentOutcome, SquareState } from "./datatypes.ts"; |
||||
import { Board } from "../datatypes/board.ts"; |
||||
import { CurrentOutcome, SquareState } from "../datatypes/types.ts"; |
||||
import { getBoardOutcome, getSequenceOutcome } from "./tictactoe-rules.ts"; |
||||
|
||||
void t.test("getSequenceOutcome", async (t) => { |
@ -1,4 +1,4 @@ |
||||
import { CurrentOutcome, GameRules, SquareState } from "./datatypes.ts"; |
||||
import { CurrentOutcome, GameRules, SquareState } from "../datatypes/types.ts"; |
||||
|
||||
export const getSequenceOutcome = (sequence: SquareState[]) => { |
||||
for (let i = 1; i < sequence.length; i++) { |
@ -1,9 +1,9 @@ |
||||
import t, { Test } from "tap"; |
||||
|
||||
import { Board } from "./board.ts"; |
||||
import { ExpectedOutcome, FinalOutcome, Opponent, Player, getOccupiedStateByPlayer } from "./datatypes.ts"; |
||||
import { createOpponent } from "./opponent.ts"; |
||||
import { computeAllSolutions } from "./solver.ts"; |
||||
import { Board } from "../datatypes/board.ts"; |
||||
import { ExpectedOutcome, FinalOutcome, Opponent, Player, getOccupiedStateByPlayer } from "../datatypes/types.ts"; |
||||
import { createOpponent } from "../gameplay/opponent.ts"; |
||||
import { computeAllSolutions } from "../gameplay/solver.ts"; |
||||
import { rules } from "./tictactoe-rules.ts"; |
||||
|
||||
void t.test("computeAllSolutions", async (t) => { |
@ -1,5 +1,5 @@ |
||||
import { BoardgameState } from "./boardgame-state.ts"; |
||||
import { CurrentOutcome, GameRules } from "./datatypes.ts"; |
||||
import { BoardgameState } from "../datatypes/boardgame-state.ts"; |
||||
import { CurrentOutcome, GameRules } from "../datatypes/types.ts"; |
||||
import { createOpponent } from "./opponent.ts"; |
||||
import { getAllSolutions } from "./solver-cache.ts"; |
||||
|
@ -1,6 +1,6 @@ |
||||
import t from "tap"; |
||||
import { Board } from "./board.ts"; |
||||
import { ExpectedOutcome, FinalOutcome, Player, getOccupiedStateByPlayer } from "./datatypes.ts"; |
||||
import { Board } from "../datatypes/board.ts"; |
||||
import { ExpectedOutcome, FinalOutcome, Player, getOccupiedStateByPlayer } from "../datatypes/types.ts"; |
||||
import { createOpponent } from "./opponent.ts"; |
||||
|
||||
void t.test("createOpponent", async (t) => { |
@ -1,4 +1,4 @@ |
||||
import { ExpectedOutcome, Opponent, SquareState, getOccupiedStateByPlayer } from "./datatypes.ts"; |
||||
import { ExpectedOutcome, Opponent, SquareState, getOccupiedStateByPlayer } from "../datatypes/types.ts"; |
||||
|
||||
export const createOpponent = (outcomesByBoard: Map<string, ExpectedOutcome>): Opponent => { |
||||
const getNextMove: Opponent["getNextMove"] = (board, currentPlayer) => { |
@ -1,4 +1,4 @@ |
||||
import { ExpectedOutcome, GameRules } from "./datatypes.ts"; |
||||
import { ExpectedOutcome, GameRules } from "../datatypes/types.ts"; |
||||
import { computeAllSolutions } from "./solver.ts"; |
||||
|
||||
const solverCache = new Map<GameRules, Map<string, Map<string, ExpectedOutcome>>>(); |
@ -1,6 +1,6 @@ |
||||
import t, { type Test } from "tap"; |
||||
|
||||
import { CurrentOutcome, ExpectedOutcome, FinalOutcome, GameRules, Player, SquareState } from "./datatypes.ts"; |
||||
import { CurrentOutcome, ExpectedOutcome, FinalOutcome, GameRules, Player, SquareState } from "../datatypes/types.ts"; |
||||
import { computeAllSolutions, getPreferredNextOutcome } from "./solver.ts"; |
||||
|
||||
void t.test("getPreferredNextOutcome", async (t) => { |
Loading…
Reference in new issue