James chats with the Creative Director of the Codemasters Formula One games, Lee Mather, about the team’s approach towards building a convincing and believable racing AI.
When you think about artificial intelligence in videogames, you might immediately think of one of the millions of creatures designed to jump out of a corridor and wail aimlessly at the player who’s lying in wait to mow them down with a sawn-off shotgun. But there’s a lot more to it than that. Maybe for some it’s enough that an enemy comes at you the moment it spots you, giving no thought to its own safety or well being. But what if that enemy could hear you coming, then sneak around to your position? What if they could radio their squad and have them take up defensive positions in ready for your approach? And what if none of that was pre-scripted, but it happened ‘naturally’ because the AI decided that was the best course of action?
A good AI should help immerse you in the game world they are in, and to get them there takes both a lot of time and developer brainpower. In order to understand more about the process of creating an immersive AI for a game, I got in touch with some people who know better than most the time and effort it takes to get it right. In this third and final of three email discussions with AI programmers and game developers, I ask Lee Mather, the Creative Director on the F1 games at Codemasters, about their approach towards building racing AI that can hold their own on the virtual race track.
James Swinbanks: The AI in the Codemasters F1 games has improved to the point of becoming the benchmark of the genre in recent years. I’ve always been really impressed at how aggressively the AI can race the player, and have been on the receiving end of more than a couple of wonderful cut-backs and ultra-late braking manoeuvres. What’s your philosophy when it comes to building a convincing racing AI?
Lee Mather: First and foremost it’s about getting the AI to a level where they are capable of driving an F1 car, at speed, and in the correct manner. By that, I mean braking and accelerating as a player would. As the racing is very close, and the cars very delicate, making sure the AI races a circuit in the same way as a player would is massively important. The next step is to teach it how to deal with all of the variables that a player has to deal with, those being different aero set-ups, tyre compounds, tyre wear, tyre temperature, wetness, fuel weight, DRS and throttle map settings. Once the AI is capable of that, we start to introduce even more, which covers defending and overtaking, as well as how it behaves when entering the pits or during a VSC or safety car period. Our AI has to consider more on track events than any other racing game.
Given how approachable the series has become, how do you balance the need for believable AI between different levels of difficulty? Does the difficulty level even make a difference?
I think the fact that we first set out to make the AI behave as a player would make the AI drivers more enjoyable to race against. We also do a few things to make sure racers of varying skills still have an enjoyable experience. For F1 2017 we added a difficulty slider which runs from 1-110% and ensures all players get a level which suits them. The slider doesn’t just impact on pure pace of the AI, it also impacts on some of their characteristics. They don’t just ‘go slower’, they drive slower. We achieve this by making them brake and accelerate differently; we don’t just put them in a slower car. Another key change we make is to make them more cautious around other cars, at the lower levels. Players who race at an easier difficulty level will often be a little more erratic, so the AI will leave more space when attempting an overtake, compared to at the higher levels, where they’ll leave millimetres between the wheels.
Understanding that it’s impossible to achieve absolute perfection, how long does it take to “perfect” the AI for each circuit/difficulty level?
The first thing to take into account here, is that we have to build the cars first, so that takes time. Once they’re ready, the level design team set-up all of the racing line ‘splines’ and a huge amount of related data and markup for each circuit, which takes roughly 30 days. From this point we have a suite of tools which run each AI driver (each of our drivers have their own unique set of driver traits, which means they all have their own strengths and weaknesses), each car, track and every combination of grip and weight. From there, we know the limits of each car.
At this point we revisit stage one to see if there are any refinements we can make to the racing lines, which could help the way the AI drive and flow around the circuit. Once we’re up and running it’s a process of tweaking and iterating until all of the performance, character, and way in which lap times are achieved, feels right to the racer.
What about the AI approach to strategy? Has it gotten to a point where they can make strategic decisions on-the-fly, reacting to, say, a player pitting early to look for the undercut or a change in the weather?
There are a few things to consider here. First up, the AI knows more than any person ever could, so in theory, they could have the perfect strategy! Secondly, other elements will impact on that ever happening. The AI wouldn’t just react to the player pitting, they would react to any other vehicle pitting, which could impact on their overall race time.
At the start of a race, we generate a strategy that will get the cars to the end of the race in the quickest time possible. Once the race is live, that adjusts constantly. So many elements impact on strategy. AI cars in dirty air could find they need to pit earlier than the original strategy, due to increased tyre wear; changeable weather obviously has them thinking on the fly, as does any sort of wing damage.
In the case of damage, they’ll work out if it’s more effective to pit for a new wing, or deal with the damage. The AI has to be massively reactive throughout the race, and all the time, never be 100% perfect, as that’s not how it works in real F1. Teams have so much information available to them, but there’s the human element and all of the variables which constantly change throughout the race. Making the AI feel organic, intelligent and exciting is something which is very important to us at Codemasters.
At the start of a race, we generate a strategy that will get the cars to the end of the race in the quickest time possible.
Where can racing AI go in the future? How much further do you think it can go?
Something I’ve witnessed since starting on the F1 series back on F1 2010, is that knowledge and awareness have helped our AI feel a lot more reactive and a lot more exciting to race against. As I’ve already mentioned, they have a massive amount of knowledge about the car and conditions and how that impacts on times and racing lines etc.
The AI also has a great awareness of its surroundings, and a large amount of the immediate world around them. As processing power increases, we can start to empower the AI with an even greater knowledge of the world around them. In racing a move can take a number of corners to pull off, and in reality, a racer learns their opponent’s strengths and weaknesses. They also plan multiple corners ahead. Being able to give the AI the ability to learn and plan ahead will be the next evolution in racing AI for me.
So, a little word from me, the Editor. It has been an absolute pleasure to have James writing for me, since he first wrote about iRacing on Atomic a few years back. Watching him become a regular feature of the freelance circuit has been supremely rewarding, and it's been great getting to know him as a colleague and a friend. And now. he's recently won the rather plum position of Reviews Editor over at Gizmodo.
This might be a loss to me and this site, but it's great for everyone who digs James' passion for his work.
Thanks for being such a champ, mate. You'll be missed.
- David Hollingworth