Skip to content
Snippets Groups Projects
Commit a0a14772 authored by AREZKI Celia's avatar AREZKI Celia
Browse files

MotorizedFirefighter : add the methode moveToTarget

parent 737e8785
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,10 @@ package model;
import util.Position;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
public class MotorizedFirefighter extends FirefighterManager {
private Random random =new Random();
public MotorizedFirefighter(List<Position> firefighterPositions) {
super(firefighterPositions);
}
......@@ -29,4 +28,22 @@ public class MotorizedFirefighter extends FirefighterManager {
}
return modifiedPositions;
}
@Override
public Position moveToTarget(Position currentPosition, Collection<Position> firePositions, Map<Position, List<Position>> neighbors) {
// Logique spécifique pour le déplacement motorisé (deux cases)
List<Position> possibleMoves = new ArrayList<>();
for (Position neighbor : neighbors.get(currentPosition)) {
for (Position secondNeighbor : neighbors.get(neighbor)) {
if (!secondNeighbor.equals(currentPosition)) {
possibleMoves.add(secondNeighbor);
}
}
}
if (!possibleMoves.isEmpty()) {
return possibleMoves.get(random.nextInt(possibleMoves.size()));
} else {
return currentPosition;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment