Help with creating an AI using JS
Help with creating an AI using JS
I'm interested in creating an AI using JavaScript so I started poking around the Semperfi JS AI.
Using the master version of semperfi.js (ie. what you get when you donwload latest wz master) in a single player skirmish, the AI doesn't seem to do anything. Is there a version of semperfi.js that will build something, or is the ability to use JS AIs unavailable in the current master?
Using the master version of semperfi.js (ie. what you get when you donwload latest wz master) in a single player skirmish, the AI doesn't seem to do anything. Is there a version of semperfi.js that will build something, or is the ability to use JS AIs unavailable in the current master?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
Based on what i've seen Semperfi-JS doesn't do much yet, even though it builds a few oils and power gens. On the other hand, i'm already trying to play with it too (:
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
Right. It does not do much yet. In particular, it does not yet build up its base. If you let it start with buildings, or give it some, it will use them to build an army and attack you sometimes.
Re: Help with creating an AI using JS
Anyhow, i suppose in this topic people help with creating an AI using JS?
I try to code:
I get the following error:

I try to code:
Code: Select all
const tankBodies = [
"Body7ABT", // retribution
"Body8MBT", // scorpion
"Body5REC", // cobra
"Body1REC", // viper
];
const tankPropulsions = [
"tracked01", // tracks
"HalfTrack", // half-track
"wheeled01", // wheels
];
const mgWeapons = [
"MG5TWINROTARY",
"MG4ROTARYMk1",
"MG3Mk1",
"MG2Mk1",
"MG1Mk1",
];
/* LOTS OF STUFF IN BETWEEN */
buildDroid(struct, "Some Tank", tankBodies, tankPropulsions, "", DROID_CONSTRUCT, mgWeapons);Code: Select all
error |10:56:03: [get_first_available_component] No such component: MG5TWINROTARY
error |10:56:03: [get_first_available_component] No such component: MG4ROTARYMk1
error |10:56:03: [get_first_available_component] No such component: MG3Mk1
error |10:56:03: [get_first_available_component] No such component: MG2Mk1
error |10:56:03: [get_first_available_component] No such component: MG1Mk1
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
Hmm, since it works fine with Semperfi JS, i'd better post the complete code ... of an AI that builds a base but doesn't attack yet ^^
- Attachments
-
- nullbot.js
- (8.26 KiB) Downloaded 248 times
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
That nullbot is really useful - thanks! If I wanted to turn that in to a mod, what would I do? (mainly because I'm having problems editing base.wz so if I can experiment in a mod that would make life easier)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
You need to add nullbot.ai file with obvious contentsput the two files into clean /multiplay/skirmish/ folder and zip multiplay folder (not its contents, but the folder itself), and the multiplayer mod is ready.
Code: Select all
[AI]
name = "NullBot v0.000001 pre-alpha"
js = nullbot.js
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
Meet the idiotDROID_CONSTRUCT
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
w00t, it works - here's sample mod .wz file (attached) for anyone else wanting to play with nullbot.
It seems like pickStructLocation() is having problems (or it's return value is misinterpreted?) as after building a research lab the next thing on the list is a factory, however the location for the factory seems to be overlapping (or directly adjacent to) the existing research lab position = doesn't get built. I've not been fast enough to grab a screenshot, but mocked this up to illustrate what is happening:

Are the x,y returned by pickStructLocation() the center, top-left or top-right of a building? And when ordering a droid to create a building, are the x,y using the same origin point? It would be useful to have that clarified in the JS API docu.
It seems like pickStructLocation() is having problems (or it's return value is misinterpreted?) as after building a research lab the next thing on the list is a factory, however the location for the factory seems to be overlapping (or directly adjacent to) the existing research lab position = doesn't get built. I've not been fast enough to grab a screenshot, but mocked this up to illustrate what is happening:

Are the x,y returned by pickStructLocation() the center, top-left or top-right of a building? And when ordering a droid to create a building, are the x,y using the same origin point? It would be useful to have that clarified in the JS API docu.
- Attachments
-
- nullbot.wz
- example nullbot mod
- (5.59 KiB) Downloaded 236 times
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
What was the issue with DROID_CONSTRUCT? (I'm totally new to WZ scripting so still lots to learn)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
I don't have a build environment set-up on my mac - is there a JS workaround I can implement for now to overcome that issue?NoQ wrote:fixed in latest git.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
I used to add +1 to both loc.x and loc.y and it seemed to do the job, but it doesn't work for cyborg factories.
Producing tanks failed because i put DROID_CONSTRUCT instead of DROID_WEAPON (By the way, can't this value be auto-detected, based on turrets?)aubergine wrote:What was the issue with DROID_CONSTRUCT? (I'm totally new to WZ scripting so still lots to learn)
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
Re: Help with creating an AI using JS
Just dabbling with some utility functions before diving in to more complex stuff - is this of any use:
Code: Select all
// find the closest item in featureList to a given x,y point
// optionally limited by a min/max range and droid's ability to get there
function findNearestFeature(featureList,x,y,minRange,maxRange,droid) {
// param defaults (leave param empty or null to use default)
minRange = minRange || 0;
maxRange = maxRange || Number.MAX_VALUE;
var nearestFeature = {
dist: maxRange,
feature: null
};
var feature, range;
var i = featureList.length;
// find the nearest feature within range limits
while (-1<--i) {
feature = featureList[i];
if (!!droid && !droidCanReach(droid,feature.x,feature.y)) continue;
dist = distBetweenTwoPoints(x,y,feature.x,feature.y);
if (dist<nearestFeature.dist && dist>=minRange) {
nearestFeature = {
dist: dist,
feature: feature;
};
}
}
return nearestFeature;
}
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: Help with creating an AI using JS
How do I find out if a given droid object is a VTOL or not? I know it will be defined in the .droidType property, but can't find a list of possible values for that property :s
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO


