From 7c841abfc676db124f8186d5eb5ea4d072d3a6de Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Sun, 20 Mar 2022 16:33:03 +0100 Subject: [PATCH] continued class PathFinderStrategy --- .../pm2/racetrack/strategy/PathFinderStrategy.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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; } } }