Skip to content
Snippets Groups Projects
Commit 42c0645a authored by hiba1907's avatar hiba1907
Browse files

Realisation des derinieres taches du ttp jeu de la vie

parent c695e6fc
No related branches found
No related tags found
No related merge requests found
Pipeline #41726 passed
......@@ -11,20 +11,19 @@ import matrix.MatrixInitializer;
* @param <T> the type of content of each cell
*/
public class ConstantCellInitializer<T> implements MatrixInitializer<Cell<T>> {
//TODO: ajouter la/les propriétes nécessaires
private final T defaultValue;
/** Make a new {@link MatrixInitializer} with cells containing a {@link Cell} with the same
* value.
*
* @param defaultValue the value stored in each cell.
*/
public ConstantCellInitializer(T defaultValue) {
//TODO: à compléter
}
this.defaultValue=defaultValue;
}
@Override
public Cell<T> initialValueAt(Coordinate coordinate) {
//TODO: à compléter
return null;
//retourne la nouvelle cellule avec la valeur constante par def
return new Cell<>(defaultValue);
}
}
package model;
import java.util.ArrayList;
import java.util.List;
import controller.Simulation;
import matrix.Coordinate;
import matrix.MatrixInitializer;
import matrix.ListMatrix;
import controller.Simulation;
import matrix.MatrixInitializer;
/**
* An initializer for a {@link ListMatrix} of states, where each state is computed based on the value
......@@ -13,7 +17,7 @@ import controller.Simulation;
*/
public class NextGenerationInitializer<S extends State<S>> implements MatrixInitializer<S> {
//TODO: ajouter les propriétés nécessaires
private final CellularAutomatonSimulation <S> simulation;
/** Create a {@link MatrixInitializer} to compute the next generation in
* a 2D cellular automaton.
......@@ -21,13 +25,18 @@ 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;
public S initialValueAt(Coordinate coordinate) {
List <Coordinate> neighbours=coordinate.orthodiagonalNeighbours();
List<S> states =new ArrayList<>();
for (Coordinate neighbour:neighbours){
states.add(this.simulation.at(wrap(neighbour)).get());
}
return this.simulation.at(coordinate).get().update(states);
}
/** Computes the grid {@link Coordinate} for an arbitrary {@link Coordinate}, even outside
......@@ -39,10 +48,10 @@ 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(), this.simulation.numberOfColumns()),
modulo(coordinate.y(), this.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