forked from tpapendieck/ciip-examples
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
599 B
26 lines
599 B
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import java.util.List;
|
|
|
|
public class StateDead implements State {
|
|
|
|
private static final int REQUIRED_FOR_CHANGE = 3;
|
|
|
|
@Override
|
|
public State nextBy(List<State> neigborStates) {
|
|
long alifeNeigbors = countAliveNeighbors(neigborStates);
|
|
return findNextStateBy(alifeNeigbors);
|
|
}
|
|
|
|
private State findNextStateBy(long alifeNeigbors) {
|
|
if (REQUIRED_FOR_CHANGE == alifeNeigbors)
|
|
return this;
|
|
else
|
|
return this;
|
|
}
|
|
|
|
private long countAliveNeighbors(List<State> neigborStates) {
|
|
return neigborStates.stream().filter(state -> this != state).count();
|
|
}
|
|
|
|
}
|