Skip to content
Snippets Groups Projects
FireFighter.java 1.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • import util.Neighbour;
    
    MEHDI's avatar
    MEHDI committed
    
    
    MEHDI's avatar
    MEHDI committed
    import java.util.HashSet;
    
    MEHDI's avatar
    MEHDI committed
    
    
    public class FireFighter extends Extinguisher {
    
        private final TargetStrategy targetStrategy = new TargetStrategy();
    
    
    
        public FireFighter(Position position){
    
            super(position);
            element = ModelElement.FIREFIGHTER;
    
        public List<Position> update(Board<List<ModelElement>> firefighterBoard){
    
            this.neighbour = new Neighbour(firefighterBoard);
    
    
            List<Position> modifiedPositions = new ArrayList<>();
    
            Position currentPosition = this.getPosition();
    
            Position newPosition = targetStrategy.neighborClosestToFire(currentPosition, firefighterBoard.getFires().keySet(), this.neighbour.getNeighbors());
    
    BELHACHEMI Mehdi's avatar
    BELHACHEMI Mehdi committed
    
    
    MEHDI's avatar
    MEHDI committed
    
    
            this.setPosition(newPosition);
            modifiedPositions.add(currentPosition);
            modifiedPositions.add(newPosition);
    
    BELHACHEMI Mehdi's avatar
    BELHACHEMI Mehdi committed
    
    
            for (Position neighbor : this.neighbour.getNeighbors().get(newPosition)) {
    
    MEHDI's avatar
    MEHDI committed
            for(Obstacle obstacle : firefighterBoard.getObstacles().values()){
                if(obstacle instanceof Montain){
                    modifiedPositions.remove(obstacle.getPosition());
                }
            }