PRUNplanner doesn't model travel, so nothing in the project could answer "how far is planet X" until now. Builds a graph from /systemstars (698 systems, real jump connections + 3D coordinates) and runs Dijkstra weighted by straight-line ly (what FTL fuel/time actually scale with), reporting jump count alongside. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from puga import route
|
|
|
|
# Small synthetic graph: A-B-C in a line, A-D direct (shorter), D-C (closes a loop so Dijkstra has a choice)
|
|
GRAPH = {
|
|
"A": {"name": "A", "natural_id": "A", "pos": None, "neighbors": {"B": 10.0, "D": 3.0}},
|
|
"B": {"name": "B", "natural_id": "B", "pos": None, "neighbors": {"A": 10.0, "C": 10.0}},
|
|
"C": {"name": "C", "natural_id": "C", "pos": None, "neighbors": {"B": 10.0, "D": 10.0}},
|
|
"D": {"name": "D", "natural_id": "D", "pos": None, "neighbors": {"A": 3.0, "C": 10.0}},
|
|
}
|
|
|
|
|
|
def test_shortest_path_picks_lower_total_distance_not_fewer_jumps():
|
|
r = route.shortest_path("A", "C", graph=GRAPH)
|
|
assert r["path"] == ["A", "D", "C"] # 3+10=13, beats A-B-C's 10+10=20 despite same jump count
|
|
assert r["jumps"] == 2
|
|
assert r["distance_ly"] == 13.0
|
|
|
|
|
|
def test_same_system_is_zero_jumps():
|
|
r = route.shortest_path("A", "A", graph=GRAPH)
|
|
assert r["jumps"] == 0
|
|
assert r["distance_ly"] == 0.0
|
|
|
|
|
|
def test_no_route_returns_none():
|
|
graph = dict(GRAPH)
|
|
graph["E"] = {"name": "E", "natural_id": "E", "pos": None, "neighbors": {}}
|
|
assert route.shortest_path("A", "E", graph=graph) is None
|