A few quick updates. I know the doc isn't 100% correct -- it's a lot of guesswork. I'm not super inspired to update it yet, but I might become inspired if I (or others on the forum) have any brilliant new insights into how the AI works. If and when that happens, I'll also try to edit it down to 5 pages. :^)
In the meantime, two games have me scratching my head to explain the AI's play.
#1: I didn't save pics unfortunately. I left a large-ish army out on a limb. I thought I was safe because the AI who could kill it would need to merge his existing troops into an L3 knight, and he had plenty of "safe expansion" available to his L1 grunt and L2 spearman. My territory was larger than his by a fair amount, but I had no L3 knights. It's very possible that I was just not paying close enough attention and he had insufficient "safe expansion" available without upgrading. It's also possible the AI checks moves that involve upgrading and moves that do not involve upgrading in one pass, and the score for killing my army with a single move of an L3 knight outweighed his other options. It's also possible my model for AI play is complete bunk.
#2: The mysteries of AI defense continue to elude me. See this pic: https://s28.postimg.org/cbug9hkyl/IMG_0464.png
. The AI sat in this configuration for many turns. I had a much larger territory with multiple L3 knights. He had 13 hexes so was saving 5 per turn and I believe he would have eventually upgraded to an L3 knight and began attacking if I left him long enough. But why in the world does he choose this defensive pattern?? Maybe he doesn't choose to build a castle because I already have an L3 knight so he figures a castle wouldn't help him? I'll have to keep an eye out to see if this explains why the AI sometimes builds castles and other times doesn't. (In many of my games, I refrain from building an L3 knight as long as I can, thinking this will allow me to expand faster.) Even if that explains why he doesn't buy a castle, why in the world doesn't he put his best defensive troop one hex back from the border? My hail mary explanation is as follows. The AI doesn't move his best troops first, but instead moves his weakest troops first, or, he moves troops in some harder-to-guess order such as reading order within a territory. The AI moved his L1 grunt first in this situation and put it in the best defensive position -- in a hex that is not a border hex but is adjacent to the most border hexes. He then moved his L2 spearman. Since the AI has no concept of "distance to border", all possible moves with his L2 spearman evaluated to the same score. So the AI fell back on its hidden hex tie break value to choose which hex to put the L2 spearman on, which in this case was a poor choice.
A few things the AI definitely did not do. It did not maximize the number of hexes that gained L2 defense. It did not maximize defense for hexes with the lowest "distance to border". It did not add a level of protection to its town hall or its L1 grunt.
But, I can think of another weird defense algorithm that can explain these placements. Given it cannot expand safely or upgrade then expand safely, and given it chooses not to buy a castle, how should it place its troops? Maybe it doesn't care about protecting border hexes at all. Maybe instead it just cares about adding protection to the most hexes starting in a weird reading order -- left to right then top to bottom. Reading L to R then T to B, the first hex that does not have protection is the hex furthest to the left. Maybe the AI considers placing a troop there or on any hex adjacent to that one, and chooses whichever one covers the most hexes. So, it places it's L2 grunt first, and the best way to place it while adding protection to the all-important left-most hex is as he placed it. The next hex in the weird reading order that doesn't have protection is the one at the top. Again, it evaluates putting its next best troop there or on an adjacent hex and finds that it can place the L1 grunt as it did to maximize protection added while still adding protection to the hex that is next in weird reading order. This would not be good play, and I seriously doubt this is how the AI works, but it could explain this particular picture so I'll have to keep an eye out for more defensive positions to see if this funky algorithm could explain them.