diff --git a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderStrategy.java b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderStrategy.java index 084e690..23c8c9b 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderStrategy.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderStrategy.java @@ -21,6 +21,7 @@ public class PathFinderStrategy implements MoveStrategy{ private void test(){ ArrayList temporary = new ArrayList<>(); Iterator it = possiblePaths.iterator(); + while(it.hasNext()) { tryOutPaths current = it.next(); if (!current.isFeasible()) { @@ -29,7 +30,9 @@ public class PathFinderStrategy implements MoveStrategy{ else { for (PositionVector.Direction direction : directions) { temporary.add(current); - temporary.get(temporary.size() - 1).takeDirection(direction); + if (temporary.get(temporary.size() - 1).takeDirection(direction)){ + break; + } } } } @@ -49,6 +52,7 @@ public class PathFinderStrategy implements MoveStrategy{ public PositionVector.Direction nextMove() { return null; } + public class tryOutPaths { ArrayList directionsTaken = new ArrayList<>(); PositionVector currentPosition; @@ -58,18 +62,23 @@ public class PathFinderStrategy implements MoveStrategy{ public tryOutPaths(Track track){ this.track = track; } + public boolean isFeasible(){ return feasible; } - public void takeDirection(PositionVector.Direction direction) { + + public boolean takeDirection(PositionVector.Direction direction) { if(directionsTaken.size() >= 50){ feasible = false; + return false; } else if(finished){ + return true; } else { //check if possible eventuell hier?? directionsTaken.add(direction); + return false; } } }