skip to Main Content

So currently I am working on a simple game for fun. In the game you walk around in a map and meet foes and enter battles similar to those in Pokemon. I have finished almost everything in the game and I now want to implement AI for the non-playable fighters (the foes). The game is pretty simple and there is very little complexity in terms of the actions that me or the foe can do. The possible actions the foe can do are to block and use attacks (the attacks vary in terms of damage and cost). So my question is, what data structure or method would be most suitable for this purpose? As I said it is not meant to be really complicated but it should be somewhat challenging. I have read about some ways in which AI is implemented in games such as action lists but I feel these methods are way to complicated for a game like this.

2

Answers


  1. As pointed out by @Frecklefoot, your question is extremely broad. However, if you’ve got a simple game, start by putting together a decision tree for you foes (given a state of the game, what are the possible actions a foe can take and how would it decide between them) and then implement using if-then or switch statements.

    Login or Signup to reply.
  2. Here is a very simple class for “AI” for a game you described. As you can see, this is just a partial solution. You’ll have to come up with the Attack class (just damage and cost, right?) and the AttackResult class.

    I would use this as a dependency for your Foe, so you can just inject his brain when you construct him. That way, you can inherit from this class and create different types of enemies (some smart, some stupid, etc.):

    public class FoeBrain {
        bool block;
        ArrayList[Attack] attacks;
    
        public FoeBrain() {
            block = false;
            attacks = new ArrayList[Attack]();
            ...
        }
    
        public AttackResult determineAttack() {
            ...
        }
    }
    

    Add whatever other methods you think it needs. It might need some massaging; it’s been a while since I developed in Java.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search