Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
  • correction_video
  • going_further
  • ImprovedMouseInteraction
  • final2023
  • template
  • ModifGUI
7 results

BriansBrainState.java

Blame
  • Forked from YAGOUBI Rim / Game of life Template
    5 commits behind the upstream repository.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    BriansBrainState.java 922 B
    package model.automata;
    
    import javafx.scene.paint.Color;
    import model.State;
    
    import java.util.List;
    
    public enum BriansBrainState implements State<BriansBrainState> {
        ON, OFF, DYING;
    
        @Override
        public Color getColor() {
            return switch (this) {
                case ON -> Color.WHITE;
                case OFF -> Color.BLACK;
                case DYING -> Color.BLUE;
            };
        }
    
        @Override
        public BriansBrainState next() {
            return switch (this) {
                case ON -> DYING;
                case OFF -> ON;
                case DYING -> OFF;
            };
        }
    
        @Override
        public BriansBrainState update(List<BriansBrainState> neighbours) {
            return switch (this) {
                case ON -> DYING;
                case DYING -> OFF;
                case OFF -> {
                    int count = State.count(ON, neighbours);
                    yield count==2 ? ON : OFF;
                }
            };
        }
    
    
    }