Skip to content
Snippets Groups Projects
Commit 5060d1ac authored by Yanis OUALAN's avatar Yanis OUALAN
Browse files

Fix problème permission gradlew

parent 9283d2e7
Branches
No related tags found
No related merge requests found
Pipeline #39134 passed
gradlew 100644 → 100755
File mode changed from 100644 to 100755
......@@ -87,8 +87,7 @@ public class Controller {
private void initializeTimeline() {
Duration duration = new Duration(Controller.PERIOD_IN_MILLISECONDS);
EventHandler<ActionEvent> eventHandler =
event -> updateBoard();
EventHandler<ActionEvent> eventHandler = event -> updateBoard();
KeyFrame keyFrame = new KeyFrame(duration, eventHandler);
timeline = new Timeline(keyFrame);
timeline.setCycleCount(Animation.INDEFINITE);
......
......@@ -5,7 +5,8 @@ import java.util.List;
import util.Position;
/**
* This interface represents a generic board for modeling various state-based systems.
* This interface represents a generic board for modeling various state-based
* systems.
*
* @param <S> The type of state represented on the board.
*/
......@@ -63,12 +64,13 @@ public interface Board<S> {
int stepNumber();
public int getStepNumber();
// Le booléen replaceState permet de forcer le remplacement des cases vides
public void setSquare(S square, boolean replaceStates);
public boolean doesPositionExist(Position position);
public void clearCase(Position position);
public void clearCaseFrom(Entity entity, Position position);
public Position getNearestEntity(Position fromPos, Class<?> entityType);
......@@ -80,4 +82,3 @@ public interface Board<S> {
public void addEntityAtSquare(Entity entity, Position position, boolean replaceStates);
}
package model;
import java.util.ArrayList;
import java.util.List;
......@@ -11,11 +12,13 @@ public class Fire implements Entity{
private Position position;
private final Color viewColor = Color.RED;
private int age;
public Fire(Position position, Board<Square> b) {
this.b = b;
this.position = position;
this.age = 0;
}
public Fire(Position position, Board<Square> b, int age) {
this.b = b;
this.position = position;
......@@ -24,13 +27,14 @@ public class Fire implements Entity{
@Override
public List<Position> nextTurn(Board<Square> board) {
if(board.getStepNumber() % 2 == 0)return new ArrayList<Position>();
if (board.getStepNumber() % 2 == 0)
return new ArrayList<Position>();
List<Position> positions = PositionUtil.generateAdjacentPositions(position, board);
for (Position p : positions) {
if (b.getStates(p).isEmpty()) {
if(b.getStates(p).getMaxAge() < b.getStepNumber() && PositionUtil.getManhattanDistance(position, p) == 1){
if (b.getStates(p).getMaxAge() < b.getStepNumber()
&& PositionUtil.getManhattanDistance(position, p) == 1) {
board.addEntityAtSquare(new Fire(p, board), p);
}
}
if (!b.doesPositionExist(p)) {
......@@ -40,13 +44,11 @@ public class Fire implements Entity{
return positions;
}
@Override
public void setPosition(Position p) {
this.position = p;
}
@Override
public Position getPosition() {
return this.position;
......@@ -65,6 +67,7 @@ public class Fire implements Entity{
public void incrementAge() {
this.age = age + 1;
}
@Override
public void setAge(int age) {
this.age = age;
......
package model;
import java.util.ArrayList;
import java.util.List;
......@@ -11,11 +12,11 @@ public class FireFighter implements Entity{
private Position position;
private final Color viewColor = Color.BLUE;
public FireFighter(Position position, Board<Square> b) {
this.position = position;
this.age = 0;
}
public FireFighter(Position position, Board<Square> b, int age) {
this.position = position;
this.age = age;
......@@ -43,7 +44,7 @@ public class FireFighter implements Entity{
Position nextPos = getNextPositionTowards(position, nearestFirePos, b);
if (nextPos != null) {
// Mettre à jour la position du pompier
b.clearCase(position); // Vider l'ancienne case
b.clearCaseFrom(this, position); // Vider l'ancienne case
positions.add(new Position(position.x(), position.y()));
this.position = nextPos;
b.addEntityAtSquare(this, nextPos); // Mettre à jour la nouvelle case
......@@ -61,11 +62,12 @@ public class FireFighter implements Entity{
private List<Position> extinguish(List<Position> adjacentPositions, Board<Square> b) {
List<Position> extinguishedPositions = new ArrayList<>();
for (Position p : adjacentPositions) {
extinguishedPositions.addAll(adjacentPositions);
b.getStates(p).getEntities().removeIf(element -> element instanceof Fire);
List<Entity> entities = b.getStates(p).getEntities();
for (Entity e : entities) {
if (e instanceof EmptyEntity) {
e.setAge(age+1);
e.setAge(b.stepNumber() + 1);
}
}
extinguishedPositions.add(p); // Ajouter la position où le feu a été éteint
......@@ -107,9 +109,6 @@ public class FireFighter implements Entity{
return bestMove;
}
@Override
public void setPosition(Position p) {
this.position = p;
......@@ -119,6 +118,7 @@ public class FireFighter implements Entity{
public Position getPosition() {
return this.position;
}
public Color getViewColor() {
return this.viewColor;
}
......@@ -127,6 +127,7 @@ public class FireFighter implements Entity{
public int getAge() {
return this.age;
}
@Override
public void incrementAge() {
this.age = age + 1;
......
......@@ -40,7 +40,6 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
}
while (fireCount < initialFireCount || fireFighterCount < initialFireFightersCount) {
System.out.println("aaa");
Collections.shuffle(positions); // Mélange les positions pour un parcours aléatoire
for (Position pos : positions) {
......@@ -122,10 +121,8 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
}
@Override
public void clearCase(Position position) {
Square s = new Square(position);
s.addEntity(new EmptyEntity(position, step+1));
setSquare(s, true);
public void clearCaseFrom(Entity entity, Position position) {
matrix.get(position.x(), position.y()).getEntities().removeIf(element -> element.equals(entity));
}
public List<Position> updateToNextGeneration() {
......@@ -142,13 +139,15 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
if (s.getMaxAge() == step + 1) {
continue;
}
for (Entity e : s.getEntities()) {
List<Entity> entities = new ArrayList<>(s.getEntities());
for (Entity e : entities) {
List<Position> entityUpdatedPositions = e.nextTurn(this);
e.incrementAge();
changedPositions.addAll(entityUpdatedPositions);
}
}
this.step = this.step + 1;
// matrix.displayMatrix();
return changedPositions;
}
......@@ -188,7 +187,6 @@ public class FireFighterScenario extends EntityScenario implements Board<Square>
}
public int stepNumber() {
this.step = step + 1;
return this.step;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment