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

Prevent firefighters from crossing a mountain.

parent 39e96532
No related branches found
No related tags found
No related merge requests found
package util;
import view.ViewElement;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public interface Strategy {
Position neighborClosestToTarget(Position position, Collection<Position> targets, Map<Position, List<Position>> neighbors);
Position neighborClosestToTarget(Position position, Collection<Position> targets, Map<Position, List<Position>> neighbors, ViewElement[][] grid);
}
package util;
import util.Position;
import view.ViewElement;
import java.util.*;
......@@ -13,7 +14,7 @@ public class TargetStrategy implements Strategy{
* @return the position next to the current position that is on the path to the closest target.
*/
public Position neighborClosestToTarget(Position position, Collection<Position> targets,
Map<Position, List<Position>> neighbors) {
Map<Position, List<Position>> neighbors, ViewElement[][] grid) {
Set<Position> seen = new HashSet<Position>();
HashMap<Position, Position> firstMove = new HashMap<Position, Position>();
Queue<Position> toVisit = new LinkedList<Position>(neighbors.get(position));
......@@ -21,6 +22,7 @@ public class TargetStrategy implements Strategy{
firstMove.put(initialMove, initialMove);
while (!toVisit.isEmpty()) {
Position current = toVisit.poll();
if (grid[current.row()][current.column()] == ViewElement.MOUNTAIN) continue;
if (targets.contains(current))
return firstMove.get(current);
for (Position adjacent : neighbors.get(current)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment