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

FirefighterManager.java

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 1.08 KiB
    package model.automata;
    
    import javafx.scene.paint.Color;
    import model.State;
    
    import java.util.List;
    import java.util.Random;
    
    /**
     * {@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<State<GameOfLifeState>> neighbours) {
            int countAlive = 0;
            for (State<GameOfLifeState> state : neighbours) {
                if (state.equals(ALIVE)) {
                    countAlive++;
                }
            }
            boolean isAlive =
                    (this == DEAD && 3 == countAlive)
                    || (this == ALIVE && 2 <= countAlive && countAlive <= 3);
            return isAlive ? ALIVE : DEAD;
        }
    
    }