|
|
@ -2,7 +2,7 @@ import t from "tap"; |
|
|
|
|
|
|
|
|
|
|
|
import { ExpectedOutcome, FinalOutcome, Player } from "./datatypes.ts"; |
|
|
|
import { ExpectedOutcome, FinalOutcome, Player } from "./datatypes.ts"; |
|
|
|
import { computeAllSolutions, getPreferredNextOutcome } from "./solver.ts"; |
|
|
|
import { computeAllSolutions, getPreferredNextOutcome } from "./solver.ts"; |
|
|
|
import { getBoardOutcome } from "./tictactoe-rules.ts"; |
|
|
|
import { rules } from "./tictactoe-rules.ts"; |
|
|
|
|
|
|
|
|
|
|
|
void t.test("getPreferredNextOutcome", async (t) => { |
|
|
|
void t.test("getPreferredNextOutcome", async (t) => { |
|
|
|
const nextOutcomes: ExpectedOutcome[] = [ |
|
|
|
const nextOutcomes: ExpectedOutcome[] = [ |
|
|
@ -102,9 +102,7 @@ void t.test("computeAllSolutions", async (t) => { |
|
|
|
expectedSolutions: Record<string, ExpectedOutcome>, |
|
|
|
expectedSolutions: Record<string, ExpectedOutcome>, |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
t.matchOnlyStrict( |
|
|
|
t.matchOnlyStrict( |
|
|
|
Object.fromEntries( |
|
|
|
Object.fromEntries(computeAllSolutions(rows, columns, rules).entries()), |
|
|
|
computeAllSolutions(rows, columns, { getBoardOutcome }).entries(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
expectedSolutions, |
|
|
|
expectedSolutions, |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -115,9 +113,7 @@ void t.test("computeAllSolutions", async (t) => { |
|
|
|
expectedSolutionsCount: number, |
|
|
|
expectedSolutionsCount: number, |
|
|
|
expectedSolutionsIncomplete: Record<string, ExpectedOutcome>, |
|
|
|
expectedSolutionsIncomplete: Record<string, ExpectedOutcome>, |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
const allSolutions = computeAllSolutions(rows, columns, { |
|
|
|
const allSolutions = computeAllSolutions(rows, columns, rules); |
|
|
|
getBoardOutcome, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
t.equal(allSolutions.size, expectedSolutionsCount); |
|
|
|
t.equal(allSolutions.size, expectedSolutionsCount); |
|
|
|
t.matchStrict( |
|
|
|
t.matchStrict( |
|
|
|
Object.fromEntries(allSolutions.entries()), |
|
|
|
Object.fromEntries(allSolutions.entries()), |
|
|
|