-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.py
120 lines (110 loc) · 4.65 KB
/
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
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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]
# 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]
# 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]
# 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]
# 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]