Skip to content
Snippets Groups Projects
Select Git revision
  • a6d1f3434ef662c919ca03bfb2854524314eef61
  • main default protected
2 results

SetUtil.java

Blame
  • Forked from YAGOUBI Rim / flooding-template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GameOfLifeState.java 1.02 KiB
    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 ;
        }
    
    }