node-sc2 / core Goto Github PK
View Code? Open in Web Editor NEWA lightweight node.js framework to facilitate writing agents (or 'bots') for Starcraft II in JavaScript.
License: MIT License
A lightweight node.js framework to facilitate writing agents (or 'bots') for Starcraft II in JavaScript.
License: MIT License
// main.js
import { createAgent, createEngine, createPlayer } from '@node-sc2/core';
import { Difficulty, Race } from '@node-sc2/core/constants/enums';
const bot = createAgent({
async onGameStart({ resources }) {
const { units, actions, map } = resources.get();
map.getEnemyMain(); //throws error
}
});
const engine = createEngine();
engine.connect().then(() => {
return engine.runGame('RoyalBloodAIE', [
createPlayer({ race: Race.RANDOM }, bot),
createPlayer({ race: Race.RANDOM, difficulty: Difficulty.MEDIUM }),
]);
});
error looks like this:
TypeError: Cannot read properties of undefined (reading 'NaN')
at Grid.getNodeAt (B:\projects\monorepo\typescript\sc2bot\node_modules\pathfinding\src\core\Grid.js:84:25)
at AStarFinder.findPath (B:\projects\monorepo\typescript\sc2bot\node_modules\pathfinding\src\finders\AStarFinder.js:58:26)
at Object.path (B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\resources\map.js:401:35)
at B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\systems\map.js:325:39
at Array.map (<anonymous>)
at calculateExpansions (B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\systems\map.js:320:14)
at Object.onGameStart (B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\systems\map.js:419:9)
at B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\systems\create-system.js:107:65
at Array.map (<anonymous>)
at MapSystemWrapper (B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\systems\create-system.js:83:32)
at B:\projects\monorepo\typescript\sc2bot\node_modules\@node-sc2\core\engine\create-engine.js:325:62
at tryCatcher (B:\projects\monorepo\typescript\sc2bot\node_modules\bluebird\js\release\util.js:16:23)
at Object.gotValue (B:\projects\monorepo\typescript\sc2bot\node_modules\bluebird\js\release\reduce.js:166:18)
at Object.gotAccum (B:\projects\monorepo\typescript\sc2bot\node_modules\bluebird\js\release\reduce.js:155:25)
at Object.tryCatcher (B:\projects\monorepo\typescript\sc2bot\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (B:\projects\monorepo\typescript\sc2bot\node_modules\bluebird\js\release\promise.js:547:31)
Map is not decomposable! If this is a 1v1 ladder map, please submit a bug report
I'm just trying out the basic worker rush.
It opens the SC2 app (Version 5.0.2 (81433)) on my MacBook running Catalina (10.15.6) but unfortunately SC2 just renders a black window. SC2 works when I open it normally to play.
See:
What am I missing? I've read all the docs. Thanks!
[jyan@jyan-mbp sc2]$ cat main.js
const { createAgent, createEngine, createPlayer } = require('@node-sc2/core');
const { Difficulty, Race } = require('@node-sc2/core/constants/enums');
const bot = createAgent({
async onGameStart({ resources }) {
const { units, actions, map } = resources.get();
const workers = units.getWorkers();
return actions.attackMove(workers, map.getEnemyMain().townhallPosition);
}
});
const engine = createEngine();
engine.connect().then(() => {
return engine.runGame('Blueshift LE', [
createPlayer({ race: Race.RANDOM }, bot),
createPlayer({ race: Race.RANDOM, difficulty: Difficulty.MEDIUM }),
]);
});
[jyan@jyan-mbp sc2]$ node -v
v14.8.0
Hi, thanks for the awesome project!
Is this supposed to work with Wine on Ubuntu assuming one has a working installation of SC2 that runs fine otherwise.
I know the protobuf API is Windows+Mac only but technically with Wine you are running the Windows version so I thought it would be fine.
Currently the only way to morph an orbital command is to:
const { MORPH_ORBITALCOMMAND } = require('@node-sc2/core/constants/ability')
const { ability, build } = taskFunctions;
const test = createSystem({
name: 'Test',
type: 'build',
buildOrder: [
[13, build(SUPPLYDEPOT)],
[13, build(BARRACKS)],
[16, ability(MORPH_ORBITALCOMMAND)],
],
Probably it would be better to support the following:
const { ORBITALRELAY } = require('@node-sc2/core/constants/upgrade')
const { ability, build } = taskFunctions;
const test = createSystem({
name: 'Test',
type: 'build',
buildOrder: [
[13, build(SUPPLYDEPOT)],
[13, build(BARRACKS)],
[16, upgrade(ORBITALRELAY)],
],
Not stonks, stinks
Currently unit.inject
function without arguments do nothing, and the problem placed in egine/create-units.js
in inject
function, instead of this
const [idleHatch] = units.getById(UnitType.HATCH).filter(u => u.isIdle());
should be
const [idleHatch] = units.getByType(TownhallRace[Race.ZERG]).filter(u => u.isIdle());
But this solution causes another effect that any queen on run blank inject function will go to the main to inject it, though to inject nearest Hatchery has more sense.
something like this
const [idleHatch] = units.getClosest(this.pos, units.getByType(TownhallRace[Race.ZERG]), 1);
Either needs to be upgraded to a version of it with a fix or swapped out with something that works:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.