#!/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";

import { francais } from "../data/data.ts";

async function main() {
	const args = await new Command().name("simulation")
		.description(
			"Program to simulate TUSMO game with guesser controller.",
		)
		.option(
			"-f, --file <path:string>",
			"Sets dictionnary to use words from (defaults to internal french dict).",
		).option(
			"-n, --length <length:number>",
			"Length of the word to use from the dictionnary.",
			{ default: 6 },
		).option(
			"-w, --wait <wait:number>",
			"Time to wait between guesses, in ms.",
			{ default: 0 },
		).parse(Deno.args);

	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);

	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();
