I want to implement an ai into a simple street fighter style game, and I want to do this with a finite state machine. For a simple example, this FSM has the states:
Attacking, Chasing, Fleeing
From what I have read online, a good way of implementing this would be to use an Enum, although I'm slightly confused how to do this.
At any one point the FMS is in a current state and should change occur in the game, this state could change through a transition function (next()). Using an Enum like below, how would I keep track of the current state, and how could I make this change when the next() function is called?
public enum FiniteStateAutomata {
  ATTACKING() {
    public FiniteStateAutomata next() {
      if (!gun.isInRange()) return CHASING;
      else if (health.isLow()) return FLEEING;
    }
  },
  CHASING() {
    public FiniteStateAutomata next() {
      if (gun.isInRange()) return ATTACKING;
      else if (health.isLow()) return FLEEING;
    }
  },
  FLEEING() {
    public FiniteStateAutomata next() {
      if (health.isHigh()) return CHASING;
    }
  };
  public abstract FiniteStateAutomata next();
}
 
     
     
     
    