Compare commits
5 commits
241bcd29e3
...
3ac586e7e1
Author | SHA1 | Date | |
---|---|---|---|
3ac586e7e1 | |||
be91004c3a | |||
c5e439e567 | |||
57f78a4db1 | |||
fbfcd43799 |
7 changed files with 357648 additions and 9 deletions
2
data/data.ts
Normal file
2
data/data.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export { default as gutenberg } from "./gutenberg.txt.json" with { type: "json" };
|
||||
export { default as francais } from "./francais.txt.json" with { type: "json" };
|
21076
data/francais.txt.json
Normal file
21076
data/francais.txt.json
Normal file
File diff suppressed because it is too large
Load diff
23
data/generate.ts
Executable file
23
data/generate.ts
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env -S deno run --allow-read --allow-write
|
||||
|
||||
import { join } from "https://deno.land/std@0.224.0/path/join.ts";
|
||||
import { dirname } from "https://deno.land/std@0.224.0/path/dirname.ts";
|
||||
|
||||
async function main() {
|
||||
const script_path = new URL(import.meta.url).pathname;
|
||||
const data_dir = dirname(script_path);
|
||||
|
||||
for await (const entry of Deno.readDir(data_dir)) {
|
||||
if (!entry.isFile) continue;
|
||||
if (!entry.name.endsWith("txt")) continue;
|
||||
|
||||
const content = await Deno.readTextFile(join(data_dir, entry.name));
|
||||
const lines = content.split("\n").map((l) => l.trim());
|
||||
|
||||
const json_path = join(data_dir, entry.name + ".json");
|
||||
const serialized = JSON.stringify(lines, null, 2);
|
||||
await Deno.writeTextFile(json_path, serialized);
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) await main();
|
336532
data/gutenberg.txt.json
Normal file
336532
data/gutenberg.txt.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -9,10 +9,9 @@ export class Dict {
|
|||
this.letters = new Set([...words.values()].map((w) => w.split("")).flat());
|
||||
}
|
||||
|
||||
static async from_file(path: string, length: number) {
|
||||
static from_lines(lines: string[], length: number) {
|
||||
const words = new Set<string>();
|
||||
const content = await Deno.readTextFile(path);
|
||||
for (const word of content.split("\n")) {
|
||||
for (const word of lines) {
|
||||
const word_ = word.trim().toLowerCase();
|
||||
if (word_.length !== length) continue;
|
||||
if (contains_any(word_, [" ", "-", "."])) continue;
|
||||
|
@ -21,8 +20,13 @@ export class Dict {
|
|||
return new Dict(words, length);
|
||||
}
|
||||
|
||||
static async from_text_file(path: string, length: number) {
|
||||
const content = await Deno.readTextFile(path);
|
||||
return Dict.from_lines(content.split("\n"), length);
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")]() {
|
||||
return `Dict { ${this.words.size} words }`;
|
||||
return `Dict { ${this.words.size} words, ${this.letters.size} letters }`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,16 @@ 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(
|
||||
"-d, --dictionnary <path:string>",
|
||||
"Sets dictionnary to use words from.",
|
||||
{ default: "./data/liste_francais.txt" },
|
||||
"-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.",
|
||||
|
@ -21,10 +22,11 @@ async function main() {
|
|||
).option(
|
||||
"-w, --wait <wait:number>",
|
||||
"Time to wait between guesses, in ms.",
|
||||
{ default: 500 },
|
||||
{ default: 0 },
|
||||
).parse(Deno.args);
|
||||
|
||||
const dict = await Dict.from_file(args.options.dictionnary, args.options.length);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue