Skip to content
Snippets Groups Projects
Commit c0e5765e authored by BALME Maxence's avatar BALME Maxence
Browse files

avancée

parent 6a93814e
No related branches found
No related tags found
No related merge requests found
Pipeline #40917 failed
...@@ -25,8 +25,6 @@ public interface State<S> { ...@@ -25,8 +25,6 @@ public interface State<S> {
* *
* @return The next state. * @return The next state.
*/ */
S next();
/** /**
* Updates the state based on the states of its neighboring cells. * Updates the state based on the states of its neighboring cells.
* *
...@@ -44,7 +42,10 @@ public interface State<S> { ...@@ -44,7 +42,10 @@ public interface State<S> {
* @return The number of times the specified state appears in the list of neighbors. * @return The number of times the specified state appears in the list of neighbors.
*/ */
static <T> int count(T state, List<T> neighbours) { static <T> int count(T state, List<T> neighbours) {
//TODO: à compléter int nb = 0;
return 0; for (T n : neighbours){
if (n.equals(state)) nb++ ;
}
return nb;
} }
} }
\ No newline at end of file
...@@ -24,8 +24,7 @@ public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> { ...@@ -24,8 +24,7 @@ public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> {
@Override @Override
public GameOfLifeState defaultState() { public GameOfLifeState defaultState() {
//TODO: à compléter return GameOfLifeState.DEAD;
return null;
} }
@Override @Override
......
...@@ -14,20 +14,40 @@ public enum GameOfLifeState implements State<GameOfLifeState> { ...@@ -14,20 +14,40 @@ public enum GameOfLifeState implements State<GameOfLifeState> {
@Override @Override
public Color getColor() { public Color getColor() {
//TODO: à compléter switch(this) {
case ALIVE:
return Color.RED;
case DEAD:
return Color.WHITE;
}
return Color.BLACK; return Color.BLACK;
} }
@Override @Override
public GameOfLifeState next() { public GameOfLifeState next() {
//TODO: à compléter if (this == GameOfLifeState.ALIVE) {
return null; return GameOfLifeState.DEAD;
}
else if (this == GameOfLifeState.DEAD) {
return GameOfLifeState.ALIVE;
}
} }
@Override @Override
public GameOfLifeState update(List<GameOfLifeState> neighbours) { public GameOfLifeState update(List<GameOfLifeState> neighbours) {
//TODO: à compléter int count = State.count(ALIVE, neighbours);
return null; if this == ALIVE {
if(count == 2 || count == 3) {
return GameOfLifeState.ALIVE;
}
}
else if this == DEAD {
if (count ==3) {
return GameOfLifeState.ALIVE;
}
}
return this.next();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment