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

TP

parent deacc664
Branches
No related tags found
No related merge requests found
Pipeline #45494 passed
...@@ -5,7 +5,6 @@ import model.CellularAutomaton; ...@@ -5,7 +5,6 @@ import model.CellularAutomaton;
import java.util.Random; import java.util.Random;
public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> { public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> {
private final int numberOfColumns; private final int numberOfColumns;
private final int numberOfRows; private final int numberOfRows;
......
...@@ -4,7 +4,6 @@ import javafx.scene.paint.Color; ...@@ -4,7 +4,6 @@ import javafx.scene.paint.Color;
import model.State; import model.State;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}. * {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}.
...@@ -12,6 +11,7 @@ import java.util.Random; ...@@ -12,6 +11,7 @@ import java.util.Random;
public enum GameOfLifeState implements State<GameOfLifeState> { public enum GameOfLifeState implements State<GameOfLifeState> {
ALIVE, DEAD; ALIVE, DEAD;
@Override @Override
public Color getColor() { public Color getColor() {
return this == ALIVE ? Color.RED : Color.WHITE; return this == ALIVE ? Color.RED : Color.WHITE;
...@@ -23,16 +23,14 @@ public enum GameOfLifeState implements State<GameOfLifeState> { ...@@ -23,16 +23,14 @@ public enum GameOfLifeState implements State<GameOfLifeState> {
} }
@Override @Override
public GameOfLifeState update(List<GameOfLifeState> neighbors) { public GameOfLifeState update(List<GameOfLifeState> neighbours) {
int aliveCount = State.count(ALIVE, neighbors); int aliveNeighbors = State.count(ALIVE, neighbours);
if (this == ALIVE){ if (this == ALIVE){
return (aliveCount == 2 || aliveCount == 3) ? ALIVE : DEAD; return (aliveNeighbors == 2 || aliveNeighbors == 3) ? ALIVE : DEAD;
} else { } 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