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

Create the class MotorizedStrategy

parent 4e463e33
Branches
No related tags found
No related merge requests found
Pipeline #40178 failed
package util;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class MotorizedStrategy implements Strategy{
@Override
public Position neighborClosestToTarget(Position position, Collection<Position> targets, Map<Position, List<Position>> neighbors) {
TargetStrategy normalStrategy = new TargetStrategy();
Position firstMove = normalStrategy.neighborClosestToTarget(position, targets, neighbors);
// Si un premier mouvement est trouvé, on simule un second déplacement
if (firstMove != null && neighbors.containsKey(firstMove)) {
return normalStrategy.neighborClosestToTarget(firstMove, targets, neighbors);
}
return position;
}
}
......@@ -4,7 +4,7 @@ import util.Position;
import java.util.*;
public class TargetStrategy {
public class TargetStrategy implements Strategy{
/**
......@@ -12,7 +12,7 @@ public class TargetStrategy {
* @param targets positions that are targeted.
* @return the position next to the current position that is on the path to the closest target.
*/
public Position neighborClosestToFire(Position position, Collection<Position> targets,
public Position neighborClosestToTarget(Position position, Collection<Position> targets,
Map<Position, List<Position>> neighbors) {
Set<Position> seen = new HashSet<Position>();
HashMap<Position, Position> firstMove = new HashMap<Position, Position>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment