From 1156752e0acb0420aac55aea9bfcdf55db908c96 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 30 Apr 2024 16:40:51 +0200 Subject: [PATCH] add TUSMO simulator --- src/lib/game/simulator.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/game/simulator.ts b/src/lib/game/simulator.ts index b71a82d..7b4d247 100644 --- a/src/lib/game/simulator.ts +++ b/src/lib/game/simulator.ts @@ -1,8 +1,8 @@ import { Dict } from "../dict.ts"; import { enumerate, range, zip } from "../utils.ts"; -import { GuessResult, Info } from "./game.ts"; +import { Gaming, GuessResult, Info } from "./game.ts"; -export class Simulator { +export class Simulator implements Gaming { word; constructor(word: string) { @@ -15,10 +15,10 @@ export class Simulator { return new Simulator(word); } - try_guess(guess: string): GuessResult { - if (guess === this.word) return { kind: "success" }; + guess(guess_: string, _known: string): GuessResult { + if (guess_ === this.word) return { kind: "success" }; const rest_actual = [...this.word].map((letter) => letter as (string | null)); - const rest_guess = [...guess].map((letter) => letter as (string | null)); + const rest_guess = [...guess_].map((letter) => letter as (string | null)); const info = [...range(0, this.word.length)].map(() => null) as (Info | null)[]; for (const [index, [guessed, actual]] of enumerate(zip(rest_guess, rest_actual))) { @@ -40,4 +40,8 @@ export class Simulator { const informations = info.map((i) => i != undefined ? i : ({ kind: "abscent" }) as Info); return { kind: "failure", informations }; } + + length(): number { + return this.word.length; + } }