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
Showing
with 148 additions and 235 deletions
package model.automata;
import java.util.Random;
public class BiColorAutomaton extends AbstractAutomaton<BiColorState> {
public BiColorAutomaton(int numberOfColumns, int numberOfRows) {
super(numberOfColumns, numberOfRows);
}
@Override
public BiColorState defaultState() {
return BiColorState.DEAD;
}
@Override
public BiColorState randomState(Random generator) {
return generator.nextBoolean()? BiColorState.DEAD:
generator.nextBoolean()? BiColorState.RED:
BiColorState.BLUE;
}
}
package model.automata;
import javafx.scene.paint.Color;
import model.State;
import java.util.List;
public enum BiColorState implements State<BiColorState> {
BLUE, RED, DEAD;
@Override
public Color getColor() {
return switch (this) {
case BLUE -> Color.BLUE;
case RED -> Color.RED;
case DEAD -> Color.WHITE;
};
}
@Override
public BiColorState next() {
return switch (this) {
case BLUE -> RED;
case RED -> DEAD;
case DEAD -> BLUE;
};
}
@Override
public BiColorState update(List<BiColorState> neighbours) {
int countBlue = State.count(BLUE, neighbours);
int countRed = State.count(RED, neighbours);
int countAlive = countBlue + countRed;
if (this == DEAD) {
return (countAlive != 3)? DEAD:
countBlue > countRed? BLUE:
RED;
}
return 2 <= countAlive && countAlive <= 3? this:
DEAD;
}
}
package model.automata;
import java.util.Random;
public class BriansBrainAutomaton extends AbstractAutomaton<BriansBrainState> {
public BriansBrainAutomaton(int numberOfColumns, int numberOfRows) {
super(numberOfColumns, numberOfRows);
}
@Override
public BriansBrainState defaultState() {
return BriansBrainState.OFF;
}
@Override
public BriansBrainState randomState(Random generator) {
return generator.nextInt(10) == 0 ?
BriansBrainState.ON:
BriansBrainState.OFF;
}
}
package model.automata;
import javafx.scene.paint.Color;
import model.State;
import java.util.List;
public enum BriansBrainState implements State<BriansBrainState> {
ON, OFF, DYING;
@Override
public Color getColor() {
return switch (this) {
case ON -> Color.WHITE;
case OFF -> Color.BLACK;
case DYING -> Color.BLUE;
};
}
@Override
public BriansBrainState next() {
return switch (this) {
case ON -> DYING;
case OFF -> ON;
case DYING -> OFF;
};
}
@Override
public BriansBrainState update(List<BriansBrainState> neighbours) {
return switch (this) {
case ON -> DYING;
case DYING -> OFF;
case OFF -> {
int count = State.count(ON, neighbours);
yield count==2 ? ON : OFF;
}
};
}
}
package model.automata;
import model.CellularAutomaton;
import java.util.Random;
public class GameOfLifeAutomaton extends AbstractAutomaton<GameOfLifeState> {
public class GameOfLifeAutomaton implements CellularAutomaton<GameOfLifeState> {
public GameOfLifeAutomaton(int numberOfColumns, int numberOfRows) {
super(numberOfColumns, numberOfRows);
//TODO: à compléter
}
@Override
public int numberOfColumns() {
//TODO: à compléter
return 0;
}
@Override
public int numberOfRows() {
//TODO: à compléter
return 0;
}
@Override
public GameOfLifeState defaultState() {
return GameOfLifeState.DEAD;
//TODO: à compléter
return null;
}
@Override
public GameOfLifeState randomState(Random generator) {
return generator.nextBoolean()?
GameOfLifeState.ALIVE:
GameOfLifeState.DEAD;
//TODO: à compléter
return null;
}
}
......@@ -9,31 +9,25 @@ import java.util.List;
* {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}.
*/
public enum GameOfLifeState implements State<GameOfLifeState> {
ALIVE(Color.RED),
DEAD(Color.WHITE);
ALIVE, DEAD;
public final Color color;
GameOfLifeState(Color color) {
this.color = color;
}
@Override
public Color getColor() {
return this.color;
//TODO: à compléter
return Color.BLACK;
}
@Override
public GameOfLifeState next() {
return GameOfLifeState.values()[1 - this.ordinal()];
//TODO: à compléter
return null;
}
@Override
public GameOfLifeState update(List<GameOfLifeState> neighbours) {
int countAlive = State.count(ALIVE, neighbours);
return (countAlive == 3 || this == ALIVE && countAlive == 2)?
ALIVE:
DEAD;
//TODO: à compléter
return null;
}
}
package model.automata;
import java.util.Random;
public class SeedsAutomaton extends AbstractAutomaton<SeedsState> {
public SeedsAutomaton(int numberOfColumns, int numberOfRows) {
super(numberOfColumns, numberOfRows);
}
@Override
public SeedsState defaultState() {
return SeedsState.OFF;
}
@Override
public SeedsState randomState(Random generator) {
return generator.nextInt(10) == 0?
SeedsState.ON:
SeedsState.OFF;
}
}
package model.automata;
import javafx.scene.paint.Color;
import model.State;
import java.util.List;
public enum SeedsState implements State<SeedsState> {
ON, OFF;
@Override
public Color getColor() {
return switch (this) {
case ON -> Color.GOLD;
case OFF -> Color.BLACK;
};
}
@Override
public SeedsState next() {
return switch (this) {
case ON -> OFF;
case OFF -> ON;
};
}
@Override
public SeedsState update(List<SeedsState> neighbours) {
return switch (this) {
case ON -> OFF;
case OFF -> State.count(ON,neighbours) == 2 ? ON: OFF;
};
}
}
package view;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.input.MouseEvent;
public class FillingMouseListener implements MouseListener {
......
package view;
import controller.Controller;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
......
package view;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.input.MouseEvent;
interface MouseListener {
......
package view;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.input.MouseEvent;
class WaitingMouseListener implements MouseListener {
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......@@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.*;
class ConstantMatrixInitializerTest {
@Test
public void testMatrixInitializationWithConstantValue() {
Matrix<String> matrix = new Matrix<>(3, 3, new ConstantMatrixInitializer<>("X"));
ListMatrix<String> matrix = new ListMatrix<>(3, 3, new ConstantMatrixInitializer<>("X"));
// Test that all cells have the constant value.
for (int x = 0; x < 3; x++) {
......@@ -19,7 +19,7 @@ class ConstantMatrixInitializerTest {
@Test
public void testMatrixInitializationWithConstantValue2() {
Matrix<Integer> matrix = new Matrix<>(3, 5, new ConstantMatrixInitializer<>(12));
ListMatrix<Integer> matrix = new ListMatrix<>(3, 5, new ConstantMatrixInitializer<>(12));
// Test that all cells have the constant value.
for (int x = 0; x < 3; x++) {
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......
package datastruct;
package matrix;
import org.junit.jupiter.api.Test;
......@@ -6,14 +6,14 @@ import java.util.Iterator;
import static org.junit.jupiter.api.Assertions.*;
class MatrixTest {
class ListMatrixTest {
private final MatrixInitializer<Integer> sumInitializer =
coord -> coord.x() + coord.y();
@Test
public void testMatrixCreationWithInitializer() {
Matrix<Integer> matrix = new Matrix<>(3, 4, sumInitializer);
ListMatrix<Integer> matrix = new ListMatrix<>(3, 4, sumInitializer);
assertEquals(3, matrix.width());
assertEquals(4, matrix.height());
assertEquals(4, matrix.get(2, 2));
......@@ -24,7 +24,7 @@ class MatrixTest {
@Test
public void testMatrixCreationWithInitialValue() {
Matrix<String> matrix = new Matrix<>(2, 2, "Foo");
ListMatrix<String> matrix = new ListMatrix<>(2, 2, "Foo");
assertEquals(2, matrix.width());
assertEquals(2, matrix.height());
assertEquals("Foo", matrix.get(1, 1)); // Test a specific cell value.
......@@ -32,7 +32,7 @@ class MatrixTest {
@Test
public void testMatrixSetAndGet() {
Matrix<Integer> matrix = new Matrix<>(3, 3, 0);
ListMatrix<Integer> matrix = new ListMatrix<>(3, 3, 0);
matrix.set(1, 1,42);
assertEquals(42, matrix.get(1, 1));
matrix.set(0, 2,10);
......@@ -43,7 +43,7 @@ class MatrixTest {
@Test
public void testMatrixWidthAndHeight() {
Matrix<String> matrix = new Matrix<>(4, 2, "A");
ListMatrix<String> matrix = new ListMatrix<>(4, 2, "A");
assertEquals(4, matrix.width());
assertEquals(2, matrix.height());
matrix.set(3, 1,"B");
......@@ -53,7 +53,7 @@ class MatrixTest {
@Test
public void testMatrixIterator() {
Matrix<Integer> matrix = new Matrix<>(2, 2, sumInitializer);
ListMatrix<Integer> matrix = new ListMatrix<>(2, 2, sumInitializer);
Iterator<Integer> iterator = matrix.iterator();
assertTrue(iterator.hasNext());
assertEquals(0, iterator.next());
......@@ -68,7 +68,7 @@ class MatrixTest {
@Test
public void testMatrixCoordinates() {
Matrix<Integer> matrix = new Matrix<>(2, 2, 0);
ListMatrix<Integer> matrix = new ListMatrix<>(2, 2, 0);
Iterable<Coordinate> coordinates = matrix.coordinates();
int count = 0;
for (Coordinate coord : coordinates) {
......@@ -77,12 +77,24 @@ class MatrixTest {
assertEquals(4, count);
}
@Test
public void testMatrixLens() {
Matrix<Integer> matrix = new Matrix<>(2, 2, 0);
Lens<Integer> lens = matrix.at(1, 1);
assertEquals(0, lens.get());
lens.set(42);
assertEquals(42, matrix.get(1, 1));
public void testSubMatrix() {
Matrix<Integer> matrix = new ListMatrix<>(5, 5, 0);
for (int x = 0; x < 5; x++) {
for (int y = 0; y < 5; y++) {
matrix.set(x,y,x + y * 5);
}
}
Matrix<Integer> sub = matrix.subMatrix(Coordinate.of(2,1),2,3);
assertEquals(2, sub.width());
assertEquals(3, sub.height());
for (int x = 2; x < 4; x++) {
for (int y = 1; y < 4; y++) {
assertEquals(x + y * 5, sub.get(x-2,y-1));
}
}
}
}
package model;
import datastruct.Coordinate;
import matrix.Coordinate;
import javafx.scene.paint.Color;
import model.automata.GameOfLifeAutomaton;
import static model.automata.GameOfLifeState.*;
......
package model;
import matrix.Coordinate;
import model.automata.GameOfLifeAutomaton;
import model.automata.GameOfLifeState;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Random;
import static model.automata.GameOfLifeState.ALIVE;
import static model.automata.GameOfLifeState.DEAD;
import static org.junit.jupiter.api.Assertions.*;
class NextGenerationInitializerTest {
private final CellularAutomatonSimulation<GameOfLifeState> simulation =
new CellularAutomatonSimulation<>(
new GameOfLifeAutomaton(4,3),
new Random()
);
private final NextGenerationInitializer<GameOfLifeState> initializer =
new NextGenerationInitializer<>(this.simulation);
@BeforeEach
public void prepareSimulation() {
GameOfLifeState[][] state =
{ { DEAD, DEAD, DEAD, DEAD }
, { ALIVE, ALIVE, DEAD, DEAD }
, { DEAD, DEAD, ALIVE, DEAD }
};
for (Coordinate coordinate : this.simulation) {
this.simulation.at(coordinate).set(state[coordinate.y()][coordinate.x()]);
}
}
@Test
void initialValueAt() {
assertEquals(DEAD, initializer.initialValueAt(Coordinate.of(0,1)));
assertEquals(ALIVE, initializer.initialValueAt(Coordinate.of(1,0)));
assertEquals(ALIVE, initializer.initialValueAt(Coordinate.of(1,1)));
assertEquals(ALIVE, initializer.initialValueAt(Coordinate.of(1,2)));
assertEquals(DEAD, initializer.initialValueAt(Coordinate.of(2,2)));
}
@Test
public void testWrapCoordinateInsideGrid() {
Coordinate coordinate = Coordinate.of(1, 1);
Coordinate wrapped = initializer.wrap(coordinate);
assertEquals(coordinate, wrapped);
}
@Test
public void testWrapCoordinateOutsideGrid() {
assertEquals(
Coordinate.of(0, 1),
initializer.wrap(Coordinate.of(4, 4))
);
assertEquals(
Coordinate.of(3, 2),
initializer.wrap(Coordinate.of(-1, 2))
);
assertEquals(
Coordinate.of(3, 2),
initializer.wrap(Coordinate.of(-1, -1))
); }
@Test
public void testModuloPositive() {
int result = NextGenerationInitializer.modulo(7, 4);
assertEquals(3, result);
}
@Test
public void testModuloNegative() {
int result = NextGenerationInitializer.modulo(-7, 4);
assertEquals(1, result);
}
}
\ No newline at end of file