parent
7ed91f3621
commit
0b77ff5a1d
@ -0,0 +1,20 @@ |
|||||||
|
import { ExpectedOutcome, GameRules } from "./datatypes.ts"; |
||||||
|
import { computeAllSolutions } from "./solver.ts"; |
||||||
|
|
||||||
|
const solverCache = new Map<GameRules, Map<string, Map<string, ExpectedOutcome>>>(); |
||||||
|
|
||||||
|
export const getAllSolutions = (rows: number, columns: number, rules: GameRules) => { |
||||||
|
if (!solverCache.has(rules)) { |
||||||
|
solverCache.set(rules, new Map<string, Map<string, ExpectedOutcome>>()); |
||||||
|
} |
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we have just ensured that it exists.
|
||||||
|
const solverCacheForRules = solverCache.get(rules)!; |
||||||
|
const dimensionsKey = `${rows}x${columns}`; |
||||||
|
if (!solverCacheForRules.has(dimensionsKey)) { |
||||||
|
solverCacheForRules.set(dimensionsKey, computeAllSolutions(rows, columns, rules)); |
||||||
|
} |
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we have just ensured that it exists.
|
||||||
|
return solverCacheForRules.get(dimensionsKey)!; |
||||||
|
}; |
Loading…
Reference in new issue