Changes between Initial Version and Version 1 of AIEngineAPI


Ignore:
Timestamp:
Mar 9, 2011, 11:28:25 PM (13 years ago)
Author:
Philip Taylor
Comment:

initial API description

Legend:

Unmodified
Added
Removed
Modified
  • AIEngineAPI

    v1 v1  
     1AI scripts receive data from the engine about the current simulation state, once per simulation turn. This is a fairly low-level mechanism - it is expected that AI scripts will use a wrapper to provide more convenient access to the data. Currently this wrapper is implemented in `common-ai/base.js`.
     2
     3The AI's `HandleMessage` method is called with one argument:
     4
     5{{{
     6state = {
     7  entities: ...,
     8  events: ...,
     9  players: [...],
     10  timeElapsed: ..., // seconds since the start of the match
     11  map: ...,
     12  passabilityClasses: ...
     13};
     14}}}
     15
     16== `entities` ==
     17
     18TODO
     19
     20== `events` ==
     21
     22TODO
     23
     24== `map` and `passabilityClasses` ==
     25
     26{{{
     27state.map = {
     28  width: 256,
     29  height: 256,
     30  data: [ ... ] // Uint16Array with width*height entries
     31};
     32}}}
     33
     34{{{
     35state.passabilityClasses = {
     36  "pathfinderObstruction": 1,
     37  "foundationObstruction": 2,
     38  "building-land": ..., // these are all the PassabilityClasses defined in simulation/data/pathfinder.xml
     39  ...
     40};
     41}}}
     42
     43`state.map.data` encodes all the passability data of each terrain tile. `state.passabilityClasses` gives bitmasks that define how to interpret `state.map.data`. For example:
     44
     45{{{
     46// Get the bitmask for tiles that will obstruct foundations (i.e. you can't place any buildings there)
     47var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction");
     48
     49for (var i = 0; i < map.data.length; ++i)
     50    if (map.data[i] & obstructionMask)
     51        ; // tile i is an unbuildable location
     52
     53}}}
     54
     55Since these are bitmasks, you can 'or' them together:
     56
     57{{{
     58var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction");
     59
     60// Add in the bitmask for tiles that are obstructed for the "building-land" passability class
     61// (i.e. tiles that are underwater or too steep, based on the definition in pathfinder.xml)
     62obstructionMask |= gameState.getPassabilityClassMask("building-land");
     63
     64for (var i = 0; i < map.data.length; ++i)
     65    if (map.data[i] & obstructionMask)
     66        ; // tile i is an unbuildable location for land-based buildings
     67}}}