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.
21 lines
452 B
21 lines
452 B
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import java.util.List;
|
|
|
|
public class StateAlive implements State {
|
|
|
|
@Override
|
|
public State nextBy(List<State> neigborStates) {
|
|
long alifeNeigbors = countAliveNeighbors(neigborStates);
|
|
if(alifeNeigbors >1) {
|
|
return this;
|
|
} else {
|
|
return new StateDead();
|
|
}
|
|
}
|
|
|
|
private long countAliveNeighbors(List<State> neigborStates) {
|
|
return neigborStates.stream().filter(state -> this == state).count();
|
|
}
|
|
|
|
}
|