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. I'm Tommy Thompson and in this episode
AI and Games, we're going to look at a fantastic example of this found in the popular city-building
simulator Cities: Skylines. Let's 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.
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 posted 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 episode:
- 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 realiy 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 intracacies 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 signaling, 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 signaling 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.
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 happieness.
- A reference to their currenct activity, including any destinations they are currently
headed towards if they're travelling around the map.
- Their health. - Their wealth.
- And lastly it maintains 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. - And lastly seniors, where citizens retire
and no longer go to work but still use city services and commerical 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 running amok picking up newspapers, cans
of tennents super and jelly sweets. 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 being around... six in-game years!
Oh man, the first AI and Games video was in 2014, that means I just wasted my entire Cities
Skylines life trying to sound smart on the internet... what a waste of time. There was
so many things I never go to do, like an episode on Shadow of Mordor or Dark Souls or that
bloody Forza video I threaten in the welcome video on the channel homepage and why am I
only thinking about the videos there's much more to life than YouTube and oh man my wife's
gonna kill me.
So given we have so many citizens moving around, how does the road system work? Before I can
get into the movement of traffic, lets look at how roads are built, given this influences
how the search process takes place afterwards.
Under the hood, roads are modelled as a collection of nodes. Two nodes connected to one another
is a segment, providing both start and end points. 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 of road stores
information about itself, including what type of road it is, how many lanes it has and what
types of lanes these are. This all become useful when a citizen wants to travel between
locations.
Now this information extends to sidewalks too, which operate on a slightly different
system, given they can be elevated or tunneled to go over or under traffic and crosswalks
are established when building them alongside roads to enable pedestrians to cross. All
of this information comes into play when a citizen makes the decision to travel to a
destination.
Having citizens move around in Cities: Skylines is - by the developers own admission - the
single greatest challenge faced during development, resonating with the issues that plagued Sim
City. Given it is arguably the one system that any player who spends more than 10 minutes
in the game will come to interact with, hence ensuring a basic level of functionality and
avoiding some of the more gnarly edge cases was paramount. To that end, not only did Colossal
Order rework this system several times over, but as we'll see in a moment, some elements
that players might want to see were actually removed because it only made the problem worse!
When a citizen decides they want to travel, they use all of the available information
about the cities transport infrastructure: including the roads, sidewalks, crossings,
public transporation routes and available vehicles and will find the fastest possible
route to their destination. Hence the node system within the roads and sidewalks is searched
through to find a valid path. This actually factors in numerous elements based on the
citizen involved and the local geography. If a citizen owns a car, they will attempt
to drive it. If they don't have a car, they'll not only check for a valid path on sidewalks,
but also factor in whether there is any public transportation that can speed up that process.
In some cases there are strict rules on how this can operate: specific buildings such
as hospitals and fire departments will enforce the use of ambulances and fire trucks repsectively
rather than a fire fighter taking a bus with a bucket of water as your home turns to ash.
Meanwhile pedestrians cannot walk on highways and hence if they don't have public transporation
options and sufficient sidewalks to get them to their destinations, they'll resign themselves
to defeat. Colossal Order have never outright stated what they're search algorithm is. However,
given the rich data laced throughout the road network, it would not be surprising to find
a modified version of A* or Dijkstra's that achieves the desired effect.
The resulting system is actually quite remarkable that a character can make this level of nuanced
decision making, especially at this scale. Given a pedestrian can easily walk and take
multiple forms of public transportation in order to get to their destination. The destination
they want to visit can vary and while they will prioritise going to the primary destination
for their life stage - such as school, college or work - they will also go to commercial
units such as shops and restaurants, as well as clinics and hospitals.
When a citizen takes a car, it utilises not just the road network topology, but the additional
constraints of the road types themselves against the vehicle. This includes the dedicated cylcing
or bus lanes, as well as the speed limits, the number of lanes and the current congestion
level. Provided the system can generate a path through the road network, then the vehicle
will begin to drive it. It can also still use the public transporation system. Hence
it is possible for a citizen to drive to a metro station and then use that for the remainder
of the journey.
In essence, that's how Cities: Skylines works, but there several edge cases revolving around
traffic, the number of citizens in the city and much more. And we're going to get into
that now, but before I do there are two really important caveats I need to cover:
- First things first: not all citizens are rendered in the city at any point in time.
There is a hard limit on how many citizens and vehicles can be simulated on the streets
of your city at any given time. Now you might think this is just a rendering issue: in that
the game is still simulating all citizens under the hood and you just don't see it.
No, no, no; Cities Skylines outright caps how many citizens can be travelling within
the city at any given time. There is a separate system that monitors whether there are available
slots for travelling citizens and then allows them to travel once there is space. While
the movement of citizens is important for maintaining the economy and their own personal
health and education, you the player are not penalised for a citizen being unable to travel
due to this simulation cap. The system that oversees this ensures that players are not
punished because a citizen is - due to compute limitations - unable to travel to their desired
destination.
- The second caveat, is that the traffic you see on the streets is a separate simulation
system from the citizen management. When you watch traffic, it's a collection of thousands
of small physics objects that read information from the road network to figure out how to
move through it.
So for the remainder of this episode, let's look at two things: first how the traffic
simulation systems work, and secondly, what happens when traffic jams start to occur in
the game world.
Traffic is handled in a separate simulation system that is actively calculating how to
follow the chosen path, the velocity that the vehicle should be going at and preventing
collisions. While traffic looks like this smooth and constantly updating process, it's
only rendered that way. The traffic simulation is updated 4 times a second, and the rendering
system takes two of these simulation updates to derive movement of the objects on screen.
When traffic is simulated a vehicle knows the path that it's been told to go on and
they know where on a given road they can drive - hence they won't drive the wrong way down
a one way. Paths through the roads are calculated on a spline using the nodes of each road segment.
This allows for tight curves and intersections to be handled as gracefully as possible.
These simulation steps allow for vehicles to calculate whether collisions are going
to occur at intersections or from traffic slowing down. Vehicles do recognise traffic
lights and will slow down and stop if the lights dictate they can't travel into the
intersection. Meanwhile, to minimise crashes, vehicles check ahead of themselves during
simulation for whether a collision between two vehicles is imminent. This annotates a
segment of the road as liable to cause a crash, at which point the distance to the segment
is used to decide which vehicle goes first and they move through it on a first-come-first
served basis, each adapting speed accordingly.
But of course despite all of this effort, there are still issues with traffic jams.
In part this is to be expected if the player does not build the network sufficiently, but
there are other issues that impact the system. So let's wrap up by talking about what the
simulation does and does not do in order to keep it manageable.
First of all, unless something happens that causes the a given path to no longer be valid
or has been extensively modified, a citizen or vehicle will not change their pre-calculated
route. You may think there would be some opportunistic behaviour going on where a character may re-evaluate
their options on the fly, but nope, only in the event something happens that negates the
original path. While in some larger segments of road with multiple lanes that could spread
traffic out, you'll notice they don't change lane again after moving into the one they
originally decided upon - even if that would make sense to do so. Having vehicles change
lanes midway through a segment of road was actually something that Colossal Order experimented
with, only to later remove, because during internal testing, it actually made everything
worse.
When traffic builds up, you may see cars sitting idle at junctions and not moving forward,
despite having room to do so and that's often because their paths have determined further
issues up ahead and as a result they opt to simply stand idle.
Last but not least, Cities Skylines has a fallback option for when traffic jams are
overwhelming. If a vehicle has found itself in gridlock and unable to move, it will actually
teleport back to its origin. And the previously mentioned worker system may well stop that
citizen from trying to travel again and avoid punishing the player any further. This was
an decision made by Colossal Order in order to make the transporation challenge more manageable,
given even some relatively small cities begin to be impacted by this issue. This decision
has actually proven to be contentious among some players, who prefer the challenge it
presents and use mods that actively remove the teleport feature.
Building a city simulation game is incredibly demanding, especially as the granularity and
fidelity of the simulation increases. Cities: Skylines is an incredible effort from a team
that - at launch - was comprised of only 14 people. But it shows the core tenets of their
design from previous games could steer them through to making a game that is now the leading
game of its kind on the market. With an entire generation of city planners still working
away for hours on end perfecting those road networks, Colossal Order know this is a problem
they need to tackle again in future releases. The issue of the traffic is an ongoing one
within the Cities: Skylines community - with some PC players using mods to teleportation
or outright replace the pathfinding systems used in the game. Meanwhile others are happy
to leave it as it is and embrace the chaos.
Thanks for watching this episode here on AI and Games. Cities: Skylines was one of several
topics voted for recently by my crowdfunding supporters on Patreon and you can expect to
see some fun and quirky new topics being explored in the coming months. Plus a special patron
shout-out in this episode goes out to Dillon Gotham, Stephen Barr and UrielNinjaBear! To
have your say in future episodes and your name on screen right now, join the AI and
Games Patreon via the links on-screen and in the description.