-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine functionality in Finder, implement BreadthFirstFinder #3
- Loading branch information
Showing
10 changed files
with
199 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from .finder import Finder, TIME_LIMIT, MAX_RUNS | ||
from pathfinding.core.util import backtrace | ||
from pathfinding.core.diagonal_movement import DiagonalMovement | ||
|
||
class BreadthFirstFinder(Finder): | ||
def __init__(self, heuristic=None, weight=1, | ||
diagonal_movement=DiagonalMovement.never, | ||
time_limit=TIME_LIMIT, | ||
max_runs=MAX_RUNS): | ||
super(BreadthFirstFinder, self).__init__( | ||
heuristic=heuristic, | ||
weight=weight, | ||
diagonal_movement=diagonal_movement, | ||
time_limit=time_limit, | ||
max_runs=max_runs) | ||
if not diagonal_movement: | ||
self.diagonalMovement = DiagonalMovement.never | ||
|
||
def check_neighbors(self, start, end, grid, open_list): | ||
node = open_list.pop(0) | ||
node.closed = True | ||
|
||
if node == end: | ||
return backtrace(end) | ||
|
||
neighbors = self.find_neighbors(grid, node) | ||
for neighbor in neighbors: | ||
if neighbor.closed or neighbor.opened: | ||
continue | ||
|
||
open_list.append(neighbor) | ||
neighbor.opened = True | ||
neighbor.parent = node |
Oops, something went wrong.