Skip to content
Matthias Mailรคnder edited this page May 17, 2015 · 10 revisions

AI Does What AI Can

It might happen that you create a custom unit and find out that the Skirmish AI is not using the unit. This is because AI cannot use what it cannot see. I am myself very new to understanding the working of AI, so I will only explain the basics. Once the developers see this post, they can make corrections where necessary.

Making your AI

Go to your "Rules" folder and open ai.yaml

Every AI that you use in the game is defined here. So copy the first AI code, which will be this:

HackyAI@RushAI:
		Name: Rush AI
		BuildingCommonNames:
			ConstructionYard: fact
			Refinery: proc
			Power: powr,apwr
			Barracks: barr,tent
			VehiclesFactory: weap
			Production: barr,tent,weap,afld,hpad,spen,syrd
			Silo: silo
		UnitsCommonNames:
			Mcv: mcv
		BuildingLimits:
			proc: 4
			barr: 1
			tent: 1
			dome: 1
			weap: 1
			spen: 1
			syrd: 1
			hpad: 4
			afld: 4
			atek: 1
			stek: 1
			fix: 1
		BuildingFractions:
			proc: 30%
			powr: 35%
			barr: 1%
			tent: 1%
			weap: 1%
			pbox: 7%
			gun: 7%
			tsla: 5%
			ftur: 10%
			agun: 5%
			sam: 5%
			atek: 1%
			stek: 1%
			fix: 0.1%
			dome: 10%
		UnitsToBuild:
			e1: 50%
			e3: 10%
			apc: 30%
			jeep: 40%
			arty: 15%
			v2rl: 40%
			ftrk: 50%
			1tnk: 70%
			2tnk: 25%
			3tnk: 50%
		SquadSize: 20

Go at the bottom of the page and paste it right after the last AI. We want our AI to be passive, that is it relies on long range weapons. so first of all we call it Passive AI and do these changes:

HackyAI@PassiveAI:
		Name: Passive AI

We can ignore BuildingCommonNames: and UnitsCommonNames: and go right to BuildingLimits: This limits the number of buildings that the AI must have. Since the AI is going to be passive, we want it to accumulate lots of ore so we change the number of proc: to 6 from 4.

We also ignore BuildingFractions: and go right to UnitsToBuild. This tells the AI which units it should build. Lets change v2rl and arty to 60% as we are going for a long range user and add our own entries. Suppose you defined t72 tank as a unit, so add this line.

t72: 80%

So now the AI will make a lot of your tanks plus a lot of long range units. Start up Skirmish, select your AI and have fun!

Support Power Targeting

You can also change how the AI decides to use its various support powers and super weapons, simply by editing the yaml. Take another look at the Rush AI, and look for the bit about Support Power decisions.

		SupportPowerDecision@spyplane:
			OrderName: SovietSpyPlane
			MinimumAttractiveness: 1
			Consideration@1:
				Against: Enemy
				Types: Structure
				Attractiveness: 1
				TargetMetric: None
				CheckRadius: 5c0
		SupportPowerDecision@paratroopers:
			OrderName: SovietParatroopers
			MinimumAttractiveness: 5
			Consideration@1:
				Against: Enemy
				Types: Structure
				Attractiveness: 1
				TargetMetric: None
				CheckRadius: 10c0
			Consideration@2:
				Against: Enemy
				Types: Vehicle, Tank, Infantry, Defense
				Attractiveness: -10
				TargetMetric: None
				CheckRadius: 10c0
		SupportPowerDecision@parabombs:
			OrderName: UkraineParabombs
			MinimumAttractiveness: 1
			Consideration@1:
				Against: Enemy
				Types: Structure
				Attractiveness: 1
				TargetMetric: None
				CheckRadius: 5c0
		SupportPowerDecision@nukepower:
			OrderName: NukePowerInfoOrder
			MinimumAttractiveness: 3000
			Consideration@1:
				Against: Enemy
				Types: Structure
				Attractiveness: 1
				TargetMetric: Value
				CheckRadius: 5c0
			Consideration@2:
				Against: Ally
				Types: Air, Ground, Water
				Attractiveness: -10
				TargetMetric: Value
				CheckRadius: 7c0

Don't worry, it is actually very easy, even if it is a lot. It is basically just explaining how a person would decide where to use its support powers and superweapons.

Let's take a look at how it decides to use its atomic bombs:

		SupportPowerDecision@nukepower:
			OrderName: NukePowerInfoOrder
			MinimumAttractiveness: 3000
			Consideration@1:
				Against: Enemy
				Types: Structure
				Attractiveness: 1
				TargetMetric: Value
				CheckRadius: 5c0
			Consideration@2:
				Against: Ally
				Types: Air, Ground, Water
				Attractiveness: -10
				TargetMetric: Value
				CheckRadius: 7c0

OrderName is the name of the order it gives when firing the atomic bomb. Don't worry, you can just copy it from the wiki. Look at https://github.com/OpenRA/OpenRA/wiki/Traits#nukepower at the OrderName entry. See, simple copy and paste. You can do the same for any other power.

MinimumAttractiveness is how 'juicy' a target must be before the AI will actually fire its atomic bomb at that location. In this case, the 3000 means that the total worth of the targets must be at least $3000 in that area before the AI will fire the atomic bomb there. How does it know to use buildings? How does it know to use their $ worth? How does it know how big the atoic bomb explodes? All of this is done by the next thing, namely...

Consideration these are the ways in which the AI makes it decisions. Each time it decides "Do I want to use this power here?" it can take multiple things into consideration. In this example, it wants to find a location that has a lot of enemy buildings, but avoid targets that have ally units nearby. It does this using two considerations:

Consideration@1:
	Against: Enemy
	Types: Structure
	Attractiveness: 1
	TargetMetric: Value
	CheckRadius: 5c0

This says that when it looks at a particular spot to nuke, it is looking for enemies Against: Enemy, structures only Types: Structure, within 5 cells CheckRadius: 5c0, each structure's cost value TargetMetric: Value is multiplied by 1 Attractiveness: 1. I.e. We really like shooting really expensive enemy buildings, especially where there are many buildings together.

While:

Consideration@2:
	Against: Ally
	Types: Air, Ground, Water
	Attractiveness: -10
	TargetMetric: Value
	CheckRadius: 7c0

Says that any allied Against: Ally, air or ground or water units or buildings Types: Air, Ground, Water, within 7 cells CheckRadius: 7c0, have their cost value TargetMetric: Value multiplied by -10 Attractiveness: -10. I.e. Even if there are only a few allies near a very lucrative spot, we still won't shoot there. Unless the enemy buildings are worth at least 10x times more than our ally units.

The sum of all these considerations are taken together, and the final answer must be > 3000 MinimumAttractiveness: 3000 (in this example) for the AI to shoot at an area. So a lone war factory won't be attractive enough for the AI to shoot at. But 2 war factories together will. But 2 war factories with ally units nearby won't.

By adjusting these decisions we can define how the AI chooses their targets. We could even make a dumb AI that shoots itself!

You see, it isn't really hard. Simply think of how you would use a particular support power, and then tell the AI to consider it in that manner.

Players ๐ŸŽฒ

Modders โœ๏ธ

Developers ๐Ÿ”ง

Clone this wiki locally