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?
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. |
|||
|
You might want to look at the Strategy design pattern. Essentially write up same basic strategies of how the ships will behave:
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. |
|||||
|
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. |
|||
|
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. |
|||||||
|