Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public Generation evolve() {
  2. Set<Cell> newGeneration = new HashSet<Cell>();
  3. allCandidateToBeAliveInTheNextGeneration().forEach((Cell candidate) -> {
  4. int aliveNeighbors = candidate.neighbors().count((Cell c) -> isAlive(c));
  5. State candidateStateInNewGeneration = rules.nextState(state(candidate), aliveNeighbors);
  6. if (candidateStateInNewGeneration == State.ALIVE) {
  7. newGeneration.add(candidate);
  8. }
  9. });
  10. return new Generation(newGeneration);
  11. }
  12.  
  13. private Zone allCandidateToBeAliveInTheNextGeneration() {
  14. Zone toCalculate = aliveCells
  15. .stream()
  16. .map((alive) -> alive.block())
  17. .reduce(
  18. Zone.empty(),
  19. (Zone z1, Zone z2) -> z1.union(z2)
  20. );
  21. return toCalculate;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement