AiGameDev.com
Welcome to your new online hub for Game AI!

“Join the official #gameai IRC channel on irc.freenode.net for discussion about AI in games!” – Alex

Getting Started with AI and Programming in Games

Alex J. Champandard

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

PyGame

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?


Bookmark and Share

Comments

Comment on this article. | Show full forum thread.


by Fernando 12.October 2007
One thing you can do is to take a simple game that you like and try to program it yourself. You can start with something like Pong and Tetris and then move to something more complicated like Pacman. It's probably easier to try out new programming techniques with stuff you already know and then apply it to your own ideas.

by Manakel 15.October 2007
Hello,

A good 3D game engine fully designed to be used in Python is panda3D
(www.panda3D.org).

It provides also a very nice Event & Messenging System as well as a tagging system for every object in the render .
(Ex:you can tag entities with flag like "friend", "factionA" etc...)
However no AI has been implemented so far in this engine, so it's a good place to be the "pionner"

by Mihai Campean 16.October 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.

by alexjc 18.October 2007
Fernando,

Indeed; great suggestion! Rebuilding a good game is a great way to learn.

Manakel,

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 :-)

Mihai,

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

by SRC 03.January 2008
I'm wandering why all the languages, I'm trying to get oriented with programming and all I've heard. it seems confusing

by Chris Dircks 04.January 2008
I have a related question, that hopefully someone here can help me with. I'm interested in AI design, but not really looking to build my own game. Which existing games or frameworks would you recommend to start building AI mods for? I've done some searching, but I haven't found any good resources to start building AI mods.

FPS is a slight preference but I'm open, and I'm not picky about languages either.

There was an active dev community for counterstrike bots back before CS Source, but it seems to have died away and most of the sites have vanished. :/

by vic 19.February 2008
One very good and surprisingly useful resource for a complete beginner is a book by Mark Overmars "The Game Maker Apprentice". This is excellent if you have a kid around age of 10-14 and you want to introduce programming and game design to them. If you prefer collective wisdom, the ratings on Amazon are consistently five stars by pretty much every reviewer there. Again this book is great for a beginner tween, the drop-and-drag interface is excellent, with capability for some serious coding if interested (http://en.wikipedia.org/wiki/Game_Maker).

As far as Python, I found that introduction for absolute beginner by Michael Dawson "Python Programing" is also good, because it focuses on very simple games like asteroids or tic-tac-toe (again, see Amazon reviews) but is not as friendly for the kid since it is heavy on coding (even if simple) right from the get go. But than you can use Python LiveWires or PyGame as continuation. Again, if you have a young tween at home, the Game Maker is a fantastic resource.

by mfragin 16.March 2008
I think the best book for Python game programming is Andy Harris' Game Programming: The L Line. This book really does a good job in teaching good programming techniques and even includes a game engine that can be modified for your own games.

http://www.amazon.com/gp/product/0470068221/ref=cm_arms_pdp_dp

by Kaidong Wang 29.March 2008
I have leaned C++,but I want not to learn python
Is there many resources which writted by C++?

by niku 06.April 2008
Ive got a problem I was wondering if you could help me.
I'm interested in AI but I know i need to learn principles. I know programming in C.and I've worked with micro controllers and robotics but i know neither of these can lead me to AI(at least academically) . another problem is I'm sophomore in electronics . i know that credits related to AI in software engineering (undergraduate) are algorithm designing , AI and neurion networks (in my country) .so it seems i have no chance to study AI academically.so I'm determined to do it on my own. im really willing to know the principles of AI.I don't know exactly how to get started I mean should I learn a programming language more seriously or try to learn and study the same credits i have mentioned, what should i do as a person with this limited knowledge about AI .thanks

by Chris 25.August 2008
@niku

Not long ago I was in the same boat as you. I got my undergrad in CPE, but I was always fascinated with A.I. I took genetic algorithms my senior year which really got my cogs turning. I recently went back and got my M.S. in C.S. specializing in A.I. I can safely say that the best text I have ever come across for teaching background theory is Artificial Intelligence: A Modern Approach (2nd edition). Keep in mind that A.I. is a somewhat broad field, and this book covers more than just techniques that apply to games.

I would also suggest that if you think this is more than a hobby, more than just a fleeting interest, you should seriously consider dropping EE. I know it may seem like a waste to take 'fields and not actually use it, but you may save yourself years of soul searching by following your interests now.