up vote 15 down vote favorite
10
Share on Facebook

I am new to game programming and am trying to make a basic 2d top-down space game with 2 space ships that fight each other. I am doing well with the user controlled space ship, but have no idea how to even start programming an AI. Are certain methods/patterns better for this situation? Where would I even begin?

link|flag

4 Answers

The Strategy pattern is great for determining what to do but not when to do it. You're also going to need to use Finite State Machines to know which state your AI is in and what appropriate decisions are available.

A Practical Guide to Building a Complete Game AI: Volume I

link|flag

You might want to look at the Strategy design pattern. Essentially write up same basic strategies of how the ships will behave:

  • Move closer to target
  • Attack target
  • Run away from target
  • Move towards power ups
  • Use power ups

Then you will use logic (state machines) to choose between these strategies. For example: If the ships shields have fallen below 50%, then run away from the target and move toward power ups/healing items and so forth.

link|flag
so each time through the game loop, it decides which of those 'strategies' takes priority and then executes that? – jle Aug 4 at 21:08
@jle Pretty much. So each of your strategies will broken down into their own classes, keeping your code organized. – Bryan Denny Aug 4 at 21:10

May I suggest that you buy the book Artificial Intelligence for Games by Ian Millington - it's excellent! :) http://www.ai4g.com/

The source code is at Github - MIT license.

Of course, if you're not using C/C++, then this might be less relevant.

But really an awesome introduction to the world of Artificial stupidity/intelligence.

Things you're going to need from it are steering and state machines. For starters.

link|flag

You might want to look at OpenSteer, and the Steering Behaviors documentation that goes with it. The source code is not beginner-level, but the concepts behind it should give you some good ideas.

link|flag
Do people use opensteer in games or is it more for simulations? – jle Aug 5 at 18:12
I'm at least trying to use it in a game under development. It's working well for me so far. I believe the author developed much of it while working for the Playstation group at Sony - Its likely it made it into some games. MobyGames lists him on the credits of JohnMadden Football and one of the Leisure Suit Larry games. – AShelly Aug 6 at 18:54
FreeOrion is using OpenSteer in its tactical combat engine. – Mike Strobel Aug 10 at 15:12

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.