package Server.Automaton;

public class Automaton {

    private GameState state = GameState.SETUP;

    public GameState getState(){
        return state;
    }

    private Boolean canEvolve(int val){
        int currOrd = state.ordinal();
        int setupOrd = GameState.SETUP.ordinal();

        if (currOrd == setupOrd && val > 5) {
            System.out.println("Invalid number of player");
            return false;
        }
        return true;
    }


    public Boolean evolve(int i) {
        if (!canEvolve(i))
            return false;

        int currOrd = state.ordinal();
        int lastOrd = GameState.GAME_OVER.ordinal();

        if (currOrd < lastOrd) {
            state = state.next(i);
            return true;
        }
        return false;
    }


    public Boolean evolveTo(GameState toState, int i){
        if (!canEvolve(i))
            return false;

        int toOrd = toState.ordinal();
        int currOrd = state.ordinal();

        if (toOrd>currOrd) {
            state = toState;
            return true;
        }
        return false;
    }


}
