Age of Empire II AI Expert System: Part I
Challenge
I am building an AI to play a custom scenario game that I myself play a lot just for fun. I call it Army Rush: 500 pop, post-Imperial, all-visible game with infinite resources played in Amazon Tunnel against five players. I have won with selected civs against Moderate AI. The goal is to see if I can create an AI which can handle Hard or Extreme AIs.
A blank AI
Created ranuzz.ai
and ranuzz.per
in the ai
directory. Just a check for civilization and a chat message to self to make sure that AI was loaded.
; Resign if selected civilisation is not franks
(defrule
(not (civ-selected frankish))
=>
(chat-local-to-self "I am not playing")
(resign)
(disable-self))
; Announce the ai to self
(defrule
(true)
=>
(chat-local-to-self "ranuzz ai. plays army rush only with franks v2")
(disable-self))
- Scout doesn’t move but later started following enemy scout once it came in its line of sight
- All three villager started moving
- one became lumberjack immediately
- rest of them just wandering aimlessly, most likely as civilian explorer
Enabling Scout
After exploring the documentation a bit, I found the very basic way to enable scouting.
(defrule
(true)
=>
(up-send-scout group-type-land-explore scout-opposite)
(disable-self))
Everyone’s a Builder
Since this is an infinite resource game there is no need for economy management and civilian gatherer. All I need is a builder. The inbuild strategy numbers and goals compel the AI to do something towards maintaining the economy and attacking the enemy. For my game I need civilians to be builders. Based on what I have found I have updated the following strategy numbers to make sure no villager is worrying about the economy.
(defrule
(true)
=>
(set-strategic-number sn-percent-civilian-builders 100)
(set-strategic-number sn-cap-civilian-explorers 0)
(set-strategic-number sn-cap-civilian-gatherers 0)
(set-strategic-number sn-maximum-town-size 500)
(set-strategic-number sn-food-gatherer-percentage 0)
(set-strategic-number sn-wood-gatherer-percentage 0)
(set-strategic-number sn-gold-gatherer-percentage 0)
(set-strategic-number sn-stone-gatherer-percentage 0)
(set-strategic-number sn-percent-civilian-explorers 0)
(set-strategic-number sn-percent-civilian-gatherers 0)
(set-strategic-number sn-cap-civilian-builders 50)
(set-strategic-number sn-minimum-town-size 500)
(set-strategic-number sn-total-number-explorers 10)
(disable-self))
Train Train Train
Enabled training with a fixed true
predicate so it doesn’t stop as long as I have buildings available. For villagers the population is capped at 30, but no limit on paladins.
(defrule
(civilian-population < 30)
(can-train villager)
=> (train villager))
(defconst gl-escrow-state 101)
(defrule
(up-can-train gl-escrow-state c: knight-line)
=>
(up-train gl-escrow-state c: knight-line)
)
Building Houses and Stables
With the initial three villagers I immediately assigned two on house building duty and one on stable duty. These are one shot rules and execute only once at the start of the game. As a result, as soon as the game starts two villagers start making houses and one goes out to build a stable.
(defrule
(true)
=>
(up-assign-builders c: house c: 2)
(disable-self))
(defrule
(true)
=>
(up-assign-builders c: stable c: 1)
(disable-self))
Later in the game as I get more villagers I increase the builders for stable. I don’t know how to specify a percentage yet so I manually added rules for all possible population numbers. Ther twenty plus rules where N ranges from 4 to 30.
(defrule
(civilian-population == N)
=>
(up-assign-builders c: stable c: N-2)
)
Buildings are continuously getting built as one finishes. I don’t know yet how to preplan building placement.
(defrule
(up-can-build 0 c: stable)
=>
(up-build place-normal 0 c: stable))
(defrule
(up-can-build 0 c: house)
=>
(up-build place-normal 0 c: house))
The Match
With this primitive AI I was able to defeat easiest
AI in 16 mins. To compare, I can defeat extreme
AI with the same civilization in 10 mins. So there is a lot to improve. See the video and difference below.
{{< youtube BP1gHPr5ltc >}}