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> { ...@@ -37,7 +37,7 @@ public interface Simulation extends Iterable<Coordinate> {
* *
* @param coordinate The {@link Coordinate} to advance to the next state. * @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}. * Copies the state from the source {@link Coordinate} to the destination {@link Coordinate}.
......
...@@ -42,14 +42,12 @@ public class CellularAutomatonSimulation<S extends State<S>> ...@@ -42,14 +42,12 @@ public class CellularAutomatonSimulation<S extends State<S>>
@Override @Override
public int numberOfColumns() { public int numberOfColumns() {
//TODO: à compléter return this.automaton.numberOfColumns();
return 0;
} }
@Override @Override
public int numberOfRows() { public int numberOfRows() {
//TODO: à compléter return this.automaton.numberOfRows();
return 0;
} }
/** /**
...@@ -59,13 +57,18 @@ public class CellularAutomatonSimulation<S extends State<S>> ...@@ -59,13 +57,18 @@ public class CellularAutomatonSimulation<S extends State<S>>
* @return The cell at the specified coordinate. * @return The cell at the specified coordinate.
*/ */
public Cell<S> at(Coordinate coordinate) { public Cell<S> at(Coordinate coordinate) {
//TODO: à compléter return this.grid.get(coordinate);
return null;
} }
@Override @Override
public void updateToNextGeneration() { 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 /** Computes the {@link Matrix} of states obtained after a single step of updates
...@@ -74,23 +77,28 @@ public class CellularAutomatonSimulation<S extends State<S>> ...@@ -74,23 +77,28 @@ public class CellularAutomatonSimulation<S extends State<S>>
* @return the states of each cell after one generation * @return the states of each cell after one generation
*/ */
private Matrix<S> nextGenerationMatrix() { private Matrix<S> nextGenerationMatrix() {
//TODO: à compléter return new Matrix<>(
return null; this.numberOfColumns(),
this.numberOfRows(),
new NextGenerationInitializer<>(this)
);
} }
@Override @Override
public void next(Coordinate coordinate) { public void cycleThrough(Coordinate coordinate) {
//TODO: à compléter Cell<S> cell = this.at(coordinate);
S newState = cell.get().cycle();
cell.set(newState);
} }
@Override @Override
public void copy(Coordinate source, Coordinate destination) { public void copy(Coordinate source, Coordinate destination) {
//TODO: à compléter S state = this.at(source).get();
this.at(destination).set(state);
} }
@Override @Override
public Color getColor(Coordinate coordinate) { public Color getColor(Coordinate coordinate) {
//TODO: à compléter return this.at(coordinate).get().getColor();
return null;
} }
@Override @Override
...@@ -108,13 +116,19 @@ public class CellularAutomatonSimulation<S extends State<S>> ...@@ -108,13 +116,19 @@ public class CellularAutomatonSimulation<S extends State<S>>
@Override @Override
public void clear() { 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 @Override
public void reset() { 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 @Override
......
...@@ -29,7 +29,7 @@ public class FillingMouseListener implements MouseListener { ...@@ -29,7 +29,7 @@ public class FillingMouseListener implements MouseListener {
@Override @Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) { public void onMousePressed(MouseEvent event, Coordinate coordinate) {
this.matrix.getController().getSimulation().next(coordinate); this.matrix.getController().getSimulation().cycleThrough(coordinate);
this.matrix.setMouseListener( this.matrix.setMouseListener(
new FillingMouseListener(this.matrix, coordinate) new FillingMouseListener(this.matrix, coordinate)
); );
......
...@@ -14,7 +14,7 @@ class WaitingMouseListener implements MouseListener { ...@@ -14,7 +14,7 @@ class WaitingMouseListener implements MouseListener {
@Override @Override
public void onMousePressed(MouseEvent event, Coordinate coordinate) { 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)); this.matrix.setMouseListener(new FillingMouseListener(this.matrix, coordinate));
} }
......
...@@ -78,7 +78,7 @@ class CellularAutomatonSimulationTest { ...@@ -78,7 +78,7 @@ class CellularAutomatonSimulationTest {
Coordinate coordinate = Coordinate.of(1, 1); Coordinate coordinate = Coordinate.of(1, 1);
Cell<GameOfLifeState> cell = simulation.at(coordinate); Cell<GameOfLifeState> cell = simulation.at(coordinate);
GameOfLifeState oldState = cell.get(); GameOfLifeState oldState = cell.get();
simulation.next(coordinate); simulation.cycleThrough(coordinate);
assertNotEquals(oldState, cell.get()); 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