Best book to learn AI?

Apprentice
Posts: 16
Joined: 2010.01
Post: #1
I've been making a game for the iPhone and now I want to add an AI cpu. But I have never made AI before and I am not sure where to start. What's the best book to learn how to make AI? (or any good online resources?)

thanks! Smile

Edit: I forgot to mention it is a 2D game.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #3
I think the best discussion on AI for 2D games is in the iPhone Game Development book from O'Reilly:
http://www.amazon.com/iPhone-Game-Develo...817&sr=8-1
Though hardly comprehensive, it is thoroughly practical.

Other books include:
Mat Buckland's:http://www.amazon.com/Programming-Game-E...pd_sim_b_1
which is certainly the most fun to read, though written for C++ programmers. Code is included for a terminal Q&A style app, a demo of flocking behaviors, a simple soccer game, and a shooter vs. bots game that includes lua scripting.

Brian Schwab's book: http://www.amazon.com/Game-Engine-Progra...pd_sim_b_3
is more complete, with examples in C++. Most of the sample code is built around the an Asteroids-type game. His code is good.

Ian Millington's book: http://www.amazon.com/gp/product/0124977...d_i=507846
attempts a comprehensive coverage of the topic. He is a great writer (see his Game Physics Engine book), but this book comes off as pedantic and not very practical. The code examples are pseudocode, but his website offers a working version in C++.

Steve Rabin's AI Game Programming Wisdom series
http://www.amazon.com/AI-Game-Programmin...pd_sim_b_5
are all very good, but definitely not for beginners. However, the predecessor to this series, Game Programming Gems, has an AI section in every edition. For instance, the first Gems book
http://www.amazon.com/Game-Programming-G...700&sr=1-1
has articles on "Designing a General Robust AI Engine", "A Finite-State Machine Class", "Game Trees", and a great series on pathfinding with A*. Despite being 10-years old, these are still worth reading.

Lastly, if you want the official academic textbook (read: of no practical use), it is Russell and Norvig: http://www.amazon.com/Artificial-Intelli...751&sr=8-1

Good luck.
Quote this message in a reply
Apprentice
Posts: 16
Joined: 2010.01
Post: #4
johncmurphy Wrote:I think the best discussion on AI for 2D games is in the iPhone Game Development book from O'Reilly:
http://www.amazon.com/iPhone-Game-Develo...817&sr=8-1
Though hardly comprehensive, it is thoroughly practical.

Other books include:
Mat Buckland's:http://www.amazon.com/Programming-Game-E...pd_sim_b_1
which is certainly the most fun to read, though written for C++ programmers. Code is included for a terminal Q&A style app, a demo of flocking behaviors, a simple soccer game, and a shooter vs. bots game that includes lua scripting.

Brian Schwab's book: http://www.amazon.com/Game-Engine-Progra...pd_sim_b_3
is more complete, with examples in C++. Most of the sample code is built around the an Asteroids-type game. His code is good.

Ian Millington's book: http://www.amazon.com/gp/product/0124977...d_i=507846
attempts a comprehensive coverage of the topic. He is a great writer (see his Game Physics Engine book), but this book comes off as pedantic and not very practical. The code examples are pseudocode, but his website offers a working version in C++.

Steve Rabin's AI Game Programming Wisdom series
http://www.amazon.com/AI-Game-Programmin...pd_sim_b_5
are all very good, but definitely not for beginners. However, the predecessor to this series, Game Programming Gems, has an AI section in every edition. For instance, the first Gems book
http://www.amazon.com/Game-Programming-G...700&sr=1-1
has articles on "Designing a General Robust AI Engine", "A Finite-State Machine Class", "Game Trees", and a great series on pathfinding with A*. Despite being 10-years old, these are still worth reading.

Lastly, if you want the official academic textbook (read: of no practical use), it is Russell and Norvig: http://www.amazon.com/Artificial-Intelli...751&sr=8-1

Good luck.

Thank you so much for that list!! Grin I was thinking about buying Programming Game AI by Example but when I download the source code to see what you learn in the book, it was visual studio (.vcproj) Sad When I read books I like to follow along with the code and write the code on my computer as I read. Is there any way I can use xcode for the example code in this book?

Thanks!
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #5
MrPenguin9 Wrote:Is there any way I can use xcode for the example code in this book?
I recall was able to convert some of Mat Buckland's code, but the graphics are draw with GDI, (the Windows analog to Quartz2D) which presents a big problem.
However, I was able to convert all of Brian Schwab's code to Mac OS X since it is C++ and OpenGL. I doubt I could share it, however, since it is copyrighted material. I guess I could try to contact the author...
But you can actually do the conversion yourself by creating a C++ project in Xcode, adding the OpenGL and GLUT frameworks to the project, and fixing any incompatible code. Usually, this just involves fixing the timers, since OS X returns time in seconds as a double instead of in milliseconds as an unsigned int. Also, you will have to change anywhere it says
Code:
#include <GL/glut.h>
to
Code:
#include <Glut/glut.h>
Other than that, it should be pretty straight-forward.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.03
Post: #6
I can't give you any book references, but I can tell you this. When doing AI the most important thing to remember is that player doesn't know what's under the hood! Before I got into game development industry, I've always thought about AI as a bit of an extraordinary thing. My first game I've worked on was motorboat racing game. It needed AI. So I simply asked an artist to make a path from dummy objects, and just made AI to go from one object to another with some smoothing and randomness. It took me like a couple hours to code, and it worked perfectly! Later I just added a few tweaks to escape when it got stuck, etc. Doing AI simply fake things as much as possible. Player doesn't care if it's an advanced neural network, or simple sin(x) function. The goal is to make it fun and believable! KISS! Keep It Stupid Simple! Keep this always in your mind. :-)
Quote this message in a reply
Apprentice
Posts: 16
Joined: 2010.01
Post: #7
johncmurphy Wrote:I recall was able to convert some of Mat Buckland's code, but the graphics are draw with GDI, (the Windows analog to Quartz2D) which presents a big problem.
However, I was able to convert all of Brian Schwab's code to Mac OS X since it is C++ and OpenGL. I doubt I could share it, however, since it is copyrighted material. I guess I could try to contact the author...
But you can actually do the conversion yourself by creating a C++ project in Xcode, adding the OpenGL and GLUT frameworks to the project, and fixing any incompatible code. Usually, this just involves fixing the timers, since OS X returns time in seconds as a double instead of in milliseconds as an unsigned int. Also, you will have to change anywhere it says
Code:
#include <GL/glut.h>
to
Code:
#include <Glut/glut.h>
Other than that, it should be pretty straight-forward.

