Skip to content

Commit

Permalink
Merge pull request junyanz#30 from ThomasThelen/master
Browse files Browse the repository at this point in the history
Fix Quiet Mode
  • Loading branch information
jostbr authored Jan 30, 2018
2 parents 1a069de + b7d4c85 commit 7c2c55b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/maze_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def solve_maze(self, maze_id, method, neighbor_method="fancy"):
"""DEVNOTE: When adding a new solution method, call it from here.
Also update the list of names in the documentation above"""
if method == "DepthFirstBacktracker":
solver = DepthFirstBacktracker(maze, neighbor_method, quiet_mode)
solver = DepthFirstBacktracker(maze, neighbor_method, self.quiet_mode)
maze.solution_path = solver.solve()
elif method == "BiDirectional":
solver = BiDirectional(maze, neighbor_method, quiet_mode)
solver = BiDirectional(maze, neighbor_method, self.quiet_mode)
maze.solution_path = solver.solve()
elif method == "BreadthFirst":
solver = BreadthFirst(maze, neighbor_method, quiet_mode)
solver = BreadthFirst(maze, neighbor_method, self.quiet_mode)
maze.solution_path = solver.solve()

def show_maze(self, id, cell_size=1):
Expand Down
20 changes: 10 additions & 10 deletions src/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Solver(object):
"""

def __init__(self, maze, neighbor_method, quiet_mode):
def __init__(self, maze, quiet_mode, neighbor_method):
logging.debug("Class Solver ctor called")

self.maze = maze
Expand All @@ -40,11 +40,11 @@ def get_path(self):

class BreadthFirst(Solver):

def __init__(self, maze, neighbor_method):
def __init__(self, maze, quiet_mode=False, neighbor_method="fancy"):
logging.debug('Class BreadthFirst ctor called')

self.name = "Breadth First Recursive"
super().__init__(maze, neighbor_method)
super().__init__(maze, neighbor_method, quiet_mode)

def solve(self):

Expand Down Expand Up @@ -89,10 +89,10 @@ def solve(self):

class BiDirectional(Solver):

def __init__(self, maze, neighbor_method="fancy"):
def __init__(self, maze, quiet_mode=False, neighbor_method="fancy"):
logging.debug('Class BiDirectional ctor called')

super().__init__(maze, neighbor_method)
super().__init__(maze, neighbor_method, quiet_mode)
self.name = "Bi Directional"

def solve(self):
Expand Down Expand Up @@ -164,7 +164,7 @@ def solve(self):
elif any((True for n_pq in real_neighbours_pq if (n_pq, False) in path_kl)):
path_pq.append(((p_curr, q_curr), False))
path = [p_el for p_tuple in zip(path_kl, path_pq) for p_el in p_tuple] # Zip paths
if not self.quietMode:
if not self.quiet_mode:
print("Number of moves performed: {}".format(len(path)))
print("Execution time for algorithm: {:.4f}".format(time.clock() - time_start))
logging.debug("Class BiDirectional leaving solve")
Expand All @@ -175,10 +175,10 @@ class DepthFirstBacktracker(Solver):
"""A solver that implements the depth-first recursive backtracker algorithm.
"""

def __init__(self, maze, neighbor_method="fancy"):
def __init__(self, maze, quiet_mode=False, neighbor_method="fancy"):
logging.debug('Class DepthFirstBacktracker ctor called')

super().__init__(maze, neighbor_method)
super().__init__(maze, neighbor_method, quiet_mode)
self.name = "Depth First Backtracker"

def solve(self):
Expand All @@ -187,7 +187,7 @@ def solve(self):
self.maze.grid[k_curr][l_curr].visited = True # Set initial cell to visited
visited_cells = list() # Stack of visited cells for backtracking
path = list() # To track path of solution and backtracking cells
if not self.quietMode:
if not self.quiet_mode:
print("\nSolving the maze with depth-first search...")

time_start = time.clock()
Expand All @@ -210,7 +210,7 @@ def solve(self):
k_curr, l_curr = visited_cells.pop() # Pop previous visited cell (backtracking)

path.append(((k_curr, l_curr), False)) # Append final location to path
if not self.quietMode:
if not self.quiet_mode:
print("Number of moves performed: {}".format(len(path)))
print("Execution time for algorithm: {:.4f}".format(time.clock() - time_start))

Expand Down

0 comments on commit 7c2c55b

Please sign in to comment.