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.
I hope you enjoy playing my game. If you have suggestions or ideas of your own feel free to email me, find me on Twitter, or comment on the Facebook Page!
Dan says
Garren, great blog post. That reminds me when I first coded the AI in the Octagon Theory back in 1983-84. I coded it Applesoft Basic and the very first time I played against my AI I was overjoyed and astounded when it beat me. The only problem wat that it took around two minutes for the AI to make its move while flsahing an “I’m Thinking” message. Well I thought this is no good as nobody will wait that long so that’s when I learned Motorola 6502 assembly language. Then I redid the AI in assembly language. The the 1st time I played against the new AI I again was astounded when as soon as I made a move…BAM! The computer made its move. I’d make my next move, then BAM! the computer made its move. Now I had the opposite problem. It was TOO fast. No suspence. So I put in a random length pause that’d just flash the “I’m thinking” message for 1 to 4 or 5 seconds befor the computer made its move. But all the while the computer already knew what it was going to do.
reconinforce says
Now that sounds like good game design! Adding a delay does really add to the gameplay. Doing the AI for Octagon Theory must have been challenging as well, especially in 1983-84. You’ll have to share some of the theory behind the computer’s thinking sometime!