From d0de8f867f461e659c6afc4b0a7c2811552dfcb2 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 30 Apr 2024 19:43:40 +0200 Subject: [PATCH] add target arg to sim to search specific words --- src/simulation.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/simulation.ts b/src/simulation.ts index 69e59c9..485ddec 100755 --- a/src/simulation.ts +++ b/src/simulation.ts @@ -18,18 +18,22 @@ async function main() { ).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: 0 }, + ).option( + "-t, --target ", + "Target word to search for.", ).parse(Deno.args); + const length = args.options.length ?? args.options.target?.length ?? 6; - let dict = Dict.from_lines(francais, args.options.length); - if (args.options.file !== undefined) dict = await Dict.from_text_file(args.options.file, args.options.length); + 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 game = Simulator.from_dict_rand(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); console.log(); @@ -37,4 +41,9 @@ async function main() { await runner.play_all(); } +function validate_target(target: string, length: number) { + if (target.length !== length) throw new Error("Invalid target length"); + return target.toLowerCase(); +} + if (import.meta.main) await main();