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

SimulatorApplication.java

Blame
  • Forked from YAGOUBI Rim / Game of life Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    SeedsState.java 916 B
    package model.states;
    
    import javafx.scene.paint.Color;
    import model.State;
    
    import java.util.List;
    
    import static model.states.BriansBrainState.GENERATOR;
    import static model.states.BriansBrainState.countList;
    
    public enum SeedsState implements State<SeedsState> {
        ON, OFF;
        @Override
        public Color getColor() {
            return switch (this) {
                case ON -> Color.WHITE;
                case OFF -> Color.BLACK;
            };
        }
    
        @Override
        public SeedsState next() {
            return switch (this) {
                case ON -> OFF;
                case OFF -> ON;
            };
        }
    
        @Override
        public SeedsState update(List<State<SeedsState>> neighbours) {
            return switch (this) {
                case ON -> OFF;
                case OFF -> countList(ON,neighbours) == 2 ? ON: OFF;
            };
        }
    
        public static SeedsState random() {
            return GENERATOR.nextInt(10)==0? ON: OFF;
        }
    }