Building Intelligent Games

In the world of game development the term AI has been around for decades, though it was not referring to chatbots and neural networks but rather things like finite state machines and behavior trees. Both of those are fantastic tools for game development and everyone should use them, but this post is not about either. This is about using transformer networks as a way to dynamically control the level of gameplay difficulty. Instead of hard coded values, this is based on individual, (almost) real-time player behavior!

Instead of an old school difficulty slider that locks in specific game parameters to make the game harder or easier all round, a neural network can learn to react and adjust the difficulty moment to moment and without a slider anywhere in the game menus.

This is not theory, this is fairly straightforward to build and I have already done it. It is not a massive LLM we are creating after all, just a tiny model with minimal memory thanks to its transformer nature. Just enough to do this one thing. Data comes in, the network processes it all and chooses an action.

Building and Training the Model

To build a neural network like this, you start with player statistics, such as:

  • movement direction
  • position
  • recent kills
  • lives left
  • time since last death
  • total time played
  • number of enemies on-screen

Plus any other metrics that together paint a picture of the current state of the game. These data points become the inputs for the model. You can experiment with hidden layers and nodes but you really don’t need a lot.

Next a set of actions that this AI game master should be able to take are defined, and those become the outputs. The exact actions will depend on your project, but to use this demo as an example, output actions include:

  • spawning different enemy types and formations
  • increase or decrease the overall pressure (spawn rates and budget)
  • temporarily back off to give the player a moment to breathe
  • launching a massive wave of attack

If you’re building your own, you will need to define these actions ahead of time, and make sure your game code has all the necessary functions wired in to trigger when the neural network sends the signal to do so.

The hardest part is training this game master model, and getting enough data to do so. The demo game has a built-in data snapshot function that also takes a screenshot. To turn this into training data, I had to label it and evaluate every entry. It is not impossible to do, just tedious.

For this demo, I hand-labeled over 1000 entries and trained the AI on them with early stopping to avoid overfitting. I didn’t write it down, but I think it trained for around 20 epochs. The actual training took very little time.

Afterwards, the fully trained model can be converted to a format that is friendly to your game engine of choice. Godot does not natively support neural network formats like ONNX, but because the model is so small, converting the whole thing to a format that works is not a big deal.

Introducing Space Base Bomb Run

To demonstrate the idea, I put together a small tech demo. It’s a vertically scrolling shoot-em-up game where the waves of attacking enemies are controlled by exactly this kind of neural network gamemaster. Every 4 seconds, it takes a snapshot of what’s going on in the game, and takes an action accordingly. It can choose different enemies and attack patterns, as well as tweak the overall spawn rates and budget (higher budget = more elite enemies).

You can toggle visualization of the network on and off while playing (press v) to see it in action, though be warned that is does cover part of the screen if you do so.

I call the demo “Space Base Bomb Run” (SBBR) and I put the game, including the source code / Godot project on github, as well as all the training scripts and tools used to build and train the AI. If you’re curious, you can train your own game master AI model from scratch, using SBBR and the labeling and training tools included.

Do note that SBBR is a tech demo and not at all a polished game meant for release. That said, if you play it you will definitely notice that the game gets harder as you progress – and if you’re struggling to stay alive, the game will actually back off a bit, at least for a moment.

I think this way of using tiny transformer models is both exciting and fun – I like the emergence and adaptability of this approach and can easily see it adapted to other parts of a game than just the difficulty.

Apprentice in the Gaming Industry

Sorry to be blunt, but traditional college degrees are rarely important in the gaming industry. Whether you’re a producer, an animator, engineer or community manager, there are plenty of jobs where a degree is optional. More important than the degree itself, will be any projects you can show off to a potential employer. Real world experience has high value, especially if you have shipped something.

Studying game development in a school setting is one step removed from actual game development and usually comes with a hefty price tag. For those reasons, I don’t think the diploma is a good investment.

I would argue that developing and launching games is a trade better suited for an apprenticeship model. Not just for the student, but in an industry infamous for crunch culture and burning people out within a few years, it’s a step towards a more holistic approach to doing business long term.

For students, the more hands-on experience you can get, the quicker and better you will learn. Not just technical skills, but also process related and interpersonal ones, like how to run meetings, working within budgets and deadlines, and taking ownership in a real-world scenario.

Being in production, you’ll always be ahead of any textbook, and the stakes will always be higher. So you learn fast.

In real-world environments, you’re faced with a blend of new and established tools, proprietary software and depending on the studio, a chance to work with cutting edge and unreleased tech. The bigger the studio, the more of this there usually is to learn.

In my first real industry job, I had to work around hardware that was still in development (the Xbox One and its Kinect attachment). This was tremendously challenging and equally exciting, in part because of the level of secrecy involved.

The 3-Year Model

So how do apprenticeships work? If you’re not familiar with the concept, think of it like a boosted version of an internship. One that involves real work, a salary and benefits (and zero student loans), stretches over a few years and leaves you with a well-rounded education – maybe a job. It traditionally culminates with a graduation project that really showcases your acquired mastery, also known as a masterpiece.

Let’s imagine an apprenticeship that runs over 3 years. You start out making slightly less than a typical junior position but still more than a paid intern. At first you won’t be contributing as much as learning, but in the final year you should be on par with, or slightly above a typical junior salary.

In the first year, you’ll focus on the basics. Sit in on meetings, work under guided supervision, mess around in the different tools, learn about budgets, timelines, testing and release. You will do mostly low level work at this point, but still actively contribute to the making of a game. After year one, you’ll have a good big picture overview of the industry, the studio, title and your role within that environment.

In year 2, you dive into the discipline you are looking to specialize in. You get ownership of smaller projects, where making mistakes won’t halt production. Making mistakes is expected and part of the learning process, but that doesn’t mean there won’t be expectations and real deadlines as well.

In the 3rd and final year, you pick one major feature to fully own alongside the work you are already doing – this is your masterpiece. The apprentice and their mentor set the final scope together, but it should highlight a “specialty” skill as well as other skills covered during the apprenticeship. What that is depends on what you do, of course. An animator will have a different goal than a producer.

At the end of the apprenticeship, the apprentice becomes a master and technically graduates out of their job. Ideally, the company has spent 3 years training a perfect new hire but even if they don’t convert the apprentice, that person walks away with 3 years of industry experience, no student loan debt, and hopefully at least one shipped title to their name.

Where do I start?

If you’re a newcomer hoping to get into the industry, the options are very limited. To my knowledge, there aren’t any studios or publishers offering apprenticeships. I have seen interns get hired into junior positions, but it is rare. If you know of anyone with an apprenticeship model, I would love to know about it.

If you run a studio or are a publisher in the gaming industry, I would strongly urge you to consider something like the model I have proposed. Do the math, and take the benefits to your company culture into account. It’s an investment for sure, but a worthwhile one in my opinion.

Adopting apprenticeships industry-wide would require a lot of leg work and for some, a shift in mentality. It would take time and people with greater expertise than myself to iron out the details. There are legalities and Human Resources to consider, and I am certainly not an expert in either of those. But I do believe that a well-structured variation of the apprenticeship model is better suited for the gaming industry than what we currently have.

Apprenticeships could also be developed with the support of unions, which are perfectly suited to help define win-win apprenticeship models. We need more unions across the industry, but that’s another topic for another day.

Would you take on an apprentice? Would you want to learn this way? For me, the answer is yes to both questions.