Recent master snapshots provide us with the new javascript engine that is flexible enough to create full-featured AIs for the game in pure javascript. Semperfi-JS is an AI for master/v3.1+ that is written in javascript that is already included with the game, but it still lacks some features. So i just wanted to make a simple AI in javascript, and here's what it turned out to be.

Usage:NullBot is included into the game since 3.1, so you may use it without installing. If you want to try a different version or a different personality, use the standard procedure: Installing a mod. Detailed explanation below:

Spoiler:

There are several alternative ways of installing NullBot:

Put the .wz files you downloaded into mods/autoload folder in your config folder. This is the easiest way, but it will break your multiplayer compatibility: you will be able to play only with people who have NullBot installed as well, until you remove these files.

Put the .wz files into mods/multiplay folder in your config folder, and then enable them with --mod_mp command line option. Pretty much the same thing. This way, you can make separate icons for Warzone 2100, one is with this option, another is without any options, and click the second one when you want to play multiplayer.

Unpack .wz file (which is, as usual, just a renamed .zip file) and put all *.js, *.js.inc and *.ai files into data/mp/multiplay/skirmish folder inside your game data folder (that is, in the same folder where warzone2100 executable is located) (i think it only exists when you compiled the game from source; you may try to pack it into base.wz instead). This way, you can actually host multiplayer games with NullBot without making all other players install the mod. Do not install the scavenger AI this way.

effigy's hack: put the .wz files into your maps folder. Works much like the previous way of installing, but easier. Do not install the scavenger AI this way. Doesn't work on 3.1 beta11 and later!

Another similar hack: unzip these .wz files straight into your config folder.

The AIs are packed into several separate mods due to #3147. It's ok to load two mods simultaneously, but you won't be able to use Semperfi AI in that case due to lack of widget space.

When you want to practice something similar to a real multiplayer experience, try the normal AI on Hard difficulty. If you want to make sure your enemies pick exact strategies, try the extra personality pack instead; you can also use the personality pack for making single-player challenges.

Features:

