The idea to add a single player mode to ReconInForce was proposed about one year ago today. Initially RiF was supposed to only have online multiplayer. Just the thought of tackling a “human-like” strategy game AI was extremely daunting. But the reality was that most people wanted a way to play the game alone without having to wait on another person to take their turn. By that time in development I sort of had a grasp on how I thought the computer should play the game. Somehow I just had to program it… Realizing this would require a lot of non-computer time sitting around putting thoughts to paper, I strategically scheduled the RiF AI design kick-off to coincide with my wife and my hiking trip to Peru. What better time to reflect on video game creation than while sipping Pisco at Hostal Wara Wara’s rooftop bar in Cusco.
Over the course of ten days of hiking through the Andes I had plenty of time to soak up the beauty of Peru and managed to scribble out some pages of hand-written notes about how I played ReconInForce. The culmination of this endeavor was a series of equations that described how units were grouped into squads, where they placed their objectives, where they moved and how they chose their targets. By the time I hopped off the plane at MSP I was itching to crack open my Mac and strap in for some hardcore coding.
The AI would be split into three layers:
- The “manager” level which oversaw the long-term goals of the computer
- The “squad” level which coordinated the movements of a pack of units
- The “individual” level which decided how each unit reacted to the immediate situation
The first step was to criss-cross each map with invisible roads that the computer would use to drive troops towards the player’s base. These avenues always began at the computer’s base and ended at the player’s base. Along the way the invisible roads would zig-zag to pass near capturable flags or call-in zones to ensure units detoured towards points of interest on their way to destroy the player.
The “manager” level AI would assign weights to each avenue and send more or less units down each road based on where the player was deploying their troops. At this point I was able to add some personality to the commanders as well: some commanders barrel down just one avenue while others spread their forces evenly across the entire battlefield. It was one of those nice touches to introduce a more “humanlike” element with very little additional effort!
Each attack avenue was given one “squad” level AI, which was responsible for assigning objectives to the soldiers and also requesting reinforcements from the manager. To request reinforcements, the squad level AI would evaluate the human enemies along the avenue and then put in requests for the correct countermeasures. For example, if the player deployed lots of tanks, the squad level AI would request lots of anti-tank soldiers. The manager would look at the requests and determined where new soldiers were needed the most, deploying them accordingly.
The “unit” level AI was the most fun, deciding at the soldier level where to move and what to shoot. Before every decision, the “unit” level AI would evaluate nearby tiles on the board, assigning a score for either moving to that tile or shooting at the player’s unit on that tile. Really these were just equations, which went a little something like:
- Score for moving to a tile = (how close to destination) x (how much cover on tile) x (bonus points for capturing a flag) x (negative points for moving next to a known enemy) x (negative points for occupying a deployment zone)
- Score for shooting at a tile = (how much damage will be inflicted) x (bonus points for finishing off the enemy) x (bonus points if target is next to a flag) x (negative points if the target has no action points) x (bonus points if the attacking unit has indirect fire)
Now I had to address one last problem: how to manage scouts and indirect-fire units? These troops behaved goofy when told to attack down a specific path. Scouts, for example, couldn’t shoot so they would blissfully drive right past all the enemies and snuggle up against the player’s base. Artillery would also ignorantly drive right past the main army when they should be staying in the back behind all the big guns! I solved this by grouping scouts and indirect fire units into a different AI layer that responded to “hotspots” of player activity rather than scooting around and capturing flags. So instead of moving down pre-determined avenues, scouts and artillery in ReconInForce will meander about, checking up on the troubled areas of the battlefield.
The AI has one more trick up it’s sleeve. When approaching a control point that is overrun with the player’s units, the computer will keep one of it’s soldiers in reserve until near the end of the turn. I call this unit “the blitz.” If the squad level AI has failed to capture the control point, “the blitz” will banzai charge the flag and attempt to capture at all costs. The idea here is that the AI would rather lose a unit than risk letting the player have more resources at the start of their next turn. “The blitz” added such a devastating effectiveness to the AI that I chose to unleash it only on the hardest difficulty levels.
The first time the computer beat me I was utterly ecstatic. I couldn’t believe I had actually pulled it off. The computer player in ReconInForce is one of the things I am most proud of in this project. Hopefully this post gives you some appreciation to the thought and effort behind the computer player. In essence, whenever you play RiF in single player you’re playing against the thought process and tactics of the developer himself. In this way I feel that a little part of me is in every game of ReconInForce.