Create some connections that routes should follow
Home | Exercise 2 - Routes I | Exercise 4 - Cities I
Let's create real connections with real infrastructure. We want to create highways or railways from point to point, and then allow vehicles just to move on that connections.
Let's create a connection from A(0,0)
to B(3,2)
and from B to C(1,4)
. Then use the same routes as before, from A
→ B → C (21 turns) and A → B → C → B (22 turns) and check the times
| | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| 0 | A | - | - | \ | |
| 1 | | | | ¦ | |
| 2 | | | | B | |
| 3 | | | | ¦ | |
| 4 | | C | - | / | |
You can also check what happens with the "circular" route (A → B → C → B) when the connection is also
circular (from A(0,0)
to B(3,2)
, from B to C(1,4)
and from C to A again)
You can use any pathfinding algorithm to search for the correct route from point to point. There are multiple implementations out there (Disjktra, A*...) if you need an A* algorithm implementation in Kotlin, I've put together some implementations I found on the Internet in the following repo pathfinding-astar-kotlin