add control flags to simulation

This commit is contained in:
JOLIMAITRE Matthieu 2024-05-02 16:27:59 +02:00
parent aab2e60dab
commit 9d36edecc9
3 changed files with 39 additions and 8 deletions

View file

@ -2,8 +2,17 @@
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts";
import { BaseGuesser, Dict, Runner, Simulator } from "./lib/lib.ts";
import { TableLogging } from "./lib/runner.ts";
import {
BaseGuesser,
Dict,
Guessing,
LoggingStrategy,
ReducingGuesser,
Runner,
Simulator,
TableLogging,
VerboseLogging,
} from "./lib/lib.ts";
import { francais } from "../data/data.ts";
@ -25,13 +34,23 @@ async function main() {
).option(
"-t, --target <target:string>",
"Target word to search for.",
).parse(Deno.args);
).option(
"-g, --guesser <guesser:string>",
`Guesser to use, available are ${[...guessers.keys()]}.`,
{ default: "reducing" },
)
.option(
"-l, --logger <logger:string>",
`Logger to use, available are ${[...loggers.keys()]}.`,
{ default: "verbose" },
)
.parse(Deno.args);
const length = args.options.length ?? args.options.target?.length ?? 6;
let dict = Dict.from_lines(francais, length);
if (args.options.file !== undefined) dict = await Dict.from_text_file(args.options.file, length);
const guesser = new BaseGuesser(dict);
const guesser = guessers.get(args.options.guesser)!(dict);
let game = Simulator.from_dict_rand(dict);
if (args.options.target !== undefined) game = new Simulator(validate_target(args.options.target, length));
console.log("Target is", game.word);
@ -46,4 +65,14 @@ function validate_target(target: string, length: number) {
return target.toLowerCase();
}
const guessers = new Map<string, (dict: Dict) => Guessing>([
["explorer", (dict: Dict) => new BaseGuesser(dict)],
["reducing", (dict: Dict) => new ReducingGuesser(dict)],
]);
const loggers = new Map<string, LoggingStrategy>([
["verbose", new VerboseLogging()],
["table", new TableLogging()],
]);
if (import.meta.main) await main();