diff --git a/CHANGELOG.md b/CHANGELOG.md index a0dd177..23b36d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8815521 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# `micorail` + +Utilities for Nguhcraft maintained by Yusur. NOT affiliated with the Republic of Minaro-Cohasia. + +## Usage + +~~~bash +$ python3 -m micorail +~~~ + +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. diff --git a/src/micorail/__init__.py b/src/micorail/__init__.py index 35c2795..f2d99d7 100644 --- a/src/micorail/__init__.py +++ b/src/micorail/__init__.py @@ -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") diff --git a/src/micorail/rails.py b/src/micorail/rails.py index 65dc260..b20a83f 100644 --- a/src/micorail/rails.py +++ b/src/micorail/rails.py @@ -10,7 +10,10 @@ from suou import chalk from .utils import HourMin, take_first ALL_DATA = json.load(open('data/network.json')) -LEGACY_DATA = json.load(open('data/network.1.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