add manual proxied game solving
This commit is contained in:
parent
f7ebdbf9b3
commit
e058363a52
4 changed files with 83 additions and 0 deletions
1
build.sh
1
build.sh
|
@ -4,4 +4,5 @@ cd "$(dirname "$(realpath "$0")")"
|
||||||
|
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
|
||||||
|
deno compile -o bin/manual_proxy src/manual_proxy.ts
|
||||||
deno compile -o bin/simulation src/simulation.ts
|
deno compile -o bin/simulation src/simulation.ts
|
||||||
|
|
43
src/lib/game/proxy.ts
Normal file
43
src/lib/game/proxy.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { assertExists } from "https://deno.land/std@0.224.0/assert/assert_exists.ts";
|
||||||
|
|
||||||
|
import { Awaitable } from "../utils.ts";
|
||||||
|
import { Gaming, GuessResult, Info } from "./game.ts";
|
||||||
|
|
||||||
|
export class ManualProxy implements Gaming {
|
||||||
|
word_length;
|
||||||
|
|
||||||
|
constructor(length: number) {
|
||||||
|
this.word_length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
guess(guess: string, _known: string): Awaitable<GuessResult> {
|
||||||
|
console.log("<proxy> Guessing:", guess);
|
||||||
|
return read_until_correct(this.word_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
length(): number {
|
||||||
|
return this.word_length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_until_correct(length: number): GuessResult {
|
||||||
|
while (true) {
|
||||||
|
const input = prompt("<proxy> Result:");
|
||||||
|
assertExists(input);
|
||||||
|
const informations = parse_input(input, length);
|
||||||
|
if (informations === null) continue;
|
||||||
|
if (informations.every((i) => i.kind === "there")) return { kind: "success" };
|
||||||
|
return { kind: "failure", informations };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_input(input: string, length: number) {
|
||||||
|
const parsed = [] as Info[];
|
||||||
|
for (const character of input.trim()) {
|
||||||
|
if (character === "n") parsed.push({ kind: "abscent" });
|
||||||
|
if (character === "i") parsed.push({ kind: "somewhere" });
|
||||||
|
if (character === "y") parsed.push({ kind: "there" });
|
||||||
|
}
|
||||||
|
if (parsed.length !== length) return null;
|
||||||
|
else return parsed;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
export { Dict } from "./dict.ts";
|
export { Dict } from "./dict.ts";
|
||||||
export { Guesser } from "./guesser.ts";
|
export { Guesser } from "./guesser.ts";
|
||||||
export { Simulator } from "./game/simulator.ts";
|
export { Simulator } from "./game/simulator.ts";
|
||||||
|
export { ManualProxy } from "./game/proxy.ts";
|
||||||
export { Runner } from "./runner.ts";
|
export { Runner } from "./runner.ts";
|
||||||
|
|
38
src/manual_proxy.ts
Normal file
38
src/manual_proxy.ts
Normal file
|
@ -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, ManualProxy, Runner } from "./lib/lib.ts";
|
||||||
|
import { VerboseLogging } from "./lib/runner.ts";
|
||||||
|
|
||||||
|
import { francais } from "../data/data.ts";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const args = await new Command().name("manual_proxy")
|
||||||
|
.description(
|
||||||
|
"Program to solve manually proxied TUSMO games 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 = new ManualProxy(args.options.length);
|
||||||
|
|
||||||
|
const runner = new Runner(game, guesser, new VerboseLogging(), args.options.wait);
|
||||||
|
await runner.play_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import.meta.main) await main();
|
Loading…
Add table
Add a link
Reference in a new issue