Map annotations for AI

For code related discussions and questions
Post Reply
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Map annotations for AI

Post by raycast »

I wonder whether we could add an annotation format to the map. We do have gateways, but I believe we could make AIs even stronger if we allow level designers to add more annotations to the maps.

As a lot of the AI stuff is happening in JS, a simple JSON file might work that is stored in the .wz file and loaded into the AI.

JSON would be extensible, so if an AI designer considers some information useful, and level designers agree, it doesn't really require changes to the warzone engine.

Some of the annotations I can imagine being useful:

- key battlegrounds (enter with a large army, avoid when small)
- good sensor locations
- good artillery locations
- good AA locations (covered against bunker busters)
- airlift targets (constructor droids on extra oil, sensor places, sneak attacks ...)
- defenses setup, with priorities
- areas to keep clear to not block itself
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Map annotations for AI

Post by Per »

I've been thinking about "prefab" designs that the AI could build according to, if it wishes. That way it would build pretty looking (and strategically smart) bases and forward defenses, rather than the random layouts it makes now. This could be done by simply adding structures on the map with a special key in the ini file to indicate that they are only for the AI as suggestions, that I would then add a filter to remove on load, and then add a js function for listing them all (say, enumPrefabs() or something).

Structures that are removed by the no-base and partial-base options in the pre-game GUI would of course also have to be added to the prefab list. Which player owns such prefab structures would be irrelevant, I think, since you may want to build up in the enemy's area or base if you conquer it, so we could just return every prefab building with an enumPrefabs(), perhaps with original player ID intact so you can filter on it.
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Re: Map annotations for AI

Post by raycast »

These "super advanced bases" would probably work (as for say, extra oil locations, the bases could be assigned to a random player or the scavengers), but it won't help the AI with choosing places to airlift to, for example. Rally points, choke points are other non-building annotations that can help an AI. Or a "keep clear" annotation, for places that the AI tends to block. The links aubergine gave are also along these lines.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

I've been pondering about prefabs as well, but as designed by the AI creator not the map maker.

