Brain beta
Class of @v12-engine/engine/ai
export declare class Brain implements ComputerPlayerA computer player made of modules (defineBrain), seated at a world (world.computers.seat). What a module is handed as it thinks (ai): the picture of the game (snapshot), the seat it plays through (session), its options, its numbers (rng), its log, and send for its commands. A brain is a ComputerPlayer: think, and save and restore for what it remembers
Members
constructor
constructor(
def: BrainDef,
session: GameSession,
options: AiOptions, context?: BrainContext);Constructs a new instance of the Brain class
area
area<T extends AiArea>(key: AreaKey<T>): T;An area of its (AiArea): its economy (ai.area(Economy)), its scouting, a game's own (defineArea), made the first time it is asked for, with what a save remembered of it. What its modules share beyond what every module does (knowledge, goals, plans, squads, purse)
areas
areas(): readonly AiArea[];Its areas, in the order they were made: what its memory and its report are made of
budget
readonly budget: ThinkBudget;How much of a think one tick may do (ThinkBudget): so many modules, so many units looked at as the modules say (budget.spent(n)), the think going on at the next tick from where it stopped (budget.later()). Counted in work, never in milliseconds, so that the game is the same on every machine. What the seat was given (BrainContext.budget)
busy
get busy(): boolean;Whether a think is under way across ticks (budget): the seat asks it to think on at the next tick
cache
cache<T>(key: string, compute: () => T): T;What was worked out once for this think, by key: a consideration asked by several goals, a set a few modules read (ai.cache('intruders', () => ...)). Thrown away as the next think takes its picture
decide
decide(line: string, about?: {
kind?: string;
goal?: string;
}): void;Writes down a decision (decisions), with the reason that weighed most, in words: what the report's log and the debug panel show, and the world's log at its debug level. kind says what it is about (army, build)
decisions
readonly decisions: Decisions;What it decided, the last fifty (decide): the goals picked and stopped, with the reason that weighed most, and what its modules write down. Kept in a save
def
readonly def: BrainDef;What it was made from
dispose
dispose(): void;Lets its modules go of what they hold outside the brain
explain
explain(goal: string): string | undefined;A goal's row of the report as a sentence: what it scored and why, whether it runs and with what, or what kept it from running. Nothing for a goal the brain does not have
goals
readonly goals: Goals;What it could do (Goals): its goals scored each think from their considerations, the best given what they claim of its units and money, each run while it holds its claim. Its definition's goals and the seat's; a module adds its own (ai.goals.add). Picked by the goals() module, or by one of the brain's own in its place
held
held: number;Commands it would have sent this think past what its profile lets a think send (commandsPerThink): not sent
inspect
inspect(): AiReport;What it is thinking, for the debug tools: its report (report)
knowledge
readonly knowledge: Knowledge;What it remembers of the enemy, the map and itself, with when (Knowledge): their bases and army as last seen, when each place was last looked at, its own losses and income. Brought up to date as each think begins, after the view; kept in a save
knowledgeTiming
knowledgeTiming: number | undefined;Milliseconds bringing the knowledge up to date took, averaged: while the world profiles
log
readonly log: Logger;Where it says what it does: the world's log, with the player it plays and its brain on each line
made
made<T extends AiArea>(id: string): T | undefined;An area made already, by id: none where no module has asked for it. For a part of the kit that reads another's area where there is one and needs nothing of it where there is none (whether a squad's fights are the micro's)
me
get me(): PlayerState | undefined;The player it plays, as its picture shows them: resources, supply, tech (own). Nothing once out of the game. view.me is the same, never nothing
module
module<M extends AiModule>(key: ModuleKey<M>): M | undefined;A module of its, by key with its shape (MELEE_ARMY, moduleKey), or by id
module
module(id: string): AiModule | undefined;Finds one of the brain's modules by id, or nothing when it has none of that id
moduleLongest
readonly moduleLongest: Record<string, number>;The most milliseconds each module took in one pass, by id: always, as the warning (ThinkBudgetOptions.warnAfterMs) is
modules
readonly modules: readonly AiModule[];Its modules, in the order they run
moduleTiming
readonly moduleTiming: Record<string, number>;Milliseconds each module took, averaged over thinks, by id: while the world profiles (BrainContext.profiling)
options
readonly options: AiOptions;What it was seated with: a brain's own options read theirs from it
paused
paused: boolean;Whether it sits still (world.computers.pause). Kept in a save
plans
readonly plans: Plans;Its plans (Plans): the build plan (plans.build: wants, the steps to each through the tech tree, spots, builders, saving up), the production plan (plans.production: the composition, counters, supply ahead, research), the game's build order over both, and plans.want to add to them. Run by the build() and production() modules, or by one of the brain's own
playerId
get playerId(): PlayerId;The player it plays
profile
readonly profile: AiProfile;How it plays (AiProfile), resolved (resolveProfile): how well it plays (the engine's, the game's, the difficulty's, the personality's, the seat's every and budget) and its settings, the brain's, the game's, the difficulty's, the personality's, the map's and the seat's each over the one before (a flag's function left out)
purse
readonly purse: Purse;What it has to spend this think (Purse): its resources less what builders on their way will pay and what is held (a goal's money claim, a want saving up), rebuilt from the picture as each think begins. The one ledger: everything that spends, spends through it. view.me.purse is what is free
registry
get registry(): Registry;The game's definitions, as the seat has them
report
report(): AiReport;What it is thinking, as plain data (AiReport): its goals with their considerations, what it knows, its roles, its economy, what it was told, what it decided, and each module's section. Made when asked: nothing in a think waits for it. What inspect gives, and the debug panel's AI tab draws
restore
restore(memory: BrainMemory): void;Takes back what save gave. A module's memory of another version goes through its migrate; without one, or with nothing in the save for it, the module starts afresh, and the log says so once. Memory of a module the brain no longer has is dropped, said too
rng
readonly rng: Rng;Its own numbers, for whatever it leaves to chance (which base to scout first): seeded from the world's and the player's, kept in its memory, so that the same game plays the same way. Never Math.random
save
save(): BrainMemory;What it remembers, for a save: its numbers, each module's memory with its version, what it was told. A think under way (budget) is kept as it began, with how far it got and its picture (BrainMemory.thinking): the game loaded from the save runs it on to its end as the saved game does
send
send(command: PlayerCommand): number;Sends a command, as the player would: counted (sent), carried out at the next tick. Returns the command's number; -1 for one past what its profile lets a think send (commandsPerThink, a person's hands), which is not sent
sent
sent: number;Commands it sent this think
sentTo
sentTo(unit: number): {
key: string;
tick: number;
} | undefined;The last order it sent a unit lately (within a few seconds), as a key (orderKey: its kind, its target, its place to the cell) with the tick: what keeps a module from telling a unit again what it is already doing, when the unit changed hands (a squad of another goal) since. None for a unit told nothing lately
session
readonly session: GameSession;The seat it plays through: the snapshots it sees, the commands it sends
settings
get settings(): AiSettings;What its areas play by this think (AiSettings): its settings' layers worked out, a flag that is a function of the brain asked now. Each area reads its own (ai.settings.economy), over what its module was made with
snapshot
snapshot: Snapshot;What it sees, as of its last think: the snapshot of its seat, plain data, and the only input a brain has. Taken once a think: every module of the think reads the same picture
snapshotTiming
snapshotTiming: number | undefined;Milliseconds taking the picture of the game took (the seat's snapshot()), averaged: while the world profiles
squads
readonly squads: Squads;Its squads (Squads): named groups of its units, each with a task (attack there, defend here, gather and go), made by its goals, rules and modules out of what they hold, and watched by the squads() module think after think: orders sent once and watched, regroups, retreats on the odds, reinforcements. Kept in a save
stats
readonly stats: AiStats;What its play adds up to since it was seated (AiStats): commands sent, held and refused, seconds its fighters stood idle, orders sent again for the same thing, seconds its building waited on money. For the report and simulate, never for a decision; not kept in a save
strength
get strength(): Strength;How strong things are (Strength): a unit, a group, one force against another (odds), what answers what (counterFor). The view's: the kit's formula unless the brain or the seat was given one
takeTold
takeTold(word: string, count?: number): Told[];Takes the words of one kind out of what it was told, oldest first, as many as count (all when left out): they are heard no more
teamBoard
readonly teamBoard: BrainContext['team'];The board of its team, shared by its team's computers: what its seat was given (BrainContext.team), for its team play
tell
tell(word: string, data: unknown, tick: number): void;Takes in a word from the game: a module takes it with takeTold. What the seat calls for world.computers.tell
think
think(): void;One think, or one tick of it. A new picture of the game is taken, and the modules run over it in their order, as many a tick as the budget allows (budget): so many modules, so many units looked at as they say. A module's error is the seat's to catch, as a system's is
thinks
thinks: number;How many times it has thought
thinkTicks
thinkTicks: number;Ticks the last think took, all its passes: 1 unless its budget sliced it
threat
get threat(): ThreatMap;Where the strength is (ThreatMap): the friendly and the enemy strength that reaches each cell of a coarse grid over the map, by layer. Made from the think's picture when first asked; threat.at(undefined) is all zeros
tick
get tick(): number;The tick of its picture of the game
time
get time(): number;Seconds into the game, as of its picture of it
told
told(word?: string): readonly Told[];The words the game told it and no module has taken yet (world.computers.tell), oldest first; those of one word where given. Reading them takes nothing: takeTold does, as a told rule (when.told) does when it fires
view
view: AiView;Its reading of the picture (AiView): the snapshot indexed once a think and asked as sets (view.mine.idle(), view.enemies.near(home, 20)), with what unit types are for (view.roles) and the map's facts. What a module reads the game through
viewTiming
viewTiming: number | undefined;Milliseconds reading the picture into the view took (AiView, the ledger with it), averaged: while the world profiles
watch
watch(watcher: BrainWatcher): () => void;Follows its play from outside (BrainWatcher): the commands it sends, its thinks as each ends, what it decides. Returns the way to stop. What watchComputer and recordDecisions of @v12-engine/engine/testing stand on