Too bad the source code is copyrighted. I usually like to compile and run the source code to what you learn in the book first, but since I can't, could you tell me what you learn in Brian Schwab's book? Smile Which book did you prefer, Brian Schwab's or Mat Buckland's book?

Edit: What I meant by "could you tell me what you learn in Brian Schwab's book" is could you tell me what examples/games you learn to make. Like the way you wrote about Mat Buckland's book "a demo of flocking behaviors, a simple soccer game, and a shooter vs. bots game"

Thanks!

Smilediver Wrote:I can't give you any book references, but I can tell you this. When doing AI the most important thing to remember is that player doesn't know what's under the hood! Before I got into game development industry, I've always thought about AI as a bit of an extraordinary thing. My first game I've worked on was motorboat racing game. It needed AI. So I simply asked an artist to make a path from dummy objects, and just made AI to go from one object to another with some smoothing and randomness. It took me like a couple hours to code, and it worked perfectly! Later I just added a few tweaks to escape when it got stuck, etc. Doing AI simply fake things as much as possible. Player doesn't care if it's an advanced neural network, or simple sin(x) function. The goal is to make it fun and believable! KISS! Keep It Stupid Simple! Keep this always in your mind. :-)

Thanks for this helpful advise! Smile
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #8
There are so many aspects of AI. Books will only cover commonly used algorithms such as path finding, state machines, and other game specific things, which are quite vast. When it comes to AI, it boils down to coming up with your own system to fit your specific needs. For example, you can learn A* but it may not need that level of complexity, and you may have more specific needs.
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #9
Brian Schwab's book contains the following:
Chapters 1-3: Basics of AI and overview of the Asteroids game code.
Chapters 4-14: General discussion of all of the major game genres and their AI (RPG's, FPS, Platform, Racing etc.) Very little code in this section.
Chapters 15-17: state machines
Chap. 18: scripting
Chap. 19: influence maps and pathfinding
Chap. 20: Steering Behaviors
Chap. 21: Combinations of the above techniques
Chap. 22: Genetic Algorithms
Chap. 23: Neural Networks
Chap. 24: Other Techniques - including Decision trees and fuzzy logic
Chap. 25: Distributed AI
Chapters 26-28: Miscellaneous stuff
Quote this message in a reply
Apprentice
Posts: 16
Joined: 2010.01
Post: #10
Thanks! Smile I think for now I'll buy Programming Game AI by Example and just use my windows pc for the example games.

Just out of curiosity, has anyone here read Real-Time Rendering, Third Edition? (Amazon Link)
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.04
Post: #11
"Doing AI, simply fake things as much as possible. "

This is so true. You will learn more from Smiledriver's example than all those books!

Never use "A.I." when you can use a simple cheap heuristic. Never use a heuristic when you can use a simple cheap trick.


As a curiosity, it's worth noting that what's called "AI" in the game universe (a bit of pathfinding, a computer opponent targeting you, etc) would probably be labelled "an algorithm" or "heuristics" in the AI universe. Indeed, something like IBM's Deep Blue that plays chess so well ... is it "AI"? In the context of AI research probably not, it's mainly a trivial brute-force approach with neat hardware. But then philosophically, some would say a thermostat is intelligent. Of course, none of this will help the fireballs in your game!


Anyway what Smiledriver said is absolutely critical. I think sometimes one thinks there is some sort of "ingredient" AI that can be added to games, as far as I've seen that's usually not the case. Just think of the cheesiest, simplest possible algorithm/trick to achieve your aim.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #12
Yes! Less is more. I haven't done much AI programming, although I've studied a bunch of interesting algorithms and techniques (a*, neural nets, genetic algorithms, etc.). I can say this though: In my game, Ace Omicron, which we just released a week ago on the App Store, the demo AI takes up all of about 75 lines of code and took me probably 45 minutes to do. I did it at first just to have something to look at and always intended to make it "better", but it looks surprisingly convincing, so I just left it that way. Believe me when I say this: Doing the AI was the easiest part of the game.

Pure smoke and mirrors. Dumber than dumb. ... but it looks pretty good! In fact, I was just testing out OpenFeint in the game this morning and was watching the AI do some alien kills and discovered it was getting achievements! That was very cute to see happen, but it wasn't what we intended so I had to stop letting it get credit for alien kills LOL

The alien AI is even dumber! All it does is pick random locations to go to on the screen and keep shooting at the player. I just randomize the time it takes between picking locations, and randomize when they do spins, and also randomize which way it's shooting a little bit to make it look like it's missing the player. Oh yeah, and if it gets too close to the player it picks another location to go to. It's really dumb... Please don't tell anybody. Sneaky
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2010.12
Post: #13
The http://aima.cs.berkeley.edu/index.html is an ideal resource book for learning Artificial Intelligence in a detailed way. It describes all latest innovation in Robotics and Intelligent Systems.
Quote this message in a reply
Post Reply