Next on the list was AI. I had a plan for this. Since most interactions are over in 2-3 turns, I don't think I have to worry about a higher AI (where the AI is trying to think long term). I think, (at least initially), I just want to encourage the AI to move towards the player and be fairly aggressive, staying in cover and shooting if the chance to hit is high. These ten rules are definitely just a starting point.
- Find all possible tiles the character can move to, initializing them with a score of 0.
- Assign points to any tiles that are in cover (+10). If the character is currently not in cover, give all of those positions an extra boost to encourage the character to move into cover. (+10)
- Add points for tiles that are in range for the character to shoot at the opponent. (+10)
- Add points for tiles that close the gap between the AI and opponent. (+5)
- Add points for positions in cover that flank the opponent (+20)
- Add points if the opponent is within range and has more than a 50% chance to hit. (+10)
- Add even more points if the chance to hit is 80% or more. (+20)
- Add even more points if the chance to hit is 95% or higher. (+30)
- Order the list by total score, descending order (highest first)
- Pick the top score from the list.
When I add difficulty levels later, I will randomize the top 3-5 scores and pick one. This will help to give the AI some unpredictability and ensure that it's not always brutally taking the best position. Everyone makes mistakes, and it's important the AI does too (except on maybe the highest difficulty level). I may do this sooner than later to keep things interesting.
This AI is currently working, but I have some timing issues, where the AI moves into cover, but fires his weapon for his second action before he has completed his first action.
Here is a series of screenshots showing the AI's at the beginning of a turn (standing out of cover), and then moving to cover and shooting at the (flanked) player.
This one is showing the timing issues I have, where the AI fired (action 2) before completing his walk to the new cover (action 1), in the process destroying the cover.
Next I'm going to tweak the timings so the actions are one at a time and add side steps to the characters so that when behind cover they don't shoot out their own cover, but step to the side and shoot around the cover.