-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
50 lines (39 loc) · 1.81 KB
/
solve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import logging
from termcolor import colored
import shallie
from solver import Solution, find_solution_bfs
def main():
log = logging.getLogger('solve')
log.setLevel(logging.INFO)
c_handler = logging.StreamHandler()
c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
c_handler.setFormatter(c_format)
log.addHandler(c_handler)
shallie.load_data(log)
src_items = shallie.get_item_names(shallie.get_trait_donors())
dst_items = shallie.get_item_names(shallie.get_trait_recipients())
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source', help='Item added to the recipe; source of a trait',
choices=src_items, type=str)
parser.add_argument('-d', '--destination', help='Final recipe; destination of a trait',
choices=dst_items, type=str)
parser.add_argument('--depth', help='Maximum search depth. 0 for infinity.', type=int, default=0)
parser.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true')
args = parser.parse_args()
if args.verbose:
log.setLevel(logging.DEBUG)
src_item = shallie.get_item(args.source)
dst_item = shallie.get_item(args.destination)
print(f'Attempting to find a synthesis path from {colored(str(src_item), 'blue')} ' +
f'to {colored(str(dst_item), 'green')}')
Solution.max_depth = args.depth
solution = find_solution_bfs(log, src_item, dst_item, shallie.get_ingredients,
shallie.get_category_items, shallie.has_recipe,
shallie.get_disassembly_sources)
if solution is None:
print(colored('No valid solution found.', 'red'))
else:
print(solution.print_solution())
if __name__ == '__main__':
main()