forked from mikepound/mazesolving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.py
24 lines (22 loc) · 952 Bytes
/
factory.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
# A simple factory class that imports and returns a relevant solver when provided a string
# Not hugely necessary, but reduces the code in solve.py, making it easier to read.
class SolverFactory:
def __init__(self):
self.Default = "breadthfirst"
self.Choices = ["breadthfirst","depthfirst","dijkstra", "astar","leftturn"]
def createsolver(self, type):
if type == "leftturn":
import leftturn
return ["Left turn only", leftturn.solve]
elif type == "depthfirst":
import depthfirst
return ["Depth first search", depthfirst.solve]
elif type == "dijkstra":
import dijkstra
return ["Dijkstra's Algorithm", dijkstra.solve]
elif type == "astar":
import astar
return ["A-star Search", astar.solve]
else:
import breadthfirst
return ["Breadth first search", breadthfirst.solve]