binmat
Version:
binmat simulator
40 lines (39 loc) • 2.23 kB
TypeScript
import type { LaxPartial } from "@samual/lib";
import type { BinmatArgs } from "./generateArgs";
import type { State } from "./shared";
import { Role } from "./shared";
export type SimulateGameOptions = {
/** How many milliseconds the brain is allowed @default 5000 */ timeLimit: number;
/** @default "defender" */ defenderUserName: string;
/** @default "attacker" */ attackerUserName: string;
/** Pass instead of throwing when brain acts incorrectly (too slow, making move twice, etc) @default false */
noThrow: boolean;
/** Callback that is called after every move */ onMove: (state: State, binlog: string[]) => void;
/** Initial state of the game */ state: State;
/** Intial state of binlog from defender's last turn (should be even numbered turn) @default [] */
defenderBinlog: string[];
/** Intial state of binlog from attacker's last turn (should be odd numbered turn) @default [] */
attackerBinlog: string[];
};
export type CLIContext = {
/** The name of the user who is calling the script (i.e. n00b) */ caller: string;
/** The name of this script */ this_script: string;
/** The number of columns in the caller’s terminal, if reported by the client */ cols: number;
/** The number of rows in the caller’s terminal, if reported by the client */ rows: number;
/** The name of the script that directly called this script, or null if called on the command line or as a
* scriptor */
calling_script: null;
};
export type TransformScript = (args: {
op: string;
}) => {
ok: boolean;
};
export type BrainScript = (context: CLIContext, args: BinmatArgs, xform: TransformScript) => void;
/**
* @param defenderBrain defender brain script but with extra `xform` parameter to replace `#fs.binmat.x()` subscript
* @param attackerBrain attacker brain script but with extra `xform` parameter to replace `#fs.binmat.x()` subscript
* @param options {@link SimulateGameOptions details}
* @returns who won
*/
export declare function simulateGame(defenderBrain: BrainScript, attackerBrain: BrainScript, { timeLimit, defenderUserName, attackerUserName, noThrow, onMove, state, defenderBinlog, attackerBinlog }?: LaxPartial<SimulateGameOptions>): Role;