[0.17.79] Train pathfinder does not account for length of final segment
Posted: Sat Jan 11, 2020 5:26 pm
While trying to wrangle the train pathfinder to create logic circuits using trains (you know, as you do) I ran in to a train always choosing the longer of two similar paths. After experimenting a bit, and taking a look at the source code, I've arrived at the conclusion that the length of the final segment is not accounted for when determining which path is shortest.
In the picture below the path to the closer train stop contains more segments which leads to the longer path being chosen. This is because the pathfinder returns as soon as it reaches the segment containing the target rail end.
not being
Changing that would likely mean changing how the initial nodes are generated and fixing viewtopic.php?f=7&t=79951
In the picture below the path to the closer train stop contains more segments which leads to the longer path being chosen. This is because the pathfinder returns as soon as it reaches the segment containing the target rail end.
Blueprint for reproduction
I think the issue stems from
Code: Select all
double costFromStart = currentNode->costFromStart + currentSegment->getLength();
Code: Select all
double costFromStart = currentNode->costFromStart + neighbor->getLength();