There are many factors for a prefab that a map maker might not be aware of - such as what research an AI has at a given point, or what personality the AI is using (eg. it's base defences will be very different, and built in different places, depending on what they are).

This is one of the reasons I'm asking for a way to dump a load of text to a file in the logs dir (but not a log file). I'd be able to load up a map, create a base (or whatever) on it that works well for my AI in a given spot, then trigger a JS function via chat/console that dumps out an enumStruct in JSON format (or whatever) so that I can make some tweaks to that file and later my AI can load it when it sees it's running on the map.

This way there's no requirement to update the existing map making tools, an AI dev can just use debug mode to create prefabs in-game and then trigger a function in their script that saves them in the desired format. What will work well for one AI will likely not be suitable for another AI, so it really needs the AI dev to design the structure layout rather than a map maker.

There would be other requirements in the JS API, such as the ability to set the orientation of buildings (currently only possible by a human based on the camera position in the game). Also, it would need some additional properties on structure/feature objects - an x2,y2 so the script can work out the area used by a building, etc.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Map annotations for AI

Post by Per »

I was thinking that the AI only used the position, orientation and type of the building, not the exact same building, since, as you point out, the map maker does not know what techs the AI has at any time.

Another thing I've been thinking about is pre-placed orientation-dependent path-finding markers. They could nudge units to drive into a base through one opening and out another, or to keep to one side of a choke on the way in and another on the way out. That would work well with prefab bases. I once tried to teach the path-finding to drive on the left (since Pumpkin was British...) without such clues, but that turned out to be somewhat more complicated than I had hoped.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

Without knowing the AIs strategy and capabilities, prefabs will likely be ineffective. Hence, I think it should be the AI developer who chooses to create prefabs for their AI. In most cases, the prefab data would need some manual tweaking to adjust it based on AI personality - eg. at x,y build either A or B or C depending on personality.

As for pathfinding markers, I pondered that too, but came to the conclusion that it depends what's happening in the game as to which entrance/exit you want to use. Also, in many cases there is only one base entrance - eg. great rift. Furthermore, what happens if a map dev is evil and tells AIs to exit the base via an entrance that leads them straight to scavenger base, or has units returning for repair coming in via that entrance. And most maps don't have these markers on them already, and even if map makers start using them there's no guarantee that they'll use them correctly.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Re: Map annotations for AI

Post by raycast »

Well, without knowing a lot about the map, the AI will likely not make good decisions either.
Which "AI prefab" is best for a particular spot on a particular map likely depends on a number of factors. In particular, we cannot assume the locations to be symmetric or even aligned on the axes. A diagonal entrance will need a very different defense setup. I believe the map maker can give more hints here, but as Per mentioned it will be more of a type of building (i.e. hardpoint vs. bunker vs. wall, short range vs. long range vs. indirect etc.). I like the idea of using the existing map toolchain by giving the items a different user or priority. Yet, I also do see the need to have non-building annotations. And I'd like to give the AI and levelmakers the option to easily develop extensions, by having actual json objects with attributes one AI might use, and the other ignore.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Map annotations for AI

Post by Per »

aubergine wrote:I think it should be the AI developer who chooses to create prefabs for their AI.
But then each AI would need prefabs for every map, both current official maps, future official maps, and custom maps... I do not see that as being feasible. It would be easier to retro-fit existing official maps with prefabs, add prefabs as precondition for a map becoming official, and then request custom map makers to add prefabs. I think.

As for the path-finding markers, they would only be an additional tile weight, not an absolute requirement. And if there is only one exit, then the exit could be lined with an outward lane at one side and an inward lane at the other.

As for non-building annotations, is there something that the existing labels system cannot be used for? Not sure if I see anything that cannot be done with them.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

@raycast: Labels can be assigned to objects, areas, and positions, so pretty much anything imaginable.

@per: Would AIs still be able to build their own bases, or will using the prefab design be mandatory? Surely the solution would be to keep a list of base structures removed by rules.js when applying baseType and make that 'blueprint' available in a prefabs array or function?

prefab[playerID] or enumPrefab(playerID) // returns an array of pseudo STRUCTURE objects that were pre-placed on map for playerID, prior to any removals by baseType setting in rules.js

Maybe pickStructLocation() could be updated to accept a prefab list, so if you're picking a location for your next factory, it will look through the supplied prefab array for a factory blueprint and use that location if it's available. And, because a prefab array is being passed in, AI developers could choose to create their own prefab design for a given map and supply that instead.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Map annotations for AI

Post by Per »

@aubergine: Not mandatory, of course. The rest are all good ideas.
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: Map annotations for AI

Post by Shadow Wolf TJC »

I'm starting work on a new AI (initially for the Contingency mod, but later on, for vanilla Warzone 2100) that would play how I'd personally want to play online, and I'm planning on looking into using switch statements that use mapName to determine how my AI would react to each map in question, such as which technologies to prioritize research in, where to build outposts and forward bases, where to mobilize forces, etc.
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

@Shadow I'm doing something similar -- my AI will do it's best on unknown maps, but for maps I've played I was hoping to define some includes so the AI could include(mapName+".js") to have various map-specific tweaks applied. That way the AI doesn't have gazillions of map tweaks in a huge switch statement at the start.

EDIT: Also, you need to take in to account player position and whether scavs are enabled or not (if they are, and USM is installed, it's a very different scenario for your AI).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Re: Map annotations for AI

Post by raycast »

Ideally, all this would IMHO be stored in the maps themselves. If we can find a common format (usable for more than one AI!) this should be possible.Which is why I suggested the JSON thing, as this is very natural to use for JS AIs and extensible.

In contrast to label annotations, the JSON objects can store information at different detail levels. E.g. a particular spot might be annotated as "good to set up a flamer pit here, but only if researching flamers" (as a low-level flamer pit is not too useful), or annotations that only apply to an AI playing a turtling strategy. Or a player position might be annotated as "turtle" or "turtle, but only at difficult AI strength" (as e.g. the lower level AIs tend to be dead ducks when turtling, and need to be offensive to even deserve the "easy" level). "hardpoints if high-oil, wall if medium-oil, open if low-oil" annotations for defenses. etc.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Map annotations for AI

Post by aubergine »

The JS env used by WZ has inbuilt features for converting to/from JSON, so JSON would indeed be a nice format in that respect.

However, unless we're going to force map devs to learn JSON or require the map tools such as FlaME to read/write JSON, it might not be an ideal solution.

It still doesn't solve problem of a map that doesn't include the annotations (whatever format they are in) -- the AI will always need to be able to handle un-annotated maps. Furthermore, I'm gradually coming to the conclusion that map annotations are likely to be more of a hindrance than a help to AI developers. For example, as an AI developer I'll not only need to get lists of annotations, I'll need to work out if they are applicable to my AI and furthermore decide if they are reliable to use. In order to decide if an annotation is reliable to use, the amount of processing I'll already be doing would enable me to auto-generate the annotation anyway, at which point it's easier to ignore map annotations and just brew my own system for working out where things should go.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply