I want to create a new AI player, how to?

Get some help with creating maps or modding.
Need a map editor or other tools, look here!
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

I want to create a new AI player, how to?

Post by DvDmanDT »

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!
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

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).
DvDmanDT wrote:I want to add more defenses/artilleries as well as larger attacks.
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.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: I want to create a new AI player, how to?

Post by aubergine »

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
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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?
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

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.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

DvDmanDT wrote:Any idea why? Are there any specific parts/functions/algorithms you know cause slowdowns?
Emm, actually, just in case. Could you get the latest master snapshot (or git if you're using it), run it with

Code: Select all

--debug=script
command line key and show me the output (either command line output or stderr.txt, depending on the OS)? I could catch the function that causes slowdowns on your system if i see what it says (or you can find out yourself, it will write things like "the XXX function took NNN ms ...")
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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?
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

Would it be ok if I included a map-specialized version of nullbot with my map?
Sure, any time. The AI is public domain (aka CC-0 license). Here is an example of how it is done.
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.
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.
After some testing, I'm starting to think it's related to scavengers (not yours, the built-in).
Hmm, a report will still be interesting, cause i have some scavenger-specific code.
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).
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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?
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

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.
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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?
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

First of all, please get v1.17 as soon as it's out ... should have some important fixes :oops:
The bots have 8 or 10 oils in base to start with, so does it just decide it doesn't need any more?
Nooo :augh: 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.
How would I increase the size of the attacks?
In -tail:

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
And what should I modify to make it build more defenses?
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).
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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.
Last edited by DvDmanDT on 16 Apr 2012, 12:03, edited 1 time in total.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: I want to create a new AI player, how to?

Post by NoQ »

Also, does those numbers ever increase?
Check out becomeHarder(). I don't really remember what it does ...
It's not a bad idea to build tanks and defenses if you have enough cash?
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).
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).
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.
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.
since that's about the only chance it has to counter my defenses
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).

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.
DvDmanDT
Rookie
Rookie
Posts: 20
Joined: 13 Apr 2012, 16:51

Re: I want to create a new AI player, how to?

Post by DvDmanDT »

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.