You say that you understand that the enemy picks the best action based on the best actionValue. It is exactly at this point that the enemy takes that selected action and calls the TakeAction method, which causes the enemy to perform the chosen action. If the best action is to move to that specific grid position, that will be the action it performs
In the MovementAction, the test on each tile for determining if this is a good movement location is to test to see how many opposing units it can attack from that position. If position a would give the unit 3 targets to attack, but position b would only give the unit 1 target to attack, then position a would have a higher score, and be a preferable move position to b.
Oops. I think I misunderstood the question. @Brian_Trotter is right. The MoveAction asks the ShootAction how many targets there are at a specific location. The location with the most targets is considered the best move action. If no player units are nearby it will simply pick whichever location is returned first from the sort. This could, of course, be discarded if a player unit is within ‘sword-distance’ because that action is worth a whole lot
Basically how the logic works is it goes through all the Actions, for each Action it goes through all valid grid positions and calculates a certain ActionValue for taking that Action on that GridPosition
Then the AI simply selects the Action + GridPosition that has the highest ActionValue and takes that action.
As to specifically how it decides where to move, in the course I decided to base that ActionValue on testing how many Units are Shootable from that GridPosition.
For example, if you have a GridPosition where there are no Shootable targets, and another GridPosition where there is one Shootable target, the AI will go to the second Grid Position since the ActionValue is based on the number of Shootable targets.
This logic could easily accomodate other factors… for example, if the unit’s health is less than 20%, the unit may wish to consider moving to a tile that does NOT have shootable targets.
You could assign extra weight to tiles with shootable targets that have lower health than tiles with shootable targets with higher health…
There are a lot of possiblities here, remembering, of course, that adding such logic could increase the amount of time it takes for the enemies to calculate the best actions.