Skip to content
Snippets Groups Projects
Select Git revision
  • 53447461a52debf7ff91d80f0fa222d88a321126
  • 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.
    NextGenerationInitializer.java 758 B
    package model;
    
    import datastruct.Coordinate;
    import datastruct.MatrixInitializer;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class NextGenerationInitializer<S extends State<S>> implements MatrixInitializer<S> {
    
        private final CellGrid<S> grid;
    
        public NextGenerationInitializer(CellGrid<S> grid) {
            this.grid = grid;
        }
    
        @Override
        public S initialValueAt(Coordinate coordinate) {
            List<State<S>> neighbours = new ArrayList<>();
            for (Coordinate neighbourCoord : coordinate.orthodiagonalNeighbours()) {
                neighbours.add(this.grid.cellAtWrapped(neighbourCoord).getState());
            }
            S state = this.grid.cellAt(coordinate).getState();
            return state.update(neighbours);
        }
    }