-
Notifications
You must be signed in to change notification settings - Fork 2
/
solve.py
52 lines (43 loc) · 1.58 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
51
52
import streamlit as st
import numpy as np
import pandas as pd
import time
from operator import itemgetter
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from state import Board, Maze
from strategy import AStar, Dijkstra
from utils import ComputationProgress
if __name__ == "__main__":
parser = ArgumentParser(
description="Solves games using graph search algorithms",
formatter_class=ArgumentDefaultsHelpFormatter
)
parser.add_argument('--game',
help="The Game you'd like to solve (taquin and maze)",
default='taquin'
)
parser.add_argument('--strategy',
help="The algorithm used to solve the problem (a_star or dijkstra)",
default='dijkstra')
args = parser.parse_args()
if args.game == "maze":
start_maze = Maze.fixture_10_by_10()
print(start_maze)
if args.strategy == "a_star":
path = AStar.solve(start_maze, heuristic=Maze.h1)
elif args.strategy == "dijkstra":
path = Dijkstra.solve(start_maze)
elif args.game == "taquin":
start_board = Board.random()
print(start_board)
if args.strategy == "a_star":
path = AStar.solve(start_board, heuristic=Board.h2)
elif args.strategy == "dijkstra":
path = Dijkstra.solve(start_board)
if path:
print("path found")
for index, state in enumerate(path):
print("step", index)
print(state)
else :
print("no path is found. The state is considered as not solvable")