WILL YOUR OPPONENTS LEARN FASTER THAN YOU?
This Dev Story is about A.I. (Artificial Intelligence), torment and delight of any racing game fan. Pitting players against believable and engaging opponents is one of the hardest challenges in developing racing games: give AI-controlled competitors an unfair advantage or make them too hard to beat, and you end up with a recipe for rage quitting; dumb them down too much, and they are not going to keep players engaged long enough! Just like physics or controls, A.I. can make or break a racing game.
So our Programmer Jacopo Essenziale is here with us today to explain how game developers constantly strive to put the intelligence in Artificial Intelligence, and how we decided to leverage Machine Learning to train AI riders in the new SBK Official Mobile Game.
THE NEW SBK EXPERIENCE
J, as he is called by the rest of the team, describes his role in the project as follows: “As a videogame programmer, my job is all about translating game ideas, mechanics, and features into code, capable of running efficiently on a mobile device. In the SBK project, I’ve been mainly involved in the development of the new AI system, player’s riding assists, and some of the online features”. He has no doubts regarding the biggest challenge with this project: “Surely getting the most realistic, beautiful, challenging, and fun experience you usually get in PC or console racing games on the limited resources provided by a mobile platform”.
J’s favorite new feature in the next incarnation of SBK Official Mobile Game is “the new physics and bike handling experience, something that I am noticing while we proceed with the development and is slowly making a difference for this game to me”. He would describe this game as “Innovative. Knowing how the whole thing is designed and structured under the hood, I realized that the project brings some ideas that may throw the basics to make some steps forward in the racing game genre for mobile in the future”.
JOURNEY INTO THE MIND OF AN A.I. RIDER
To get down to the nitty-gritty of our game’s A.I. development, we ask J what the tools of his trade are: “Well, most game development is done through the Unity game engine. Game mechanics and most of the AI code are mainly written in C#. AI training, which is the process used to make the AI learn how to ride on a specific track and condition given some constraints, is done using some optimization algorithms based on machine learning techniques that make use of neural networks to generate a model of the AI personality we can “mount” on a rider to make it ride properly. Such algorithms are written in Python and make use of the TensorFlow library from Google. Since the learning process can be a time-consuming task, we also make use of web technologies to be able to distribute training jobs on multiple machines to reduce waiting time”.
He adds that there are a few issues to consider when developing and training A.I. for a game: “First, you need to consider that developing AI for videogames is usually different from developing AI for the ‘real world’: in the latter case, you want to get an AI that solves a specific problem in the best possible way, and you usually want it to be perfect. In video games you are not aiming at perfection, you are aiming at believability, and this is especially true for racing games, where you want AIs to ride their bikes as a real rider would do, you want them to be able to make mistakes, to improvise, to be believable. For this reason, we try to ‘model’ an AI rider’s behavior by teaching it how to ride a bike, how to seek the best racing line, how to react to an obstacle on the way, and such models generate a huge set of parameters for the designers to tune. This is where Machine Learning comes to hand, as it provides algorithms that can automatically help in producing a valid set of parameters to feed the real model with, given a set of rules and constraints such as ‘you should avoid going out of track’ or ‘you should try to go as fast as you can’”.
In the video below, you can see the very first lap raced by an AI-controlled rider learning the ins and outs of a track in SBK Official Mobile Game:
THE WAY TO REALISTIC A.I. MODELS
The biggest technical improvement that J is particularly proud of is the A.I. model itself: “AIs now actually ride the bikes the same way the players do, acting directly on bike controls (throttle, brake, steer). Nothing is simulated—AIs are riding for real, and we use parameters to shape their personality, how aggressively they ride, how late they brake, how early they get back on gas, how much they tend to ‘force’ an overtake instead of braking and letting competitors go”.
And how does he make sure that what he is developing is true to the real-world experience of riding a bike?
“On the AI side, this is achieved by modeling believable competitors, capable of riding a bike as a real rider would do. We can measure how close we are to our objectives in two ways: by watching a lot of real racing videos and comparing our AI’s behavior to what happens in a real-life WorldSBK race, and through playtesting, a lot of playtesting and collecting real feedback from the users. Therefore, Beta testing is so important to us!”.
If you found this dip into artificial intelligence fascinating, we recommend you check out our Dev Stories section to learn more about game development from the team behind the SBK Official Mobile Game. And, in case you are already up to speed, stay tuned for our next devlog update coming really, really soon!