Skip to content

Commit f94a99e

Browse files
committed
Fixing documentation.
1 parent 5c958d3 commit f94a99e

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

main/algorithms/IDAStar.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def search(draw, current, end, path, depth, cost, visited):
1111
if f > cost:
1212
return f
1313

14+
if current in visited:
15+
return float("inf")
16+
1417
visited.add(current)
1518

1619
markup(draw, current)

main/algorithms/RP.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
from queue import Queue
44

55

6+
# Chebyshev distance
7+
def chebyshev(node1: object, node2: object):
8+
"""
9+
Calculate the Chebyshev distance between two nodes.
10+
11+
Parameters:
12+
node1 (Node): The first node.
13+
node2 (Node): The second node.
14+
15+
Returns:
16+
int: The Chebyshev distance between the two nodes.
17+
"""
18+
x1, y1 = node1.get_pos()
19+
x2, y2 = node2.get_pos()
20+
21+
return max(abs(x1 - x2), abs(y1 - y2))
22+
23+
624
# Manhattan distance
725
def manhattan(node1: object, node2: object):
826
"""
@@ -53,6 +71,8 @@ def heuristic(type: str, node1: object, node2: object):
5371
float: The heuristic distance between the two nodes.
5472
"""
5573
match type:
74+
case "chebyshev":
75+
return chebyshev(node1, node2)
5676
case "euclidean":
5777
return euclidean(node1, node2)
5878
case "manhattan":
@@ -66,7 +86,7 @@ def reconstruct_path(came_from: object, current: object, draw: object):
6686
Reconstructs the path from the start node to the end node in a maze.
6787
6888
Parameters:
69-
came_from (Dict[Node, Node]): A dictionary containing the nodes traversed
89+
came_from (Dict[Node, Node]): A dictionary containing the nodes traversed
7090
during the pathfinding algorithm.
7191
current (Node): The end node of the path.
7292
draw (function): A function for drawing the maze.
@@ -109,7 +129,7 @@ def get_unvisited_nodes(start: object):
109129

110130
def check(events: list, run: bool):
111131
"""
112-
Check for and handle user events such as quitting the program or
132+
Check for and handle user events such as quitting the program or
113133
pausing the algorithm.
114134
115135
Parameters:
@@ -124,9 +144,10 @@ def check(events: list, run: bool):
124144
pygame.quit()
125145
if event.type == pygame.KEYDOWN and event.key == pygame.K_s:
126146
run = False
127-
147+
128148
return run
129149

150+
130151
def markup(draw: object, current: object):
131152
"""
132153
Mark the current node as visited and redraw the grid.
@@ -144,4 +165,4 @@ def markup(draw: object, current: object):
144165
draw()
145166

146167
if not current.is_start() and not current.is_end():
147-
current.check()
168+
current.check()

resources/Explanations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
9. [Floyd-Warshall's Algorithm](#floyd-warshalls-algorithm)
1616
10. [Greedy Best-First Search](#greedy-best-first-search-gbfs-pathfinding-algorithm)
1717
11. [Greedy Best Line Search](#greedy-best-line-search-gbls-pathfinding-algorithm)
18-
11. [Iterative Deepening DFS](#greedy-best-line-search-gbls-pathfinding-algorithm)
19-
11. [Iterative Deepening A*](#greedy-best-line-search-gbls-pathfinding-algorithm)
18+
11. [Iterative Deepening A*](#iterative-deepening-a-pathfinding-algorithm)
19+
11. [Iterative Deepening DFS](#iterative-deepening-dfs-pathfinding-algorithm)
2020
12. [Random Walk Algorithm](#random-walk-pathfinding-algorithm)
2121
13. [Theta*](#theta-pathfinding-algorithm)
2222

0 commit comments

Comments
 (0)