Skip to content
Snippets Groups Projects
Commit 982f8a82 authored by Guyslain's avatar Guyslain
Browse files

section 8 finie testée

parent da01de06
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ public interface Simulation extends Iterable<Coordinate> {
*
* @param coordinate The {@link Coordinate} to advance to the next state.
*/
void next(Coordinate coordinate);
void cycleThrough(Coordinate coordinate);
/**
* Copies the state from the source {@link Coordinate} to the destination {@link Coordinate}.
......
......@@ -42,14 +42,12 @@ public class CellularAutomatonSimulation<S extends State<S>>
@Override
public int numberOfColumns() {
//TODO: à compléter
return 0;
return this.automaton.numberOfColumns();
}
@Override
public int numberOfRows() {
//TODO: à compléter
return 0;
return this.automaton.numberOfRows();
}
/**
......@@ -59,13 +57,18 @@ public class CellularAutomatonSimulation<S extends State<S>>
* @return The cell at the specified coordinate.
*/
public Cell<S> at(Coordinate coordinate) {
//TODO: à compléter
return null;
return this.grid.get(coordinate);
}
@Override
public void updateToNextGeneration() {
//TODO: à compléter, en utilisant nextGenerationMatrix()
Matrix<S> newStates = nextGenerationMatrix();
for (Coordinate coordinate : this) {
S newState = newStates.at(coordinate).get();
Cell<S> cell = this.at(coordinate);
cell.set(newState);
}
this.generationNumber.set(this.generationNumber.get() + 1);
}
/** Computes the {@link Matrix} of states obtained after a single step of updates
......@@ -74,23 +77,28 @@ public class CellularAutomatonSimulation<S extends State<S>>
* @return the states of each cell after one generation
*/
private Matrix<S> nextGenerationMatrix() {
//TODO: à compléter
return null;
return new Matrix<>(
this.numberOfColumns(),
this.numberOfRows(),
new NextGenerationInitializer<>(this)
);
}
@Override
public void next(Coordinate coordinate) {
//TODO: à compléter
public void cycleThrough(Coordinate coordinate) {
Cell<S> cell = this.at(coordinate);
S newState = cell.get().cycle();
cell.set(newState);
}
@Override
public void copy(Coordinate source, Coordinate destination) {
//TODO: à compléter
S state = this.at(source).get();
this.at(destination).set(state);
}
@Override
public Color getColor(Coordinate coordinate) {
//TODO: à compléter
return null;
return this.at(coordinate).get().getColor();
}
@Override
......@@ -108,13 +116,19 @@ public class CellularAutomatonSimulation<S extends State<S>>
@Override
public void clear() {
//TODO: à compléter (penser à remettre le nombre de génération à 0)
for (Coordinate coordinate : this) {
this.at(coordinate).set(this.automaton.defaultState());
}
this.generationNumber.set(0);
}
@Override
public void reset() {
//TODO: à compléter (penser à remettre le nombre de génération à 0)
for (Coordinate coordinate : this) {
this.at(coordinate).set(this.automaton.randomState(this.generator));
}
this.generationNumber.set(0);
}
@Override
......
......@@ -29,7 +29,7 @@ public class FillingMouseListener implements MouseListener {
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate);
this.matrix.getController().getSimulation().cycleThrough(coordinate);
this.matrix.setMouseListener(
new FillingMouseListener(this.matrix, coordinate)
);
......
......@@ -14,7 +14,7 @@ class WaitingMouseListener implements MouseListener {
@Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate);
this.matrix.getController().getSimulation().cycleThrough(coordinate);
this.matrix.setMouseListener(new FillingMouseListener(this.matrix, coordinate));
}
......
......@@ -78,7 +78,7 @@ class CellularAutomatonSimulationTest {
Coordinate coordinate = Coordinate.of(1, 1);
Cell<GameOfLifeState> cell = simulation.at(coordinate);
GameOfLifeState oldState = cell.get();
simulation.next(coordinate);
simulation.cycleThrough(coordinate);
assertNotEquals(oldState, cell.get());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment