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

classes complete

parent f8bfd13e
Branches
No related tags found
No related merge requests found
......@@ -42,14 +42,12 @@ public class CellularAutomatonSimulation<S extends State<S>>
@Override
public int numberOfColumns() {
//TODO: à compléter
return 0;
return numberOfColumns();
}
@Override
public int numberOfRows() {
//TODO: à compléter
return 0;
return numberOfRows();
}
/**
......@@ -59,7 +57,6 @@ 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;
}
......
......@@ -4,6 +4,10 @@ import matrix.Coordinate;
import matrix.MatrixInitializer;
import matrix.ListMatrix;
import controller.Simulation;
import model.automata.GameOfLifeState;
import java.util.ArrayList;
import java.util.List;
/**
* An initializer for a {@link ListMatrix} of states, where each state is computed based on the value
......@@ -13,7 +17,8 @@ import controller.Simulation;
*/
public class NextGenerationInitializer<S extends State<S>> implements MatrixInitializer<S> {
//TODO: ajouter les propriétés nécessaires
CellularAutomatonSimulation<S> simulation;
/** Create a {@link MatrixInitializer} to compute the next generation in
* a 2D cellular automaton.
......@@ -21,13 +26,17 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @param simulation the {@link Simulation} representing the cellular automaton.
*/
public NextGenerationInitializer(CellularAutomatonSimulation<S> simulation) {
//TODO: à compléter
this.simulation = simulation;
}
@Override
public S initialValueAt(Coordinate coordinate) {
//TODO: à compléter
return null;
List<Coordinate> coordinates = coordinate.orthogonalNeighbours();
List<S> states = new ArrayList<>();
for (Coordinate c : coordinates) {
states.add(simulation.at(this.wrap(c)).get());
}
return simulation.at(coordinate).get().update(states);
}
/** Computes the grid {@link Coordinate} for an arbitrary {@link Coordinate}, even outside
......@@ -39,10 +48,9 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @return a corresponding {@link Coordinate}, that is inside the grid.
*/
Coordinate wrap(Coordinate coordinate) {
//TODO: à compléter
//Il faut recalculer les coordonnées x et y modulo les dimensions de la grille.
//Pour le modulo, utiliser la fonction ci-dessous, qui s'assure que le résultat est positif.
return null;
return new Coordinate(modulo(coordinate.x(), simulation.numberOfColumns()), modulo(coordinate.y(), simulation.numberOfRows()));
}
/** The non-negative remainder of n divided by d.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment