Skip to content
Snippets Groups Projects
Commit 6a49a5b5 authored by MANSOUR Chadi's avatar MANSOUR Chadi
Browse files

ignore

parent f5eb7bda
No related branches found
No related tags found
No related merge requests found
Pipeline #41384 passed
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
package model;
import util.Position;
import util.TargetStrategy;
import java.util.*;
public class CloudStrategy implements Strategy {
private final TargetStrategy targetStrategy = new TargetStrategy();
private List<Position> cloudPositions;
private final Set<Position> firePositions;
private final Map<Position, List<Position>> neighbors;
......
......@@ -20,22 +20,22 @@ public class FireTruckmovmentStrategy implements Strategy {
@Override
public List<Position> update() {
List<Position> modifiedPositions = new ArrayList<>();
List<Position> newFirefighterPositions = new ArrayList<>();
List<Position> newFirefTruckPositions = new ArrayList<>();
for (Position fireTruckPosition : fireTruckPositions) {
Position firstStep = nextValidPosition(fireTruckPosition ); // First step
Position firstStep = nextValidPosition(fireTruckPosition ); // 1er etape
extinguishNearbyFires(firstStep, modifiedPositions);
Position secondStep = nextValidPosition(firstStep); // Second step
Position secondStep = nextValidPosition(firstStep); // 2eme etape
extinguishNearbyFires(secondStep, modifiedPositions);
newFirefighterPositions.add(secondStep);
modifiedPositions.add(fireTruckPosition ); // Original position
modifiedPositions.add(firstStep); // First step position
modifiedPositions.add(secondStep); // Second step position
newFirefTruckPositions.add(secondStep);
modifiedPositions.add(fireTruckPosition );
modifiedPositions.add(firstStep);
modifiedPositions.add(secondStep);
}
fireTruckPositions = newFirefighterPositions;
fireTruckPositions = newFirefTruckPositions;
return modifiedPositions;
}
......@@ -45,110 +45,24 @@ public class FireTruckmovmentStrategy implements Strategy {
private void extinguishNearbyFires(Position position, List<Position> modifiedPositions) {
List<Position> firesToExtinguish = new ArrayList<>(neighbors.getOrDefault(position, List.of()));
firesToExtinguish.add(position); // Include current position
firesToExtinguish.removeIf(pos -> !firePositions.contains(pos)); // Only include actual fires
extinguishAll(firesToExtinguish);
modifiedPositions.addAll(firesToExtinguish); // Track extinguished fires
}
private void extinguishAll(List<Position> positions) {
firePositions.removeAll(positions);
}
@Override
public List<Position> getModelPositions() {
return fireTruckPositions;
}
@Override
public Set<Position> getFirePositions() {
return firePositions;
}
}
/*package model;
import util.Position;
import util.TargetStrategy;
import java.util.*;
public class FireTruckmovmentStrategy implements Strategy{
private final TargetStrategy targetStrategy = new TargetStrategy();
private List<Position> FireTruckPositions;
private final Set<Position> firePositions;
private final Map<Position, List<Position>> neighbors;
public FireTruckmovmentStrategy(List<Position> fireTruckPositions, Set<Position> firePositions, Map<Position, List<Position>> neighbors) {
this.FireTruckPositions = fireTruckPositions;
this.firePositions = firePositions;
this.neighbors = neighbors;
}
@Override
public List<Position> update() {
List<Position> modifiedPositions = new ArrayList<>();
List<Position> newFireTruckPositions = new ArrayList<>();
for (Position fireTruckPosition : FireTruckPositions) {
// Perform two steps for each fire truck
for (int step = 0; step < 2; step++) {
Position nextPosition = NextValidPosition(fireTruckPosition);
// Identify fires to extinguish around the next position
List<Position> firesToExtinguish = new ArrayList<>(neighbors.getOrDefault(nextPosition, List.of()));
firesToExtinguish.add(nextPosition);
firesToExtinguish.add(position);
firesToExtinguish.removeIf(pos -> !firePositions.contains(pos));
// Extinguish fires
extinguishAll(firesToExtinguish);
modifiedPositions.addAll(firesToExtinguish);
// Track positions
modifiedPositions.add(fireTruckPosition);
modifiedPositions.add(nextPosition);
// Update fire truck position for the next step
fireTruckPosition = nextPosition;
}
// Store the final position of the fire truck after two steps
newFireTruckPositions.add(fireTruckPosition);
}
// Update fire truck positions
FireTruckPositions = newFireTruckPositions;
return modifiedPositions;
}
private Position NextValidPosition(Position currentPosition) {
Position target = targetStrategy.neighborClosestToFire(currentPosition, firePositions, neighbors);
return target;
}
private void extinguishAll(List<Position> positions) {
firePositions.removeAll(positions);
}
@Override
public List<Position> getModelPositions() {
return FireTruckPositions;
return fireTruckPositions;
}
@Override
public Set<Position> getFirePositions() {
return firePositions;
}
}*/
}
\ No newline at end of file
......@@ -23,22 +23,19 @@ public class FirefighterGrid extends Canvas {
this.boxWidth = boxWidth;
this.boxHeight = boxHeight;
this.board = board;
setWidth(columns * boxWidth); // Set canvas width based on grid size
setHeight(rows * boxHeight); // Set canvas height based on grid size
setWidth(columns * boxWidth);
setHeight(rows * boxHeight);
}
// Repaint the grid and all elements (fire and firefighter)
public void repaint() {
if (board == null) return; // Exit if board is not set
if (board == null) return;
GraphicsContext gc = getGraphicsContext2D();
gc.clearRect(0, 0, getWidth(), getHeight()); // Clear the canvas before drawing
gc.clearRect(0, 0, getWidth(), getHeight());
// Iterate over the list of updated elements (positions and elements like fire or firefighter)
for (Pair<Position, ModelElement> pair : board.getUpdatedElements()) {
Position position = pair.getKey(); // Get the Position from the Pair
ModelElement element = pair.getValue(); // Get the ModelElement (either FIRE or FIREFIGHTER)
// Set the color based on the element type
if (element == ModelElement.FIRE) {
gc.setFill(Color.RED); // Fire is red
}else if (element == ModelElement.FIREFIGHTER) {
......@@ -57,17 +54,14 @@ public class FirefighterGrid extends Canvas {
gc.setFill(Color.WHITE); // Empty space is white
}
// Draw the element on the grid at the appropriate position
gc.fillRect(position.getCol() * boxWidth, position.getRow() * boxHeight, boxWidth, boxHeight);
gc.setStroke(Color.LIGHTGRAY); // Grid border color
gc.strokeRect(position.getCol() * boxWidth, position.getRow() * boxHeight, boxWidth, boxHeight);
}
// Optionally, draw the grid lines on top of the elements
drawGridLines(gc);
}
// Helper method to draw the grid lines
private void drawGridLines(GraphicsContext gc) {
gc.setStroke(Color.GRAY);
for (int col = 0; col < columns; col++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment