Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Generation evolve() {
- Set<Cell> newGeneration = new HashSet<Cell>();
- allCandidateToBeAliveInTheNextGeneration().forEach((Cell candidate) -> {
- int aliveNeighbors = candidate.neighbors().count((Cell c) -> isAlive(c));
- State candidateStateInNewGeneration = rules.nextState(state(candidate), aliveNeighbors);
- if (candidateStateInNewGeneration == State.ALIVE) {
- newGeneration.add(candidate);
- }
- });
- return new Generation(newGeneration);
- }
- private Zone allCandidateToBeAliveInTheNextGeneration() {
- Zone toCalculate = aliveCells
- .stream()
- .map((alive) -> alive.block())
- .reduce(
- Zone.empty(),
- (Zone z1, Zone z2) -> z1.union(z2)
- );
- return toCalculate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement