Page 1 of 1

how the AI works and how to win on the hardest setting

Posted: Fri Jan 06, 2017 10:51 pm
by rhaining
This was supposed to be a quick one-pager, documenting the tips and tricks I know now at what may be the peak of my Slay play. It ended up being 7 pages. I hope someone else finds this useful! Comments, questions, feedback, suggestions all welcome!!ApAatWNAqJ5vh4QCiMkrXI9ahgL_Jg

Re: how the AI works and how to win on the hardest setting

Posted: Wed Jan 25, 2017 11:08 pm
by rhaining

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: . 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.

Re: how the AI works and how to win on the hardest setting

Posted: Tue Jan 31, 2017 7:51 pm
by rhaining
The mystery of AI defensive troop placement on the hardest mode gets curiouser and curiouser. See this image:

He is adding protection to his one border hex, but is that coincidence? He is adding 2 levels of protection (from L0 -> L2) on 5 hexes, including border hex and upper left hex, but he could have placed the L2 spearman to cover 6 hexes including border hex and upper left hex.

OK, new proposed algorithm for defensive troop placement w/o upgrades:

* Give no extra weight to border hexes.

* Sort hexes by level of protection (lowest to highest) then in "vertical reading order". (That is, read columns left to right and read top to bottom within a column. In this newest example, all hexes except the town hall and those around it are tied for the lowest level of protection at L0, so the hex in the upper left is the first in the list.)

* Place the best troop you have on the *2nd* hex in this list that is also adjacent to the *1st* hex in this list.

* Recompute from scratch for each remaining troop.

This algorithm is not the best play, but it can at least explain troop placement for this current pic and the previous one. (Sure, he could have placed his L2 spearman to prevent me slipping around him, which I did do on my turn, but the strangest part is this: he had the tax base to upgrade to an L3 knight and support it indefinitely, but chose not to. A clue as to how/when the AI chooses to upgrade. He could have also bought a castle, but I assume he didn't do that because I already had L3 knights.)

Re: how the AI works and how to win on the hardest setting

Posted: Tue Feb 14, 2017 10:54 am
by rhaining
Three new clues/thoughts about AI behavior:

#1: Maybe the AI doesn’t have any fancy tie-break method, maybe it simply chooses the hex that is first in standard reading order when all else is equal. See these pics: . When placing a new town hall, the AI clearly favors the earliest hex in standard reading order. (That is, furthest to the left in the highest row.) If the AI only uses one tie-break logic for everything, this would mean that (e.g.) defensive troops would tend to be placed further north when all else is equal. I’m interested to keep a look out for this now.

#2: I saw another weird AI defensive troop placement but didn’t take a pic. The AI had a line of L1 and L2 units near the border —- and a solitary L2 spearman way back in a strange place. OK, there wasn’t a lot of room on the front line, so it placed the extra troop in a weird way based on tie-break rules, fine. But at least one border hex was protected only by an L1 grunt. Why didn’t it guard that hex with the stronger L2 spearman (like the entire rest of the border) and put the L1 grunt in the back? This makes me think that the AI moves troops in reading order as they appear within the territory (or perhaps as they appear across the entire board) rather than moving the strongest troops first.

#3: I wonder sometimes if the AI is biased against moving troops a long way from where they used to be. E.g., if I present two L1 grunts for an enemy L2 spearman to kill, one near the spearman’s current location and one far away, he seems to always kill the near one. It might just be coincidence, but maybe someday I’ll have to do some deliberate tests.

Re: how the AI works and how to win on the hardest setting

Posted: Thu May 11, 2017 6:49 pm
by rhaining
I took a bunch of pics to try to figure out how the AI chooses where to place troops when it's in defensive mode. After many attempts to explain the behavior, I can conclusively say, I have no idea and I give up. But rather than toss the pics I took, I'll dump them here in case anyone is interested: