From 43c835d1eb374f908239d6fdeb469552046d8cde Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 30 Apr 2024 16:41:29 +0200 Subject: [PATCH] add entrypoint for simulations --- src/simulation.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 src/simulation.ts diff --git a/src/simulation.ts b/src/simulation.ts new file mode 100755 index 0000000..d33245b --- /dev/null +++ b/src/simulation.ts @@ -0,0 +1,38 @@ +#!/usr/bin/env -S deno run --allow-read + +import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts"; + +import { Dict, Guesser, Runner, Simulator } from "./lib/lib.ts"; +import { TableLogging } from "./lib/runner.ts"; + +async function main() { + const args = await new Command().name("simulation") + .description( + "Program to simulate TUSMO game with guesser controller.", + ) + .option( + "-d, --dictionnary ", + "Sets dictionnary to use words from.", + { default: "./data/liste_francais.txt" }, + ).option( + "-n, --length ", + "Length of the word to use from the dictionnary.", + { default: 6 }, + ).option( + "-w, --wait ", + "Time to wait between guesses, in ms.", + { default: 500 }, + ).parse(Deno.args); + + const dict = await Dict.from_file(args.options.dictionnary, args.options.length); + + const guesser = new Guesser(dict); + const game = Simulator.from_dict_rand(dict); + console.log("Target is", game.word); + console.log(); + + const runner = new Runner(game, guesser, new TableLogging(), args.options.wait); + await runner.play_all(); +} + +if (import.meta.main) await main();