Getting Started with AI and Programming in Games

Alex J. Champandard on October 12, 2007

Gallius asks “I grew up with games; I’ve been playing them all of my life. My programming knowledge is very limited. Over the last few years I’ve developed an interest in creating my own games. Would you mind pointing me in the direction of some good resources for not only AI, but also game programming in general?”

It’s a great question. Since you’re keen to learn programming, my advice is to actually make games (with help from examples) and integrate AI into them. It will take some time for you to become comfortable as a coder, but these days it’s easier than it’s ever been.

Here’s how I would approach your situation:

  1. Get familiar with Python as a programming language.

  2. Download PyGame and look into some examples.

  3. Implement simple game AI techniques like steering behaviors.

  4. Experiment with AI techniques from existing libraries.

That, in a nutshell, is the best way to learn about AI and programming with games. Here’s why and how…

Two Ants Nests and Many Flowers

Screenshot 1: Ants2D simulation in PyGame by Simon Oberhammer

Becoming Comfortable with Programming

The traditional programming language used in the games industry is C++. It’s important to keep that in mind, but frankly, it’s probably the worst place to start for a beginner. In my time, I started with Pascal but these days there’s much better.

I recommend you start with Python; it’s a programming language that’s intuitive to work with and easy to understand. You’ll also be able to build industrial-strength products with Python too, for example:

  • Eve Online is primarily a Python application, though the low-level engine (graphics) is written in C++.

  • Civilization 4 uses Python for various AI, gameplay, interface and configuration scripts.

  • Many studios, including Rockstar Games, rely on Python for certain tools, as it does a great job at bringing many different pieces of functionality together.

What makes Python such a good language to start with?

  • Batteries included — There are libraries for everything!

  • Intuitive yet powerful — It’s designed for easy reading.

  • Third-party bindings — Many game engines are supported.

  • Open source — Most programs and libraries are entirely open.

Here are some good free resources to get you going:

Spend the time and get comfortable with Python; it’ll pay off in the long term. Then just as you start feeling comfortable, move on!

Venturing into Game Development


The next step is to start prototyping with 2D graphics using PyGame. PyGame is a library that provides the primary elements you need to build a game.

Here’s some advice to get you on the right track:

  1. Download, read the documentation and install it locally.

  2. Try some of the games and/or demos to see if it works.

  3. Take an example and modifying it, or build your own simulation.

Once you’ve got going, start thinking about different things you’d like to build using artificial intelligence. A great place to start with game AI is using Craig Reynold’s steering behaviors to build “boids” that wander, avoid obstacles, seek and flee other boids.

Experimenting with Artificial Intelligence

Orange Data-Mining

Finally, once you’ve got the hang of creating simple games, you can move on to using more interesting AI techniques. I don’t recommend you implement advanced technology yourself, you can do that later. However, you can learn a lot by simply applying existing software to solve problems for you, and use that in your games.

If you’re serious about AI, you should read Artificial Intelligence: A Modern Approach.

A good place to start is with the Orange library. It will allow you to play around with machine learning techniques as a user without having to implement any of the low-level algorithms. Applying AI in practice as a black box is one of the best ways to learn about neural networks, decision trees, Bayesian networks. See the getting started guide for Orange.

Words of Encouragement!

You can’t learn coding over night, but it can be easy if you enjoy the process! It gets more fun as you go along too. Keeping a diary isn’t a bad idea either as you’ll be able to catalog your own progress, which I find encouraging.

Anyway, the rewards are certainly worth it. As a programmer you’re more likely to get into industry easily and be paid more!

Does anyone else have some advice for Gallius?

Discussion 3 Comments

mihaic on October 16th, 2007

When I want to learn something new, I usually like to think of an application and start to implement it. For me the best way to learn is by actually doing something. But for a complete beginner with programming, I think the best way is to start with some basic programming techniques like learning about lists, maps arrays together with some basic algorithms. Once you get the general idea, than it is much easier to start applying the knowledge. As a language, I also believe Python is a good choice and also Java could work.

alexjc on October 18th, 2007

[B]Fernando,[/B] Indeed; great suggestion! Rebuilding a good game is a great way to learn. [B]Manakel,[/B] I'm aware of Panda3D; it looks very good I have to say. Some ex-colleagues of mine are now using it professionally. I didn't mention 3D as it's a bit more advanced already... I have another question in the queue for next week about that :-) [B]Mihai,[/B] Thanks for your advice. Some of the python books i mentioned take that practical approach. It does really help! As for Java, it certainly has the advantage of having good tools (Eclipse) and a more verbose compiler for a static-language. I can't say I have much experience with it, but it seems to do the job! Alex

johnsimpson on April 28th, 2014

I'm really getting into AI for games programming but it's taken a long time! This is a really good article. There's another really good blog on how AI works for beginners if anybody's interested - it's on

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!