Skip to content

AiView beta ​

Class of @v12-engine/engine/ai

ts
export declare class AiView

A computer player's reading of its picture of the game (Brain.view): the snapshot of its seat, indexed once a think and queried as sets (UnitSet): mine, allies, enemies (what is in sight now; enemies.known() adds the structures remembered), hostile (enemies and creeps), creeps, neutral, resources, all; the player's own state (me); what unit types are for (roles, typesOf); where things are (near, home, bases, mines, camps, regions); how strong things are (strength: odds, matchup, counterFor) and where the strength is (threat, the map made when first asked); what the game tells this player (report, component, events.game); and the map's facts (canPlace, findPath, cellAt). Made from the snapshot as the think begins; a set of it is good for the think

Members ​

constructor ​

ts
constructor(
    snapshot: Snapshot, 
    session: GameSession, options?: ViewOptions);

Constructs a new instance of the AiView class

all ​

ts
readonly all: UnitSet;

Every entity the player knows of, in the snapshot's order: in sight, and the structures remembered

allies ​

ts
readonly allies: UnitSet;

The allies' units and buildings (one's own left out)

bases ​

ts
bases(): readonly Base[];

The player's bases: its buildings clustered around what takes deposits (halls, what stands on a mine), each to the nearest of those within reach; and where there is nothing that takes deposits (a game with no economy), around any building, the clusters made as the buildings come. Home first

byId ​

ts
byId(id: number | undefined): EntityState | undefined;

An entity the player knows of, by id: none for one gone, or never seen

camps ​

ts
camps(): readonly CampInfo[];

The creep camps of the map: where they are is part of the map, which everyone knows

canPlace ​

ts
canPlace(unitType: string, point: Vec2): boolean;

Whether the player could build this here, as far as it can tell: no on ground it has not explored

cellAt ​

ts
cellAt(layer: string, x: number, z: number): number;

The value of one of the game's layers of cells at a point (Terrain.cells, CellLayerDef): 0 where it is not painted

cells ​

ts
cells(layer: string): Readonly<Uint8Array> | undefined;

One of the game's layers of cells whole, row by row (Terrain.cells), to read and not to change: none where nothing is painted

component ​

ts
component<T, S = T>(entity: EntityState, component: Component<T, S>): S | undefined;

What the game replicates to this player of an entity (Component.replicate), with the component's type

creeps ​

ts
readonly creeps: UnitSet;

The creeps in sight: hostile to everyone, no one's rival

def ​

ts
def(entity: EntityState): UnitTypeDef;

The definition of an entity's type

enemies ​

ts
readonly enemies: UnitSet;

The enemies' units and buildings in sight now, creeps left out. enemies.known() adds their structures seen before

events ​

ts
readonly events: ViewEvents;

What happened in the tick of the picture, by kind

findPath ​

ts
findPath(from: Vec2, to: Vec2, flying?: boolean): Vec2[] | null;

The route a unit would take, over the ground the player knows

has ​

ts
has(requires: readonly string[] | undefined): boolean;

Whether the player has the finished buildings something asks for (UnitTypeDef.requires)

hasRole ​

ts
hasRole(entity: EntityState | string, role: AiRole): boolean;

Whether an entity's type, or a type by id, has a role

home ​

ts
home(): EntityState | undefined;

The player's home: its first hall, or its first building where it has no hall. None with no buildings

hostile ​

ts
readonly hostile: UnitSet;

Whatever attacks the player and is in sight: enemies and creeps

inRegion ​

ts
inRegion(name: string, point: Vec2): boolean;

Whether a point is in a named region of the map. False for a region the map does not have

inspect ​

ts
inspect(): Record<string, unknown>;

What the view found of the roles, for the debug tools: each role and its types among the player's own

isCreep ​

ts
isCreep(entity: EntityState): boolean;

Whether an entity is a creep's

isFriendly ​

ts
isFriendly(entity: EntityState): boolean;

Whether an entity is the player's own or an ally's

isHostile ​

ts
isHostile(entity: EntityState): boolean;

Whether an entity is a rival's, or a creep

items ​

ts
get items(): readonly GroundItemState[];

Items lying on the ground where the player sees it

lanes ​

ts
lanes(): readonly Lane[];

The lanes of the map (GameSession.lanes: its paths with a spawner of each side at their ends), as the map shows them: none where the session does not say, or the map has none. Read once a think

me ​

ts
readonly me: Me;

The player a brain plays: resources, supply, tech, heroes, objectives. Mutable for the think

mine ​

ts
readonly mine: UnitSet;

The player's own units and buildings

mines ​

ts
mines(): readonly MineInfo[];

Where the game's money is mined, as the map shows them, under the fog too (GameSession.mines): what a computer player looks to for another hall. Where the session does not say, the deposits of the money it knows of

named ​

ts
named(name: string): EntityState | undefined;

An entity the map or the rules named (world.named), where the player knows of it: "the gate", "the hero"

neutral ​

ts
readonly neutral: UnitSet;

What is nobody's and not a resource, in sight: a shop, a neutral building. neutral.known() adds those seen before

player ​

ts
player(id: PlayerId): PlayerState | undefined;

A player, by id

playerId ​

ts
readonly playerId: PlayerId;

The player it reads for

players ​

ts
readonly players: readonly PlayerState[];

Every player, as the snapshot has them

reachable ​

ts
readonly reachable: ReadonlySet<string>;

The unit types the player has or can come to make: what the roles are narrowed to for it (typesOf)

region ​

ts
region(name: string): MapRegion | undefined;

A region of the map, by name

regions ​

ts
get regions(): readonly MapRegion[];

The regions of the map, by name, as the map was made

registry ​

ts
readonly registry: Registry;

The game's definitions, as the seat has them

relation ​

ts
relation(entity: EntityState): PlayerState['relation'] | undefined;

What an entity's owner is to the player: self, ally, enemy, neutral. Creeps are enemy

report ​

ts
get report(): Record<string, unknown> | undefined;

What the game tells the player about itself (Rules.report): a wave number, a score

resources ​

ts
readonly resources: UnitSet;

The deposits the player knows of: mines and trees in sight, and those seen before (ofResource(kind) for one kind)

resourcesNear ​

ts
resourcesNear(base: Base | Vec2, radius?: number): UnitSet;

The deposits near a base, in sight or remembered: what it gathers from

roleOf ​

ts
roleOf(entity: EntityState | string): readonly AiRole[];

The roles of an entity's type, or of a type by id

roles ​

ts
readonly roles: Roles;

What unit types are for, by the game's definitions: found once, kept while they stand

session ​

ts
readonly session: GameSession;

The seat, for the map's facts: the ground, the regions, the mines, the camps

snapshot ​

ts
readonly snapshot: Snapshot;

The picture it reads: the snapshot of the seat, plain data, the only input a brain has

strength ​

ts
readonly strength: Strength;

How strong things are: a unit, a group, one force against another (odds), what answers what (counterFor). The kit's formula unless the brain was given one; what a type's numbers come to is kept between thinks

threat ​

ts
get threat(): ThreatMap;

Where the strength is: an influence map over the picture, the friendly and the enemy strength that reaches each cell of a coarse grid, by layer (threat.at(point), around, hot). Made when first asked, once a think

tick ​

ts
get tick(): number;

The tick of the picture

time ​

ts
get time(): number;

Seconds into the game, as of the picture

typesOf ​

ts
typesOf(role: AiRole): readonly UnitTypeDef[];

The unit types with a role that are the player's own: those it has or can come to make (reachable), in the game's order, so that the first of a kind is the one meant first. A game of two races gives each player its own