Skip to content
Snippets Groups Projects
Select Git revision
  • b00e7660da24e0b1ec0144aa0b472d6f1bd240cb
  • main default protected
  • variant
3 results

Cloud.class

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GameOfLifeState.java 882 B
    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(Color.RED),
        DEAD(Color.WHITE);
    
        public final Color color;
    
        GameOfLifeState(Color color) {
            this.color = color;
        }
    
        @Override
        public Color getColor() {
            return this.color;
        }
    
        @Override
        public GameOfLifeState next() {
            return GameOfLifeState.values()[1 - this.ordinal()];
        }
    
        @Override
        public GameOfLifeState update(List<GameOfLifeState> neighbours) {
            int countAlive = State.count(ALIVE, neighbours);
            return (countAlive == 3 || this == ALIVE && countAlive == 2)?
                     ALIVE:
                     DEAD;
        }
    
    }