Implementation details on the train pathfinding (same path)

Things that are not directly connected with Factorio.
Post Reply
harmony
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri May 04, 2018 3:58 pm
Contact:

Implementation details on the train pathfinding (same path)

Post by harmony »

Hey

was wondering if anyone has some info on how all the wagons of a train are kept on the same path.
Trying to implement my own train project (not planning on selling anyhting) and it's something I'm stuck at, the only thing I can currently do is make them pick a random turn at intersections

Image
works fine when there's no intersection obviously

Image

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Implementation details on the train pathfinding (same path)

Post by betrok »

I do not know how exactly the pathfinding works in factorio, but basically you have to build the weighted graph from your railroad.
The vertexes will represent intersections and possible other notable points such as stops. Weight of the edges can contain length of the section itself and stuff like a penalty for red signals.
harmony wrote:was wondering if anyone has some info on how all the wagons of a train are kept on the same path.
Well, all the wagons just follow the first one. Save the calculated path and use it for all of them.

Jap2.0
Smart Inserter
Smart Inserter
Posts: 2339
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Implementation details on the train pathfinding (same path)

Post by Jap2.0 »

There are 10 types of people: those who get this joke and those who don't.

Post Reply

Return to “Off topic”