Newer
Older
package model;
import util.Position;
public class Fire implements Element {
private Neighbour neighbour;
private final ModelElement modelElement;
public Fire(Position position){
MEHDI
committed
modelElement = ModelElement.FIRE;
public Position getPosition() {
return position;
@Override
public ModelElement getElement() {
return modelElement;
}
public void setPosition(Position position) {
this.position = position;
MEHDI
committed
public List<Position> update(Board<List<ModelElement>> firefighterBoard) {
this.neighbour = new Neighbour(firefighterBoard);
List<Position> modifiedPositions = new ArrayList<>();
if (firefighterBoard.stepNumber() % 2 == 0) {
MEHDI
committed
Set<Position> newFirePositions = new HashSet<>();
for (Position fire : new HashSet<>(firefighterBoard.getFires().keySet())) {
List<Position> neighboursAvailable = this.neighbour.getNeighbors().get(fire);
neighboursAvailable.removeAll(firefighterBoard.getObstacles().keySet());
MEHDI
committed
newFirePositions.addAll(this.neighbour.getNeighbors().get(fire));
}
MEHDI
committed
for (Position position : newFirePositions) {
if (!firefighterBoard.getFires().containsKey(position)) {
firefighterBoard.getFires().put(position, new Fire(position));
modifiedPositions.add(position);
}
}
}
return modifiedPositions;
}
public boolean contains(List<Position> positions) {
return positions.contains(this.getPosition());