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

avancée

parent 6a93814e
Branches
No related tags found
No related merge requests found
Pipeline #40917 failed
......@@ -25,8 +25,6 @@ public interface State<S> {
*
* @return The next state.
*/
S next();
/**
* Updates the state based on the states of its neighboring cells.
*
......@@ -44,7 +42,10 @@ public interface State<S> {
* @return The number of times the specified state appears in the list of neighbors.
*/
static <T> int count(T state, List<T> neighbours) {
//TODO: à compléter
return 0;
int nb = 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> {
@Override
public GameOfLifeState defaultState() {
//TODO: à compléter
return null;
return GameOfLifeState.DEAD;
}
@Override
......
......@@ -14,20 +14,40 @@ public enum GameOfLifeState implements State<GameOfLifeState> {
@Override
public Color getColor() {
//TODO: à compléter
switch(this) {
case ALIVE:
return Color.RED;
case DEAD:
return Color.WHITE;
}
return Color.BLACK;
}
@Override
public GameOfLifeState next() {
//TODO: à compléter
return null;
if (this == GameOfLifeState.ALIVE) {
return GameOfLifeState.DEAD;
}
else if (this == GameOfLifeState.DEAD) {
return GameOfLifeState.ALIVE;
}
}
@Override
public GameOfLifeState update(List<GameOfLifeState> neighbours) {
//TODO: à compléter
return null;
int count = State.count(ALIVE, neighbours);
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