0.5.0 multiple step routes + README.md

This commit is contained in:
Yusur 2026-04-07 20:27:04 +02:00
parent f0617f741b
commit ef2ac2c7ac
4 changed files with 42 additions and 12 deletions

View file

@ -1,19 +1,26 @@
# 0.4.0
# Changelog
## 0.5.0
+ Added multiple step routes
+ Created README.md
## 0.4.0
+ Added nether lines
+ Added "day mode" colors
# 0.3.0
## 0.3.0
+ Added colors
+ Added multiple Tríwat post input
# 0.2.0
## 0.2.0
+ Added Tríwat post parsing utilities
+ Turned into a multi command
# 0.1.0
## 0.1.0
+ Initial commit
+ Added overworld route calculation

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# `micorail`
Utilities for Nguhcraft maintained by Yusur. NOT affiliated with the Republic of Minaro-Cohasia.
## Usage
~~~bash
$ python3 -m micorail <arguments>
~~~
In order for the script to work, you need the latest [network.json](https://mc.nguh.org/wiki/Data:NguhRoutes/network.json?action=raw) from Nguhcraft Wiki.

View file

@ -6,7 +6,7 @@ from .utils import HourMin
from .rails import main_rails
from .triwat import main_triwat
__version__ = "0.4.0"
__version__ = "0.5.0"
def build_parser():
parser = argparse.ArgumentParser()
@ -17,6 +17,7 @@ def build_parser():
parser_r.add_argument('start', help='station of start', default=None, nargs='?')
parser_r.add_argument('end', help='station of end', default=None, nargs='?')
parser_r.add_argument('steps', nargs='*', help='additional stops')
parser_r.add_argument('-t', '--time', help='time of start', type=HourMin, default=HourMin(0))
parser_r.add_argument('-n', '--nether', help='use the Nether', action='store_true')
parser_r.add_argument('--legacy', action='store_true', help="use legacy network")

View file

@ -10,7 +10,10 @@ from suou import chalk
from .utils import HourMin, take_first
ALL_DATA = json.load(open('data/network.json'))
try:
LEGACY_DATA = json.load(open('data/network.1.json'))
except FileNotFoundError:
LEGACY_DATA = None
INFINITY = 2147483648
@dataclass
@ -90,10 +93,10 @@ ALL_LINES = build_all_lines()
NETHER_LINES = build_all_lines('the_nether')
## TODO algorithms of research
def find_route(start: str, stop: str, nether = False):
def find_route(start: str, stop: str, nether = False, start_time = 0):
steps_i = []
dist, prev = dijkstra(start, nether=nether)
dist, prev = dijkstra(start, nether=nether, start_time = start_time)
cur = stop
steps_i.append((find_station(stop), dist[stop]))
@ -101,7 +104,7 @@ def find_route(start: str, stop: str, nether = False):
steps_i.insert(0, (find_station(cur_prev), dist[cur_prev]))
cur = cur_prev
steps_i.insert(0, (find_station(start), 0))
steps_i.insert(0, (find_station(start), start_time))
return steps_i
@ -141,12 +144,12 @@ def find_neighbors(start: str, *, nether = False):
return neighs
def dijkstra(start: str, *, nether: bool = False):
def dijkstra(start: str, *, nether: bool = False, start_time: int = 0):
dist = {node: INFINITY for node in ALL_DATA['stations']}
dist[start] = 0
dist[start] = start_time
prev = {node: None for node in ALL_DATA['stations']}
pq = [(0, start)]
pq = [(start_time, start)]
heapify(pq)
visited = set()
@ -192,6 +195,9 @@ def main_rails(args):
st_start = find_station(args.start)
st_end = find_station(args.end)
st_end_additional = []
if args.steps:
st_end_additional = [find_station(take_first(x)) for x in args.steps]
st_time = args.time
if not st_start or not st_end:
@ -200,6 +206,11 @@ def main_rails(args):
try:
route = find_route(st_start.code, st_end.code, nether=args.nether)
if st_end_additional:
for st_e2 in st_end_additional:
route.extend(find_route(st_end.code, st_e2.code, nether=args.nether, start_time = route[-1][1])[1:])
st_end = st_e2
except KeyError as k:
print('**', f'{chalk.red(f'Route {k} is impassable')}')
return