I want to create a new AI player, how to?
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
I want to create a new AI player, how to?
Hi everyone, I want to try my hand at writing AI for WZ 2100 3.1 and have some questions..
Is it possible to just create a script of some kind to add another AI player to the selectable list (in MP/SK games that is) or will I need to recompile for that? What language can/must I use? Are all commands available to human players also avaliable to AI scripts (ie transports and sending money/units)?
I suppose the easiest way to do that would be to modify the Semper fi code incrementally. My problem with the current AIs is that they more or less depend on rushing and come to a complete halt after an hour or so. I want to add more defenses/artilleries as well as larger attacks. Possibly also strategy focus (that is, pick a strategy and stick with it).
Any tips are welcome!
Is it possible to just create a script of some kind to add another AI player to the selectable list (in MP/SK games that is) or will I need to recompile for that? What language can/must I use? Are all commands available to human players also avaliable to AI scripts (ie transports and sending money/units)?
I suppose the easiest way to do that would be to modify the Semper fi code incrementally. My problem with the current AIs is that they more or less depend on rushing and come to a complete halt after an hour or so. I want to add more defenses/artilleries as well as larger attacks. Possibly also strategy focus (that is, pick a strategy and stick with it).
Any tips are welcome!
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
AIs are the scripts that are stored in multiplay/scripts folder, so they can be added via mods.
For 3.1, there are two languages they can be written in. One is wzscript, a traditional language in which the default ("Nexus") AI (as well as the campaign scenario) is written. The other is JavaScript that has become available only recently. It still lacks some functions, but it is much easier and it is the future the project has chosen (in fact, the campaign is planned to be re-written in JS as well), so it's highly recommended.
Look here (and other topics in the Scripting subforum) for documentation.
You can also have a look at my JS AI, NullBot, as an example. For an easier example, see Semperfi-JS code available in master (but not in 3.1) (it is a very basic AI that doesn't do much yet, but you can take a lot of pieces of code from it).
For 3.1, there are two languages they can be written in. One is wzscript, a traditional language in which the default ("Nexus") AI (as well as the campaign scenario) is written. The other is JavaScript that has become available only recently. It still lacks some functions, but it is much easier and it is the future the project has chosen (in fact, the campaign is planned to be re-written in JS as well), so it's highly recommended.
Look here (and other topics in the Scripting subforum) for documentation.
You can also have a look at my JS AI, NullBot, as an example. For an easier example, see Semperfi-JS code available in master (but not in 3.1) (it is a very basic AI that doesn't do much yet, but you can take a lot of pieces of code from it).
Note: the AIs written in JS should be "non-cheating". Since Nexus is a cheating AI (gets free $$$ all the time on any difficulty higher than minimal, and does some other impossible things), you won't really be able to make it produce more units or something like that.DvDmanDT wrote:I want to add more defenses/artilleries as well as larger attacks.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
aubergine
- Professional

- Posts: 3462
- Joined: 10 Oct 2010, 00:58
Re: I want to create a new AI player, how to?
I've made a little tutorial on the basics of bundling some javascript as an AI mod:
https://warzone.atlassian.net/wiki/disp ... rst+AI+mod
https://warzone.atlassian.net/wiki/disp ... rst+AI+mod
"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
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
I found out about nullbot just minutes after posting this and included it in my map to test it. I really like it, though it appears to be a bit slow (as in resource intentensive). I tried 7 nullbots and got something like 0.5 fps on my Core i7 950 (3.07 GHz) machine with 24GB ram and a GTX580.
Any idea why? Are there any specific parts/functions/algorithms you know cause slowdowns?
Any idea why? Are there any specific parts/functions/algorithms you know cause slowdowns?
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
I'm running 9 nullbots without problems on my 8-year-old P4 3.2Ghz, 2GB ram. I notice some slowdowns, but it's playable.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
Emm, actually, just in case. Could you get the latest master snapshot (or git if you're using it), run it withDvDmanDT wrote:Any idea why? Are there any specific parts/functions/algorithms you know cause slowdowns?
Code: Select all
--debug=scriptMaps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
After some testing, I'm starting to think it's related to scavengers (not yours, the built-in). I reduced the amount of scavenger factories and the lag went down considerably. Perhaps nullbot creates more of a fight for the scavengers than semper fi or nexus. The map I'm creating has a fair amount of scavenger bases.
Is there a limit to how many oils nullbot tries to capture? About 40% of the maps total oil resources were uncaptured at the end of my last game which seemed a bit much.
The map I'm creating is intended to be played by 2 humans agains two teams of 3 ai players each, and is largely focused on siege/defense. nullbot did give us quite a challenge and improved the experience alot, but there might still be room for some map specific specialization/personalities/behavior since it's intended to be played a bit like a multiplayer scenario. Would it be ok if I included a map-specialized version of nullbot with my map?
Is there a limit to how many oils nullbot tries to capture? About 40% of the maps total oil resources were uncaptured at the end of my last game which seemed a bit much.
The map I'm creating is intended to be played by 2 humans agains two teams of 3 ai players each, and is largely focused on siege/defense. nullbot did give us quite a challenge and improved the experience alot, but there might still be room for some map specific specialization/personalities/behavior since it's intended to be played a bit like a multiplayer scenario. Would it be ok if I included a map-specialized version of nullbot with my map?
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
Sure, any time. The AI is public domain (aka CC-0 license). Here is an example of how it is done.Would it be ok if I included a map-specialized version of nullbot with my map?
I've heard some reports of this, but i never could reproduce any. In the hundreds of tests i regularly make, it captures all oil without any problems. Sometimes it has pathfinding issues with oils that are surrounded by cliffs too closely, but it's very rare, and even humans will have to navigate trucks manually in these cases.Is there a limit to how many oils nullbot tries to capture? About 40% of the maps total oil resources were uncaptured at the end of my last game which seemed a bit much.
Hmm, a report will still be interesting, cause i have some scavenger-specific code.After some testing, I'm starting to think it's related to scavengers (not yours, the built-in).
Note: it's easy to build-in custom scavengers in a challenge, and even make scavenger AI control "real" players (so that scavengers were allied with one of the teams).not yours, the built-in
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
I didn't have time to record a full game yet, but I recorded the start of a game and it's huntForOil that takes 60-120ms which is probably the issue. Is that normal? After reducing the amount of scavengers and oil, the lag is less of an issue but still a bit annoying. Much of the oil on this map is guarded by scavenger defenses, would that have any effect on your algorithms?
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
huntForOil is cpu-intensive, because it brute-force-checks for threats (including scavengers) before sending trucks to death, and the complexity of this check is currently count-of-oils times count-of-all-units-on-map. I could probably significantly improve it for master (using enumRange()), but not for 3.1.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
Hmm. There are plenty of unguarded oils, some fairly close to their bases, but they still try to build on the oil that is 3-4 tiles away from my mortar/howitzer lines.. There is a fairly large amount of oil on the map, but none of them are next to a cliff or anything. The bots have 8 or 10 oils in base to start with, so does it just decide it doesn't need any more?
How would I increase the size of the attacks? And what should I modify to make it build more defenses?
How would I increase the size of the attacks? And what should I modify to make it build more defenses?
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
First of all, please get v1.17 as soon as it's out ... should have some important fixes
just show me anything like that at least once and i'll fix it.
upd: just caught something, but it appeared only recently, even though the issue seems to be older.
NoooThe bots have 8 or 10 oils in base to start with, so does it just decide it doesn't need any more?
upd: just caught something, but it appeared only recently, even though the issue seems to be older.
In -tail:How would I increase the size of the attacks?
Code: Select all
var MAX_WARRIORS = 12; // the maximum number of droids in a group
var NUM_WARRIORS = 8; // the number of battle droids to maintain in a single group
var MIN_WARRIORS = 7; // the number of battle droids necessary to engage in combat
const NO_WARRIORS_AT_ALL = 3; // the number of droids that doesn't make a cluster yet
DEFENSIVENESS in personality definition. But it doesn't change too much, because using both defenses and tanks is a bad idea in any real game. There is also a turtle AI if you want only defenses (fill the whole map with defenses: doesn't use tanks or borgs, and DEFENSIVENESS is set to 0 ... not sure what will happen if you allow him to make tanks after all).And what should I modify to make it build more defenses?
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
It's not a bad idea to build tanks and defenses if you have enough cash? Also, does those numbers ever increase? For example, I want to have it try to attack with 7-8 tanks first, but then increase the size of the attacks incrementally..
Currently, it attacks alot and does a fairly good job at it as well, but there's next to no defenses in their bases making it very easy to use a few vtols to wipe them out. I would also like to see more howitzers, ground shakers and archangels built by the bot since that's about the only chance it has to counter my defenses, especially if combined with scout vtols since they appear to function as sensors.
Is there a VTOL only personality by the way? I've seen it attack with large-ish bomb ships but no attack darts (bug-vtol-hvc for example).
Oh and if you want to see it for debugging purposes or whatever, I can make it available somewhere.
Currently, it attacks alot and does a fairly good job at it as well, but there's next to no defenses in their bases making it very easy to use a few vtols to wipe them out. I would also like to see more howitzers, ground shakers and archangels built by the bot since that's about the only chance it has to counter my defenses, especially if combined with scout vtols since they appear to function as sensors.
Is there a VTOL only personality by the way? I've seen it attack with large-ish bomb ships but no attack darts (bug-vtol-hvc for example).
Oh and if you want to see it for debugging purposes or whatever, I can make it available somewhere.
Last edited by DvDmanDT on 16 Apr 2012, 12:03, edited 1 time in total.
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: I want to create a new AI player, how to?
Check out becomeHarder(). I don't really remember what it does ...Also, does those numbers ever increase?
I think it does spend extra cash on defenses, but prefers building extra factories and labs (note: even with 40 oils, you don't usually have extra money for defenses).It's not a bad idea to build tanks and defenses if you have enough cash?
Turtle is pretty much VTOL-only. It just ... builds defenses as well. Gun VTOLs are present, he just prefers bombs when they are actually better. But if bombs are unavailable or i told him to prefer guns to all available bombs, you will see rocket, assault gun and cannon VTOLs.Is there a VTOL only personality by the way? I've seen it attack with large-ish bomb ships but no attack darts (bug-vtol-hvc for example).
Note: there is also some bug with gun VTOLs #3178, so they are broken on the latest master, and work more or less well but still weird on 3.1.
Turtle AI will build much arty and send sensor tanks at you, and also if you set him on HARD (in fact, he should always be on HARD), you will see many howitzer tanks attacking you when available if you turtle too much (howitzer tanks are much stronger in arty wars than howitzer emplacements, but he doesn't use CB turrets correctly yet, prefering to place CB towers instead, but i'm not sure they will work well during siege, without extra coding to actually attach howitzers to them).since that's about the only chance it has to counter my defenses
P.S. I never tried to allow turtle AI build tanks (THIS_AI_MAKES_TANKS etc. personality properties). Probably this may lead to curious results.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
DvDmanDT
- Rookie

- Posts: 20
- Joined: 13 Apr 2012, 16:51
Re: I want to create a new AI player, how to?
Is the turtle AI included in -ge or must I include it from extras?
Does it (nullbot in general) detect sensor towers near/in its base and try to destroy them? Our current strategy is to build tons of archangels in base and then build sensor towers closer and closer to enemy bases. That, or just use vtols since there are apparently no defenses against that.
Does it (nullbot in general) detect sensor towers near/in its base and try to destroy them? Our current strategy is to build tons of archangels in base and then build sensor towers closer and closer to enemy bases. That, or just use vtols since there are apparently no defenses against that.