'AI and Games' is a crowdfunded YouTube series that explores research and applications of artificial intelligence in video games. You can support this work by visiting my Patreon page.
Quite often artificial intelligence is in control of so many elements of our favourite video games, but we seldom take notice and take it for granted. An AI tool or system can be running in plain sight, providing a critical element of the game that players are largely unaware of until it starts to go wrong. Let's take a look at a fantastic example of this found in the popular city-building simulator Cities: Skylines. In this article, we'll take a look at the traffic and navigation systems that run in every city, how citizens go about their day-to-day routine and how developers Colossal Order sought to address the traffic jams that can easily emerge.
About the Problem
Released in 2015 and published by Paradox Interactive, Cities: Skylines is an open-ended city-building simulator where players are responsible for many aspects of modern urban planning. This includes establishing city zoning, utilities such as water and electricity, establishing zones for residential, commercial and industrial growth, public services such as schools, fire services and law enforcement, all the taxation that is required to pay for it all and - critically for this episode - road placement and establishing transportation services within the region. Colossal Order, having achieved success with the Cities in Motion series had sought to expand into a full city building title, a sentiment that at that time Paradox Interactive did not share. However, 2013 saw a gap emerge in the market courtesy of the latest entry in the beloved SimCity franchise from Electronic Arts. The game came under intense criticism at release with players posting screenshots and videos of cities not behaving as expected. And while the issues raised were numerous, there are two critical points we are exploring in this piece.

Sim City had issues with pathfinding and citizen behaviour.
Sim City had issues with pathfinding and citizen behaviour.
First, the traffic simulation in SimCity was highly problematic. Traffic would often bottleneck, creating massive jams that seemingly never resolved themselves. Meanwhile, should the play attempt to rework junctions to enable better traffic flow or add public transportation this often proved to be more a hindrance than a help. Secondly, the citizens in SimCity did not behave as expected. While it was anticipated that the sims would live their pre-determined lives - working jobs and living happily in their homes - in reality, they lacked any individuality. Sims would leave the house in the morning, find the nearest job available in the city and then after the working day, they didn't necessarily go back to the house they left that morning. Instead, they simply go to the nearest vacant property. While this is undesirable it seems slightly innocuous, until you realise how big an impact this had on the already troubled traffic systems as well as the actual behaviour and economy of the cities themselves.
While SimCity sought to address this through numerous patches, it never really coalesced at a solution that players were happy with. However, Cities: Skylines when released satisfied many of the features that players sought from its competitor. And as we'll see in a moment, it not only tracks the passage of every vehicle through your city's road system, but your citizens will go about their daily business as one would expect. That said, it still suffers from traffic congestion issues.
Now before we get into the intricacies of this problem and how it is tackled in Cities: Skylines, it's important to acknowledge that this isn't just an issue that plagues video games, but the real world too. Traffic management systems in the real world are highly complex and incredibly expensive to research and develop. These systems have to manage signalling, traffic flow and congestion, tracking and responding to accidents and other incidents on the road such as spillages, damage to the road or faults emerging in signalling systems and CCTV cameras that used to provide oversight. There are efforts to employ artificial intelligence to handle the complexities of real-world traffic management, but it is far from a solved problem at this time. Hence, it's understandable that as city-building simulation games seek to become more and more realistic, the challenges that developers face will rise accordingly.

How Citizens Work
First let's talk about the citizens, how do they work and what impact are they going to have on the traffic network. Each citizen in Cities: Skylines has information that is used as part of the city simulation. This includes:
Their name.
What level of education they have.
Their residential address.
Their place of employment or education if they have one.
Their overall level of happiness.
Current activity, including any destinations they are currently headed towards if they're travelling around the map.
Their health.
Their wealth.
References to familial relationships and what other citizens are related to them.
Each of these features impacts the game in different ways. Levels of education influences what types of jobs they take on, the performance of these businesses and the value of residential areas. Meanwhile, happiness is shown to the player and gives a barometer for how well you're performing, given there may be services these citizens require, such as healthcare or utilities that they feel is lacking or the job opportunities in the region aren't up to scratch. But perhaps what's most influential on citizens behaviour moving around the map is their age. While a citizen does have a numeric age, this isn't exposed to players by default, but the key part is that they live their lives in five stages:
Children, where they start going to nearby schools if there is capacity.
Teens, who go to high schools if there is space.
Young Adults, who either attend university or get a job if they can.
Adults, who not only move out of their current home and into a new one if they can, but will also settle down and start their own families.
Seniors, where citizens retire and no longer go to work but still use city services and commercial businesses.
This has a huge impact on the transportation network, given kids are going to school, adults are either at university or in a job and pensioners are still active in their senior years. Some of these citizens will be in their own car while others use public transport. And this is a very difficult balancing act, given not only will your city grow if you're doing your job right, but citizens age at an incredibly fast rate, with their average life expectancy of around six in-game years.
How Are Roads Built?
So given we have so many citizens moving around, how does the road system work? Under the hood, roads are modelled as a collection of nodes. Two nodes connected to one another is a segment, providing both start and endpoints. Your average road in Cities Skylines is actually multiple segments glued together, given a segment has a maximum size. Each node in a segment is known as a control point, this provides start and positions for roads, as well as the intersection with other roads creating junctions. Each segment