add TUSMO simulator
This commit is contained in:
parent
5d2ca505d7
commit
1156752e0a
1 changed files with 9 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue