Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • ImprovedMouseInteraction
  • correction_video
  • going_further
  • main
  • ModifGUI
  • final2023
  • template
7 results

Target

Select target project
  • s20026898/tp-6
  • boukenze.b/jeu-de-la-vie-tp-3
  • b22015696/game-of-life-template
  • s23026062/sahin-game-of-life-template
  • m22023183/game-of-life-MALEK
  • z23012739/game-of-life-template
  • p23021107/poussardin-malo-game-of-life-template
  • o21225801/game-of-life-template
  • alaboure/game-fo-life-template
  • t22007439/game-of-life-toullec
  • b23021750/game-of-life
  • c22029830/game-of-life-template-rafi
  • b23025683/game-of-life-template-tp-6
  • gnaves/game-of-life-template
  • a22025223/game-of-life-template-cristel
  • f22024692/game-of-life-template-paolo-mathis-erwan
  • t21233923/game-fo-life-template
  • h21231335/game-fo-life-template
  • l22023519/game-of-life-template-salma
  • p23020787/game-of-life-template
  • b21232450/game-of-life-template
  • s22031458/game-of-life
  • n21223697/tp-4-ngom
  • a22027291/game-of-life-of-salim
  • k22029508/tp-4
  • s19033421/game-of-life-template
  • b21229750/jeu-de-la-vie-tp-3
  • saddem.r/game-of-life-template
  • l3_s3_infoamu/s3/programmation-2/game-fo-life-template
29 results
Select Git revision
  • ImprovedMouseInteraction
  • correction_video
  • going_further
  • main
  • ModifGUI
  • final2023
  • template
7 results
Show changes
Commits on Source (5)
Showing with 122 additions and 76 deletions
...@@ -19,5 +19,5 @@ jeu de la vie. ...@@ -19,5 +19,5 @@ jeu de la vie.
## Membre du projet ## Membre du projet
- NOM, prénom, du participant - Balme,Maxence
...@@ -2,15 +2,15 @@ package matrix; ...@@ -2,15 +2,15 @@ package matrix;
public class ConstantMatrixInitializer<T> implements MatrixInitializer<T> { public class ConstantMatrixInitializer<T> implements MatrixInitializer<T> {
// TODO: add instance variables private T constant ;
public ConstantMatrixInitializer(T constant) { public ConstantMatrixInitializer(T constant) {
// TODO this.constant = constant;
} }
@Override @Override
public T initialValueAt(Coordinate coordinate) { public T initialValueAt(Coordinate coordinate) {
// TODO
return null; return constant;
} }
} }
...@@ -15,8 +15,7 @@ public record Coordinate(int x, int y) { ...@@ -15,8 +15,7 @@ public record Coordinate(int x, int y) {
* @return A new {@link Coordinate} instance. * @return A new {@link Coordinate} instance.
*/ */
public static Coordinate of(int x, int y) { public static Coordinate of(int x, int y) {
// TODO: compléter ce fabriquant return new Coordinate(x,y);
return null;
} }
/** /**
...@@ -25,8 +24,7 @@ public record Coordinate(int x, int y) { ...@@ -25,8 +24,7 @@ public record Coordinate(int x, int y) {
* @return The left adjacent {@link Coordinate}. * @return The left adjacent {@link Coordinate}.
*/ */
public Coordinate left() { public Coordinate left() {
// TODO: à compléter return new Coordinate(x-1,y);
return null;
} }
/** /**
...@@ -35,8 +33,7 @@ public record Coordinate(int x, int y) { ...@@ -35,8 +33,7 @@ public record Coordinate(int x, int y) {
* @return The right adjacent {@link Coordinate}. * @return The right adjacent {@link Coordinate}.
*/ */
public Coordinate right() { public Coordinate right() {
// TODO: à compléter return new Coordinate(x+1,y);
return null;
} }
/** /**
...@@ -45,8 +42,7 @@ public record Coordinate(int x, int y) { ...@@ -45,8 +42,7 @@ public record Coordinate(int x, int y) {
* @return The above adjacent {@link Coordinate}. * @return The above adjacent {@link Coordinate}.
*/ */
public Coordinate above() { public Coordinate above() {
// TODO: à compléter return new Coordinate(x,y+1);
return null;
} }
/** /**
...@@ -55,8 +51,7 @@ public record Coordinate(int x, int y) { ...@@ -55,8 +51,7 @@ public record Coordinate(int x, int y) {
* @return The below adjacent {@link Coordinate}. * @return The below adjacent {@link Coordinate}.
*/ */
public Coordinate below() { public Coordinate below() {
// TODO: à compléter return new Coordinate(x,y-1);
return null;
} }
/** /**
...@@ -73,8 +68,7 @@ public record Coordinate(int x, int y) { ...@@ -73,8 +68,7 @@ public record Coordinate(int x, int y) {
* @return A list of orthogonal neighboring {@link Coordinate}s. * @return A list of orthogonal neighboring {@link Coordinate}s.
*/ */
public List<Coordinate> orthogonalNeighbours() { public List<Coordinate> orthogonalNeighbours() {
// TODO: à compléter return List.of(above(),right(),left(),below());
return List.of();
} }
/** /**
...@@ -92,8 +86,7 @@ public record Coordinate(int x, int y) { ...@@ -92,8 +86,7 @@ public record Coordinate(int x, int y) {
* @return A list of diagonal neighboring {@link Coordinate}s. * @return A list of diagonal neighboring {@link Coordinate}s.
*/ */
public List<Coordinate> diagonalNeighbours() { public List<Coordinate> diagonalNeighbours() {
// TODO: à compléter return List.of(new Coordinate(x-1,y-1),new Coordinate(x-1,y+1),new Coordinate(x+1,y-1),new Coordinate(x+1,y+1));
return List.of();
} }
/** /**
...@@ -111,8 +104,7 @@ public record Coordinate(int x, int y) { ...@@ -111,8 +104,7 @@ public record Coordinate(int x, int y) {
* @return A list of all neighboring {@link Coordinate}s. * @return A list of all neighboring {@link Coordinate}s.
*/ */
public List<Coordinate> orthodiagonalNeighbours() { public List<Coordinate> orthodiagonalNeighbours() {
// TODO: à compléter return List.of(above(),right(),left(),below(),new Coordinate(x-1,y-1),new Coordinate(x-1,y+1),new Coordinate(x+1,y-1),new Coordinate(x+1,y+1));
return List.of();
} }
@Override @Override
......
...@@ -8,6 +8,9 @@ import java.util.NoSuchElementException; ...@@ -8,6 +8,9 @@ import java.util.NoSuchElementException;
* height range. * height range.
*/ */
class CoordinateIterator implements Iterator<Coordinate> { class CoordinateIterator implements Iterator<Coordinate> {
private final int width;
private final int height;
private Coordinate current = new Coordinate(0, 0);
/** /**
* Creates a new {@link CoordinateIterator} with the specified width and height. * Creates a new {@link CoordinateIterator} with the specified width and height.
...@@ -16,7 +19,8 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -16,7 +19,8 @@ class CoordinateIterator implements Iterator<Coordinate> {
* @param height The height of the coordinate range. * @param height The height of the coordinate range.
*/ */
public CoordinateIterator(int width, int height) { public CoordinateIterator(int width, int height) {
// TODO: à compléter this.width = width;
this.height = height;
} }
/** /**
...@@ -26,8 +30,7 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -26,8 +30,7 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public boolean hasNext() { public boolean hasNext() {
// TODO: à compléter return current.y() < height;
return false;
} }
/** /**
...@@ -38,7 +41,11 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -38,7 +41,11 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public Coordinate next() { public Coordinate next() {
// TODO: à compléter if (!hasNext()) throw new NoSuchElementException();
return null; Coordinate next = current;
current = current.right();
if (current.x() == width) current = new Coordinate(0, current.y() + 1);
return next;
} }
} }
\ No newline at end of file
package matrix; package matrix;
import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -23,10 +24,9 @@ public class ListMatrix<T> implements Matrix<T> { ...@@ -23,10 +24,9 @@ public class ListMatrix<T> implements Matrix<T> {
* @param initializer A matrix initializer to set values in the {@link ListMatrix}. * @param initializer A matrix initializer to set values in the {@link ListMatrix}.
*/ */
public ListMatrix(int width, int height, MatrixInitializer<T> initializer) { public ListMatrix(int width, int height, MatrixInitializer<T> initializer) {
// TODO this.width = width;
this.width = 0; this.height = height;
this.height = 0; this.matrix = new ArrayList<>(width);
this.matrix = null;
this.initializeWith(initializer); // fills the matrix using initializer this.initializeWith(initializer); // fills the matrix using initializer
} }
...@@ -35,29 +35,36 @@ public class ListMatrix<T> implements Matrix<T> { ...@@ -35,29 +35,36 @@ public class ListMatrix<T> implements Matrix<T> {
} }
private void initializeWith(MatrixInitializer<T> initializer) { private void initializeWith(MatrixInitializer<T> initializer) {
// TODO initialize each cell of the matrix, with a value determined by initializer for (int x=0; x<width; x++) {
List<T> column = new ArrayList<>(height);
for (int y = 0; y < height; y++) {
column.add(initializer.initialValueAt(new Coordinate(x, y)));
}
matrix.add(column);
}
} }
public int width() { public int width() {
// TODO return width;
return 0;
} }
public int height() { public int height() {
// TODO return height;
return 0;
} }
@Override @Override
public T get(int x, int y) { public T get(int x, int y) {
// TODO
return null; return matrix.get(x).get(y);
} }
@Override @Override
public void set(int x, int y, T newValue) { public void set(int x, int y, T newValue) {
// TODO matrix.get(x).set(y,newValue);
} }
} }
...@@ -58,7 +58,7 @@ public interface Matrix<T> extends Iterable<T> { ...@@ -58,7 +58,7 @@ public interface Matrix<T> extends Iterable<T> {
} }
default Matrix<T> subMatrix(Coordinate corner, int width, int height){ default Matrix<T> subMatrix(Coordinate corner, int width, int height){
return null ; return new ListMatrix<>(width(), height(), new SubMatrixInitializer<>(this.corner));
} }
......
package matrix;
public class SubMatrixInitializer <T> implements MatrixInitializer<T> {
private final Matrix <T> matrix;
private final Coordinate corner ;
public SubMatrixInitializer(Matrix<T> matrix, Coordinate corner) {
this.matrix = matrix;
this.corner = corner;
}
@Override
public T initalValueAt(Coordinate coordinate) {
return matrix.get(coordinate.plus(corner));
}
}
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
*/ */
public class Cell<T> implements Lens<T> { public class Cell<T> implements Lens<T> {
//TODO: ajouter la ou les propriétés nécessaires private T content;
// la liste des objets écoutant les modifications du contenu de la cellule // la liste des objets écoutant les modifications du contenu de la cellule
private final List<OnChangeListener<T>> listeners = new ArrayList<>(); private final List<OnChangeListener<T>> listeners = new ArrayList<>();
...@@ -21,7 +21,7 @@ public class Cell<T> implements Lens<T> { ...@@ -21,7 +21,7 @@ public class Cell<T> implements Lens<T> {
* @param initialContent the value initially stored by the cell. * @param initialContent the value initially stored by the cell.
*/ */
public Cell(T initialContent) { public Cell(T initialContent) {
//TODO: à compléter this.content = initialContent;
} }
/** Add a {@link OnChangeListener} to react to any change of value in the cell. /** Add a {@link OnChangeListener} to react to any change of value in the cell.
...@@ -40,8 +40,13 @@ public class Cell<T> implements Lens<T> { ...@@ -40,8 +40,13 @@ public class Cell<T> implements Lens<T> {
* @param value the new content of this {@link Cell} * @param value the new content of this {@link Cell}
*/ */
public void set(T value) { public void set(T value) {
//TODO: modifier le contenu de la cellule, puis appeler les méthodes valueChanged des T oldValue = this.content;
// listeners this.content = value;
for (OnChangeListener L :listeners) {
L.valueChanged(initialContent,value);
initialContent = value ;
}
} }
/** /**
...@@ -50,7 +55,6 @@ public class Cell<T> implements Lens<T> { ...@@ -50,7 +55,6 @@ public class Cell<T> implements Lens<T> {
* @return the current content of this {@link Cell} * @return the current content of this {@link Cell}
*/ */
public T get(){ public T get(){
//TODO: à compléter return this.content;
return null;
} }
} }
...@@ -11,7 +11,7 @@ import matrix.MatrixInitializer; ...@@ -11,7 +11,7 @@ import matrix.MatrixInitializer;
* @param <T> the type of content of each cell * @param <T> the type of content of each cell
*/ */
public class ConstantCellInitializer<T> implements MatrixInitializer<Cell<T>> { public class ConstantCellInitializer<T> implements MatrixInitializer<Cell<T>> {
//TODO: ajouter la/les propriétes nécessaires private T defaultValue;
/** Make a new {@link MatrixInitializer} with cells containing a {@link Cell} with the same /** Make a new {@link MatrixInitializer} with cells containing a {@link Cell} with the same
* value. * value.
...@@ -19,12 +19,12 @@ public class ConstantCellInitializer<T> implements MatrixInitializer<Cell<T>> { ...@@ -19,12 +19,12 @@ public class ConstantCellInitializer<T> implements MatrixInitializer<Cell<T>> {
* @param defaultValue the value stored in each cell. * @param defaultValue the value stored in each cell.
*/ */
public ConstantCellInitializer(T defaultValue) { public ConstantCellInitializer(T defaultValue) {
//TODO: à compléter this.defaultValue = defaultValue;
} }
@Override @Override
public Cell<T> initialValueAt(Coordinate coordinate) { public Cell<T> initialValueAt(Coordinate coordinate) {
//TODO: à compléter
return null; return new Cell<>(defaultValue);
} }
} }
...@@ -5,6 +5,9 @@ import matrix.MatrixInitializer; ...@@ -5,6 +5,9 @@ import matrix.MatrixInitializer;
import matrix.ListMatrix; import matrix.ListMatrix;
import controller.Simulation; import controller.Simulation;
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 * An initializer for a {@link ListMatrix} of states, where each state is computed based on the value
* of its neighbours in a {@link Simulation} of a cellular automaton. * of its neighbours in a {@link Simulation} of a cellular automaton.
...@@ -12,8 +15,7 @@ import controller.Simulation; ...@@ -12,8 +15,7 @@ import controller.Simulation;
* @param <S> the type of states in the simulation. * @param <S> the type of states in the simulation.
*/ */
public class NextGenerationInitializer<S extends State<S>> implements MatrixInitializer<S> { public class NextGenerationInitializer<S extends State<S>> implements MatrixInitializer<S> {
private final CellularAutomatonSimulation<S> simulation;
//TODO: ajouter les propriétés nécessaires
/** Create a {@link MatrixInitializer} to compute the next generation in /** Create a {@link MatrixInitializer} to compute the next generation in
* a 2D cellular automaton. * a 2D cellular automaton.
...@@ -21,14 +23,19 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit ...@@ -21,14 +23,19 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @param simulation the {@link Simulation} representing the cellular automaton. * @param simulation the {@link Simulation} representing the cellular automaton.
*/ */
public NextGenerationInitializer(CellularAutomatonSimulation<S> simulation) { public NextGenerationInitializer(CellularAutomatonSimulation<S> simulation) {
//TODO: à compléter this.simulation = simulation;
} }
@Override @Override
public S initialValueAt(Coordinate coordinate) { public S initialValueAt(Coordinate coordinate) {
//TODO: à compléter List <Coordinate> coordinates = coordinate.orthogonalNeighbours();
return null; List<S> states = new ArrayList<>();
for (Coordinate coor : coordinates) {
states.add(simulation.at(this.wrap(coordinate)).get());
} }
return simulation.at(coordinate).get().update(states);
}
/** Computes the grid {@link Coordinate} for an arbitrary {@link Coordinate}, even outside /** Computes the grid {@link Coordinate} for an arbitrary {@link Coordinate}, even outside
* the grid. This is done by considering that the grid wraps over its edges, connecting the left side to the right * the grid. This is done by considering that the grid wraps over its edges, connecting the left side to the right
...@@ -39,10 +46,9 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit ...@@ -39,10 +46,9 @@ public class NextGenerationInitializer<S extends State<S>> implements MatrixInit
* @return a corresponding {@link Coordinate}, that is inside the grid. * @return a corresponding {@link Coordinate}, that is inside the grid.
*/ */
Coordinate wrap(Coordinate coordinate) { Coordinate wrap(Coordinate coordinate) {
//TODO: à compléter
//Il faut recalculer les coordonnées x et y modulo les dimensions de la grille. //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. //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. /** The non-negative remainder of n divided by d.
......
...@@ -25,8 +25,6 @@ public interface State<S> { ...@@ -25,8 +25,6 @@ public interface State<S> {
* *
* @return The next state. * @return The next state.
*/ */
S next();
/** /**
* Updates the state based on the states of its neighboring cells. * Updates the state based on the states of its neighboring cells.
* *
...@@ -44,7 +42,10 @@ public interface State<S> { ...@@ -44,7 +42,10 @@ public interface State<S> {
* @return The number of times the specified state appears in the list of neighbors. * @return The number of times the specified state appears in the list of neighbors.
*/ */
static <T> int count(T state, List<T> neighbours) { static <T> int count(T state, List<T> neighbours) {
//TODO: à compléter int nb = 0;
return 0; for (T n : neighbours){
if (n.equals(state)) nb++ ;
}
return nb;
} }
} }
\ No newline at end of file
...@@ -5,32 +5,31 @@ import model.CellularAutomaton; ...@@ -5,32 +5,31 @@ import model.CellularAutomaton;
import java.util.Random; import java.util.Random;
public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> { public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> {
private final int numberOfColumns;
private final int numberOfRows;
public GameOfLifeAutomaton(int numberOfColumns, int numberOfRows) { public GameOfLifeAutomaton(int numberOfColumns, int numberOfRows) {
//TODO: à compléter this.numberOfColumns = numberOfColumns;
this.numberOfRows = numberOfRows ;
} }
@Override @Override
public int numberOfColumns() { public int numberOfColumns() {
//TODO: à compléter return numberOfColumns;
return 0;
} }
@Override @Override
public int numberOfRows() { public int numberOfRows() {
//TODO: à compléter return numberOfRows;
return 0;
} }
@Override @Override
public GameOfLifeState defaultState() { public GameOfLifeState defaultState() {
//TODO: à compléter return GameOfLifeState.DEAD;
return null;
} }
@Override @Override
public GameOfLifeState randomState(Random generator) { public GameOfLifeState randomState(Random generator) {
//TODO: à compléter return generator.nextBoolean() ? GameOfLifeState.ALIVE : GameOfLifeState.DEAD;
return null;
} }
} }
...@@ -14,20 +14,32 @@ public enum GameOfLifeState implements State<GameOfLifeState> { ...@@ -14,20 +14,32 @@ public enum GameOfLifeState implements State<GameOfLifeState> {
@Override @Override
public Color getColor() { public Color getColor() {
//TODO: à compléter switch(this) {
case ALIVE:
return Color.RED;
case DEAD:
return Color.WHITE;
}
return Color.BLACK; return Color.BLACK;
} }
@Override @Override
public GameOfLifeState next() { public GameOfLifeState next() {
//TODO: à compléter if (this == GameOfLifeState.ALIVE) {
return null; return GameOfLifeState.DEAD;
}
else if (this == GameOfLifeState.DEAD) {
return GameOfLifeState.ALIVE;
}
} }
@Override @Override
public GameOfLifeState update(List<GameOfLifeState> neighbours) { public GameOfLifeState update(List<GameOfLifeState> neighbours) {
//TODO: à compléter int count = State.count(ALIVE, neighbours);
return null; if (count == 3) return ALIVE ;
if ((count == 2) && this.equals(ALIVE))return ALIVE ;
return DEAD ;
} }
} }