Skip to content
Snippets Groups Projects
Commit 419decbc authored by Sarah CHERCHEM's avatar Sarah CHERCHEM
Browse files

MotorizedFireFighter : modify the methode move

parent 18c17b4a
No related branches found
No related tags found
No related merge requests found
Showing
with 28 additions and 14 deletions
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
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
......@@ -85,6 +85,22 @@ public class BoardFireFighterBehavior implements BoardBehavior{
private void extinguish(Position position) {
firePositions.remove(position);
}
/**
* Éteint les feux autour d'une position donnée.
*
* @param firePositions Les positions des feux actuels.
* @param firefighterPosition La position actuelle du pompier.
* @param modifiedPositions Les positions modifiées pendant ce tour.
*/
protected void extinguishFire(Set<Position> firePositions, Position firefighterPosition, List<Position> modifiedPositions) {
List<Position> nearbyFires = neighbors.get(firefighterPosition).stream()
.filter(firePositions::contains)
.toList();
for (Position fire : nearbyFires) {
firePositions.remove(fire);
modifiedPositions.add(fire);
}
}
public Set<Position> getFirePositions() {
......
......@@ -3,10 +3,7 @@ package model;
import util.Position;
import util.TargetStrategy;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.*;
public class MotorizedFireFighter extends FireFighter{
private final TargetStrategy targetStrategy = new TargetStrategy();
......@@ -16,17 +13,18 @@ public class MotorizedFireFighter extends FireFighter{
public Position move(Map<Position, List<Position>> neighbors, Set<Position> firePositions) {
// Utilisation de targetStrategy pour le premier mouvement
Position firstMove = targetStrategy.neighborClosestToTarget(position, firePositions, neighbors);
public Position move(List<Position> positions,Map<Position, List<Position>> neighbors, Set<Position> firePositions) {
List<Position> modifiedPositions = new ArrayList<>();
List<Position> newPositions = new ArrayList<>();
Position finalPosition=null;
for (Position firefighterPosition : positions) {
// Déplacement motorisé (deux cases maximum)
Position firstStep = targetStrategy.neighborClosestToTarget(firefighterPosition, firePositions, neighbors);
Position secondStep = targetStrategy.neighborClosestToTarget(firstStep, firePositions, neighbors);
finalPosition = secondStep != null ? secondStep : firstStep;
// Après le premier déplacement, obtenir les voisins du premier mouvement
List<Position> possibleMovesFromFirst = neighbors.get(firstMove);
// Utilisation de targetStrategy pour choisir la meilleure position à partir du premier mouvement
Position secondMove = targetStrategy.neighborClosestToTarget(firstMove, firePositions, neighbors);
}
// Si nous avons trouvé une position valide, déplace le pompier de 2 cases
return secondMove;
return finalPosition;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment