Skip to content

Commit

Permalink
Fix a bug when finding leaders
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc0711 committed Aug 14, 2021
1 parent 01f3d33 commit 8aaf8dd
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -68,7 +68,8 @@ public static Triple<IAgent, Double, Boolean> findLeader(final IScope scope,

// The second condition can be false when moving to a bigger road.
// In that case we will skip this and only find leaders on the new road.
if (road != null && lowestLane < RoadSkill.getNumLanesTotal(road)) {
if (road != null &&
lowestLane < RoadSkill.getNumLanesTotal(road) - numLanesOccupied) {
Triple<IAgent, Double, Boolean> triple = findNeighborOnCurrentRoad(scope,
vehicle, lowestLane, true);
if (triple != null) {
Expand Down Expand Up @@ -151,7 +152,8 @@ public static Triple<IAgent, Double, Boolean> findFollower(final IScope scope,

// The second condition can be false when moving to a bigger road.
// In case there's new lane with higher index, consider that there's no back vehicle.
if (road != null && lowestLane < RoadSkill.getNumLanesTotal(road)) {
if (road != null &&
lowestLane < RoadSkill.getNumLanesTotal(road) - numLanesOccupied) {
Triple<IAgent, Double, Boolean> triple = findNeighborOnCurrentRoad(scope,
vehicle, lowestLane, false);
if (triple != null) {
Expand Down Expand Up @@ -282,4 +284,5 @@ private static Triple<IAgent, Double, Boolean> findNeighborOnCurrentRoad(
return null;
}
}
}
}

0 comments on commit 8aaf8dd

Please sign in to comment.