AiView beta
Class of @v12-engine/engine/ai
export declare class AiViewA 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
constructor(
snapshot: Snapshot,
session: GameSession, options?: ViewOptions);Constructs a new instance of the AiView class
all
readonly all: UnitSet;Every entity the player knows of, in the snapshot's order: in sight, and the structures remembered
allies
readonly allies: UnitSet;The allies' units and buildings (one's own left out)
bases
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
byId(id: number | undefined): EntityState | undefined;An entity the player knows of, by id: none for one gone, or never seen
camps
camps(): readonly CampInfo[];The creep camps of the map: where they are is part of the map, which everyone knows
canPlace
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
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
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
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
readonly creeps: UnitSet;The creeps in sight: hostile to everyone, no one's rival
def
def(entity: EntityState): UnitTypeDef;The definition of an entity's type
enemies
readonly enemies: UnitSet;The enemies' units and buildings in sight now, creeps left out. enemies.known() adds their structures seen before
events
readonly events: ViewEvents;What happened in the tick of the picture, by kind
findPath
findPath(from: Vec2, to: Vec2, flying?: boolean): Vec2[] | null;The route a unit would take, over the ground the player knows
has
has(requires: readonly string[] | undefined): boolean;Whether the player has the finished buildings something asks for (UnitTypeDef.requires)
hasRole
hasRole(entity: EntityState | string, role: AiRole): boolean;Whether an entity's type, or a type by id, has a role
home
home(): EntityState | undefined;The player's home: its first hall, or its first building where it has no hall. None with no buildings
hostile
readonly hostile: UnitSet;Whatever attacks the player and is in sight: enemies and creeps
inRegion
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
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
isCreep(entity: EntityState): boolean;Whether an entity is a creep's
isFriendly
isFriendly(entity: EntityState): boolean;Whether an entity is the player's own or an ally's
isHostile
isHostile(entity: EntityState): boolean;Whether an entity is a rival's, or a creep
items
get items(): readonly GroundItemState[];Items lying on the ground where the player sees it
lanes
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
readonly me: Me;The player a brain plays: resources, supply, tech, heroes, objectives. Mutable for the think
mine
readonly mine: UnitSet;The player's own units and buildings
mines
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
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
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
player(id: PlayerId): PlayerState | undefined;A player, by id
playerId
readonly playerId: PlayerId;The player it reads for
players
readonly players: readonly PlayerState[];Every player, as the snapshot has them
reachable
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
region(name: string): MapRegion | undefined;A region of the map, by name
regions
get regions(): readonly MapRegion[];The regions of the map, by name, as the map was made
registry
readonly registry: Registry;The game's definitions, as the seat has them
relation
relation(entity: EntityState): PlayerState['relation'] | undefined;What an entity's owner is to the player: self, ally, enemy, neutral. Creeps are enemy
report
get report(): Record<string, unknown> | undefined;What the game tells the player about itself (Rules.report): a wave number, a score
resources
readonly resources: UnitSet;The deposits the player knows of: mines and trees in sight, and those seen before (ofResource(kind) for one kind)
resourcesNear
resourcesNear(base: Base | Vec2, radius?: number): UnitSet;The deposits near a base, in sight or remembered: what it gathers from
roleOf
roleOf(entity: EntityState | string): readonly AiRole[];The roles of an entity's type, or of a type by id
roles
readonly roles: Roles;What unit types are for, by the game's definitions: found once, kept while they stand
session
readonly session: GameSession;The seat, for the map's facts: the ground, the regions, the mines, the camps
snapshot
readonly snapshot: Snapshot;The picture it reads: the snapshot of the seat, plain data, the only input a brain has
strength
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
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
get tick(): number;The tick of the picture
time
get time(): number;Seconds into the game, as of the picture
typesOf
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