Native node addon which wraps around s2client-api.
npm install matortheeternal/s2js --save
See the test bot for an example of a bot that trains SCVs and assigns them to harvest minerals.
- Clone this repository.
- Run
node-gyp configure
. - Run
npm run build
. - Run
npm run test
.
- Create a fleshed-out bot using the API and expand the API functionality to match its needs.
- Build a system to run multiple JS bots against each other.
- Build a system to run a JS bot against a C++ bot.
Every enumeration in the API has both an ID to name map and a name to ID map. The *_IDS
object maps from names to IDs, where the *
object maps from IDs to names.
UNIT_TYPES
,UNIT_TYPE_IDS
UNIT_CLASSES
,UNIT_CLASS_IDS
ABILITIES
,ABILITY_IDS
BUFFS
,BUFF_IDS
RACES
,RACE_IDS
UPGRADES
,UPGRADE_IDS
ALLIANCES
,ALLIANCE_IDS
DISPLAY_TYPES
,DISPLAY_TYPE_IDS
CLOAK_STATES
,CLOAK_STATE_IDS
examples:
UNIT_TYPE_IDS.TERRAN_SCV
- The unique ID for Terran SCVs.UNIT_TYPES[45]
- The name of the unit with ID 45.ABILITY_IDS.TRAIN_MARINE
- The unique ID for the train marine ability.RACE_IDS.Terran
- The unique ID for the Terran race.
Starts a new StarCraft 2 game. Throws an error if the game fails to start.
arguments:
options
- Required options to start the game.
participants
- Array of participants in the game.type
- String for the type of participant: 'bot' or 'computer'.race
- RACE_ID to use for the participant. E.g.RACE_IDS.Zerg
.
map
- Path to the map file to use. Using an absolute path is recommended.
returns:
Nothing.
Runs the game loop.
returns:
False if the game has ended, true otherwise.
Gets game stats for the bot player.
returns: An object with the following properties:
minerals
- mineralsvespene
- vespene gasfood_cap
- supply capfood_used
- supply usedfood_army
- supply used by army unitsfood_workers
- supply used by worker unitsidle_workers
- number of idle workersarmy_count
- number of army units
Gets an array of unique IDs for all the units the bot player has vision of.
returns:
An array of strings, where each string is a hexadecimal ID corresponding to the unit's tag
.
Gets the classes associated with a unit.
arguments:
unitId
- Unit ID as returned from GetUnits()
returns:
An array of numbers corresponding to UNIT_CLASS_IDS
.
Gets a variety of information on a unit.
arguments:
unitId
- Unit ID as returned from GetUnits()
returns:
An object with the following properties:
health
- The unit's current health.health_max
- The unit's max health.type
- The unit'sUNIT_TYPE_ID
.pos
- The unit's position.x
- The unit's X position.y
- The unit's Y position.
alliance
- The unit'sALLIANCE_ID
.shield
- The unit's current shield. Only present if the unit hasshield_max
> 0.shield_max
- The unit's max shield. Only present if the unit hasshield_max
> 0.energy
- The unit's current energy. Only present if the unit hasenergy_max
> 0.energy_max
- The unit's max energy. Only present if the unit hasenergy_max
> 0.display
- The unit'sDISPLAY_TYPE_ID
. Only present for enemies.cloak
- The unit'sCLOAK_TYPE_ID
. Only present for enemies.
Gets information on a resource unit.
arguments:
unitId
- Unit ID as returned from GetUnits()
returns:
An object with the following properties:
pos
- The unit's position.x
- The unit's X position.y
- The unit's Y position.
contents
- The amount of vespene or minerals available to be harvested from the unit.
Commands a unit to use move or use an ability.
arguments:
unitId
- Unit ID for the unit to command as returned from GetUnits()
abilityId
- The id of the ability to use.
target
- Either a position object with x
and y
properties OR a target unit ID.
- Clone s2client-api and build it on your machine.
- Create an environmental variable
S2API_ROOT
set to the directory where you cloneds2client-api
. - Install NodeJS 8.x LTS. Verify by running the following commands from the command line:
npm -v
andnode -v
. - Install Python 2.7.x.
- Install windows-build-tools from the command line via:
npm install --global windows-build-tools
- Create a folder/local repository for you bot's code.
- Run the
npm init
from the command line in your bot's folder, then follow the prompts and enter options as desired. - Run
npm install matortheeternal/s2js --save
from the command line. - Create an
index.js
file in your bot's folder and create asrc
folder for additional files. - Create a
maps
folder and copy theBelShirVestigeLE.SC2Map
file into the folder. (you can find it in thetest
folder in this repository)
Put the following code into your index.js
file:
let s2js = require('s2js');
s2js.StartGame({
participants: [{
type: 'bot',
race: s2js.RACE_IDS.Terran
}, {
type: 'computer',
race: s2js.RACE_IDS.Zerg
}],
map: `${__dirname}\\maps\\BelShirVestigeLE.SC2Map`
});
while (s2js.Update()) {
// your bot code here
}
Use the library to get units and command them to do things after each Update()
function call. If you have any questions or have functionality you would like to see added you can create an issue or contact me on the Starcraft AI discord.