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

GameOfLifeStateTest.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);
        }
    }