NullBot is a non-cheating AI. Well, actually, it deity-cheats on hard difficulty and above (assumes full visibility; much like DyDo AI used to do; it doesn't share this full visibility with his teammates though), but it doesn't make him actually do anything impossible or violate game rules. Well, at least it doesn't give itself unlimited oil and fast research, and it doesn't build things that were not researched yet.

NullBot multitasks with several groups. The whole army of NullBot is split into a varying number of groups (from 1 to 6, depending on the game situation), and droids of each group try to act together and help each other. Every group is responsible for a particular enemy player, even though multiple groups may fight against a single enemy. The average size of groups gets bigger as the game progresses.

NullBot adapts to the enemy choices by changing its weapon choice and even research path based on the opponent's prefered way of playing. For instance, if you overuse cyborgs, you will be dealt with by NullBot's machineguns or flamers, and his research of anti-tank weapons will be cut, and if you make too many defensive structures, he will research and send mortars or bunker busters on you.

NullBot works correctly on sea maps. Even though Hover AI is still stronger on sea-only maps, all other personalities have this adaptation enabled as well on all difficulty levels. It attacks ground-reachable enemies first, then tries to research hovers as soon as possible. It also doesn't use ground tanks against sea enemies. Note: it doesn't yet work correctly on VTOL-only maps.

Supported in-game chat commands (for warzone2100 v3.2+ only!):

Spoiler:

!nb whoTell this to make NullBot introduce itself. It will reply with a message describing its version and personality. Should be supported by the NullBot personality to work.

!nb setTell this to set NullBot's subpersonality. For instance, "!nb set mc" sets him to machineguns-cannons. Simply say "!nb set" to see a list of possible personalities. Should be supported by the NullBot personality to work.

!nb resTell this to set NullBot's research paths. For instance, "!nb res mg" makes him prioritize machinegun research. Simply say "!nb res" to see a list of possible research path commands. Say !nb res 0 to make him stop researching completely. Say !nb res clear to make him proceed.

!nb helpAfter dropping a beacon, say this to make NullBot bring his strongest group to the beacon to stay there for the next 5 minutes. You can repeat this command to bring more of his combat groups there, if any.

!nb txDismiss groups that were sent to help you, allowing them to do whatever NullBot wants.

!nb truckAsk NullBot to give you a truck. It will always give you one, even if it's his last truck, unless you are on truck limits. It will flash a beacon near your new truck. If you yourself have placed a beacon, he will give you a truck nearest to the beacon.

!nb powerAsk NullBot to give you power. It will give you 1/3 of its power. This command is not very useful because the AI will most likely have almost-zero power.

Difficulty levels:

EASY: Research specialization and all adaptation mechanisms are disabled. The AI researches all technologies in a particular order and spams units without considering the opponent's choices, which makes him pretty weak. Note that lack of research specialization has less effect in team matches, where a team of 4 actually has a chance of researching most of the technologies.

MEDIUM: Research specialization is enabled, but research and production adaptation is still disabled. The AI picks one of the five pre-defined narrow research paths and researches its sub-branches uniformly, regardless of the game situation.

HARD: This is the best non-cheating AI i could make. It rapidly adapts its research path and unit designs to the enemy choices. Note that it doesn't necessarily defeat the Medium AI, because adaptation is not really effective against anybody who makes the same choices all the time. But this AI is designed to have as little amount of clear flaws exploitable by humans as possible; ideally, the only chance of defeating Hard AI is actually playing better than him.

INSANE: This AI differs from Hard AI only due to the hard-coded cheats it is bound to use, like preserving all defenses in no-bases mode. On 3.2+, it will have double power (you can already see that in the current master).

Note that not all of these difficulty levels make sense for the extra personalities. They usually don't discriminate between Easy and Medium, because they were designed with a specific research path in mind. The difference between Medium and Hard is also less, because most of the personalities don't support research adaptation yet. For ~Turtle~ AI, Medium and Hard difficulties are completely equal, for it doesn't really produce tanks.

Known bugs:

Some of this code is highly ineffective and CPU-intensive. It may cause the game to slow down or stutter when you have a lot of units on the map and many AI instances are running simultaneously.

AI units may sometimes get stuck. Even though some workarounds for it exist in the AI code, it should rather be fixed on the game/c++ side by creating a more effective pathfinder.

This AI doesn't make proper use of map gateways. In v3.1, gateways are not supported at all by the JS engine, while in 3.2/master there is still no easy way to find out wether some tile of the gateway is already blocked.

There is some strange error message about some "missing template 140" that i don't really understand, see also #3161. A certain workaround applied in v1.0, that makes this bug very rare, but it can still be reproduced artificially.

NullBot doesn't use commanders. This won't be fixed until commanders are actually useful in multiplayer.

Challenges:

The extra mod includes a remake of "Back to Basics" challenge (with NullBot ~MC~ as your enemy) and "Hide Behind Me" challenge (with NullBot ~MR~ controlling your allies). Note that NullBot is a non-cheating AI, so the challenges will not necessarily be more difficult or more easy.

It also includes two more challenges: the "Startup" challenge (Startup T1 no bases, with NullBot ~MC~ as your enemy showing how the standard MG rush works), and the "Flame Wars" challenge, where you fight on Mountain map against NullBot ~Flame~ and two turtles.

Here is a single-player challenge called "Anchor". It is based on NullBot v0.11 and features all four personalities this AI had.

Here is a single-player challenge called "The Paradigm". It is based on NullBot v1.29 (~MC~ and ~Hover~ personalities), and you enjoy having a NullBot Scavenger AI as your ally.

AI vs. AI matches

Please read this howto carefully before trying to make AI vs. AI matches, to avoid many common mistakes.

Spoiler:

Pick a map with more than two players. There are some maps with a spectator positions, you can pick one, but don't rely on a spectator mod (explained below).

Put yourself on a spectator position, or any other position that is ok to be empty.

Make one of the AI teams allied with you, so that you had a place to put your outpost, and you are also able to monitor their research by having a research lab now.

Enter debug mode ("cheat on" or shift+backspace).

Kill your trucks or pre-placed combat units as soon as possible (select them and press Alt+K). Otherwise the enemy AIs will react on you and the experiment will no longer be clean. Any spectator mod can't do that (lack of removeObject in 3.1 JS API), so you can't rely on it.

If you have any buildings, kill them one by one in the same manner (for the same reason).

Scroll the screen view to one of the bases you are allied with.

Open the debug menu (Ctrl+O), press the structures button.

Give yourself a command center. But not your standard command center, but rather one of the three campaign command centers (New Paradigm, Collective or Nexus). Having a friendly standard command center so close will make NullBot stop taking oil that is closer to your CC than to his. Having your CC (of any kind) outside the allied base will distract enemy Nexus/Semperfi AIs (they will try to attack it), even though NullBots won't bother killing a CC.

Give yoursef a lab to monitor friendly research.

You can use the "deity" cheat to see what happens on the board.

Note: there is no "autogame on"-like cheat that you can use to make NullBot control your units. The "autogame on" cheat makes Nexus AI on Easy difficulty control your units.

Its good you have made this AI ..I had this idea of having multi player warzone where you have observer mode and you AI making folks could pit your AI"S agains each other ..this would need a fix for the diff data and the multi player screaming cheat but think robot warzone

One question. Why do you call doResearch() all the time? Is there a bug with research events? It should not be necessary to run this in a timer at all - you should be able to rely on events to tell you when to research the next thing. The same goes for produceDroids(). I have a very rarely called timer in Semperfi-js which just sanity checks that bugs didn't eat production / research orders.

It has to be called in eventResearched and eventStructureBuilt and ... anything else? Well, i left those timers just to be sure i didn't forget anything. I'll try to remove them

By the way, does eventResearched get called when an ally finishes some research? Cause i didn't make sure labs are filled all the time (the lab remains idle instead of researching random things when the research path doesn't provide anything else to research).

Arreon wrote:First off, it uses templates that none of the other AIs use. Perhaps you can find a way to "import" stored templates (new master feature) into the ai scripts.

You can construct templates in run-time both in master and 2.3; my previous AI experiment, MCRbot, used twin assault cannons and other fancy things that aren't mentioned in templates.txt or assignweapons.txt. The new JS engine isn't aware of templates at all; you just order a factory to produce unit with some body, some propulsion and some weapons as separate function arguments.

NUM_WARRIORS < MAX_WARRIORS.We fill all groups till NUM_WARRIORS, and only then start filling them till MAX_WARRIORS. The return statement guarantees that only one groupAddDroid call happens.Or is there a better way to implement this?

The AI will not research anything that an ally is researching, so that should not be a problem. However, I've noted that if a human player races to researche something that an allied AI was already researching, then that AI's research lab will become idle without eventResearched being triggered for it. Will look for a fix for that.

In general, when I wrote the events/triggers, I did not think much about what events an AI wants from things that happens to allies, not itself. I will need to go over the events with that in mind.

Per wrote:The AI will not research anything that an ally is researching, so that should not be a problem. However, I've noted that if a human player races to researche something that an allied AI was already researching, then that AI's research lab will become idle without eventResearched being triggered for it. Will look for a fix for that.

In general, when I wrote the events/triggers, I did not think much about what events an AI wants from things that happens to allies, not itself. I will need to go over the events with that in mind.