Skip to content
Snippets Groups Projects
Commit dbc06637 authored by SAHIN Melis damla's avatar SAHIN Melis damla
Browse files

TP

parent deacc664
No related branches found
No related tags found
No related merge requests found
Pipeline #45494 passed
......@@ -5,7 +5,6 @@ import model.CellularAutomaton;
import java.util.Random;
public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> {
private final int numberOfColumns;
private final int numberOfRows;
......
......@@ -4,7 +4,6 @@ import javafx.scene.paint.Color;
import model.State;
import java.util.List;
import java.util.Random;
/**
* {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}.
......@@ -12,6 +11,7 @@ import java.util.Random;
public enum GameOfLifeState implements State<GameOfLifeState> {
ALIVE, DEAD;
@Override
public Color getColor() {
return this == ALIVE ? Color.RED : Color.WHITE;
......@@ -23,16 +23,14 @@ public enum GameOfLifeState implements State<GameOfLifeState> {
}
@Override
public GameOfLifeState update(List<GameOfLifeState> neighbors) {
int aliveCount = State.count(ALIVE, neighbors);
public GameOfLifeState update(List<GameOfLifeState> neighbours) {
int aliveNeighbors = State.count(ALIVE, neighbours);
if (this == ALIVE){
return (aliveCount == 2 || aliveCount == 3) ? ALIVE : DEAD;
return (aliveNeighbors == 2 || aliveNeighbors == 3) ? ALIVE : DEAD;
} else {
return (aliveCount == 3) ? ALIVE : DEAD;
}
return aliveNeighbors == 3 ? ALIVE : DEAD;
}
public GameOfLifeState randomState(Random generator) {
return generator.nextBoolean() ? GameOfLifeState.ALIVE : GameOfLifeState.DEAD;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment