package model.automata;

import javafx.scene.paint.Color;
import model.State;

import java.util.List;

/**
 * {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}.
 */
public enum GameOfLifeState implements State<GameOfLifeState> {
    ALIVE, DEAD;


    @Override
    public Color getColor() {
        switch(this) {
            case ALIVE:
                return Color.RED;
            case DEAD:
                return Color.WHITE;
        }
        return Color.BLACK;
    }

    @Override
    public GameOfLifeState next() {
        if (this == GameOfLifeState.ALIVE) {
            return GameOfLifeState.DEAD;
        }
        else if (this == GameOfLifeState.DEAD) {
            return GameOfLifeState.ALIVE;
        }

    }

    @Override
    public GameOfLifeState update(List<GameOfLifeState> neighbours) {
        int count = State.count(ALIVE, neighbours);
        if (count == 3) return ALIVE ;
        if ((count == 2) && this.equals(ALIVE))return ALIVE ;
        return DEAD ;
    }

}