add control flags to simulation
This commit is contained in:
parent
aab2e60dab
commit
9d36edecc9
3 changed files with 39 additions and 8 deletions
|
@ -1,6 +1,8 @@
|
|||
export { Dict } from "./dict.ts";
|
||||
export type { Guessing } from "./guesser/guesser.ts";
|
||||
export { BaseGuesser } from "./guesser/base.ts";
|
||||
export { ReducingGuesser } from "./guesser/reducing.ts";
|
||||
export { Simulator } from "./game/simulator.ts";
|
||||
export { ManualProxy } from "./game/proxy.ts";
|
||||
export { Runner } from "./runner.ts";
|
||||
export { Runner, TableLogging, VerboseLogging } from "./runner.ts";
|
||||
export type { LoggingStrategy } from "./runner.ts";
|
||||
|
|
|
@ -20,7 +20,7 @@ export class Runner<Ga extends Gaming, Gu extends Guessing> {
|
|||
}
|
||||
|
||||
async play_all() {
|
||||
this.logging.on_start(this.game.length());
|
||||
this.logging.on_start(this.game.length(), ...this.guesser.declare_properties());
|
||||
while (true) {
|
||||
const result = await this.guesser.guess(async (guess, ...properties) => {
|
||||
const result = await this.game.guess(guess);
|
||||
|
@ -48,7 +48,7 @@ function format_result(result: GuessResult) {
|
|||
return line;
|
||||
}
|
||||
|
||||
interface LoggingStrategy {
|
||||
export interface LoggingStrategy {
|
||||
on_start(length: number, ...properties: string[]): void;
|
||||
on_guess(guess: string, result: GuessResult, ...properties: unknown[]): void;
|
||||
on_finish(turns: Turn[]): void;
|
||||
|
@ -97,7 +97,7 @@ export class TableLogging implements LoggingStrategy {
|
|||
|
||||
on_start(length: number, ...properties: string[]): void {
|
||||
this.columns = properties.map((p) => [p, p.length] as const);
|
||||
this.columns.splice(0, 0, ["guess", length], ["result", length]);
|
||||
this.columns.splice(0, 0, ["guess", length], ["result", Math.max(7, length)]);
|
||||
let line = "";
|
||||
for (const [name, width] of this.columns) line += name.padStart(width) + " ";
|
||||
console.log(line);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue