From d6a9b5f1aa9c52093ee67d1b38ec6a35e6b7f46e Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 25 Mar 2022 08:58:01 +0100 Subject: [PATCH] fixed PathFinderMoveStrategy --- .../strategy/PathFinderMoveStrategy.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java index ed844fe..4148124 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/strategy/PathFinderMoveStrategy.java @@ -21,11 +21,10 @@ public class PathFinderMoveStrategy implements MoveStrategy{ this.carIndex = carIndex; allDirections = Arrays.asList(PositionVector.Direction.values()); createMoveList(); - pointer = -1; } - private void createMoveList(){ + pointer = -1; calculatedStates = new ArrayList<>(); PossibleMove finishedMove = null; List possibleMoves= new ArrayList<>(); @@ -145,6 +144,22 @@ public class PathFinderMoveStrategy implements MoveStrategy{ public PositionVector.Direction nextMove() { //TODO check for crash and recreate movelist if crash pointer += 1; if (pointer < moveList.size()) { + PositionVector.Direction direction = moveList.get(pointer); + PositionVector currentVelocity = track.getCarVelocity(carIndex); + PositionVector newVelocity = new PositionVector(currentVelocity.getX() + direction.vector.getX(), currentVelocity.getY() + direction.vector.getY()); + PositionVector currentPosition = track.getCarPos(carIndex); + PositionVector newPosition = new PositionVector(currentPosition.getX() + newVelocity.getX(), currentPosition.getY() + newVelocity.getY()); + System.out.println("currentVelocity:" + currentVelocity.getX()+ ","+ currentVelocity.getY()); + System.out.println("newVelocity:" + newVelocity.getX()+ ","+ newVelocity.getY()); + for(PositionVector point : track.calculatePointsOnPath(currentPosition, newPosition)){ + if(track.willCrashAtPosition(carIndex, point)){ + createMoveList(); + pointer = 0; + break; + } + } + + return moveList.get(pointer); } return null;