-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgent.py
More file actions
57 lines (45 loc) · 1.86 KB
/
Agent.py
File metadata and controls
57 lines (45 loc) · 1.86 KB
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
from Frontier import *
from Maze import Maze
def BFS(maze:list, start_state:tuple, goal_value:int, wall_value:int):
visited = set()
frontier = QueueFrontier()
frontier.add(Node(start_state, 0, None))
while not frontier.empty():
current = frontier.pop()
visited.add(current.state)
current_state = current.state
if maze[current_state[0]][current_state[1]] == goal_value:
path = list()
while current != None:
path.append(current.state)
current = current.parent
print(f'Visited a total of {len(visited)} unique nodes')
path.reverse()
return (True, path)
neighbors = Agent.neighbors(current_state, maze)
for neighbor in neighbors:
if not frontier.contains(neighbor) and neighbor not in visited:
frontier.add(Node(neighbor, None, current))
return (False, None)
def DFS(maze:list, start_state:tuple, goal_value:int, wall_value:int):
visited = set()
frontier = StackFrontier()
frontier.add(Node(start_state, None, None))
while not frontier.empty():
current = frontier.pop()
visited.add(current.state)
current_state = current.state
if maze[current_state[0]][current_state[1]] == goal_value:
path = list()
while current != None:
path.append(current.state)
current = current.parent
path.reverse()
return (True, path)
neighbors = Agent.neighbors(current_state, maze)
for neighbor in neighbors:
if neighbor not in frontier.nodes and neighbor not in visited and maze[neighbor[0]][neighbor[1]] != wall_value:
frontier.add(Node(neighbor, None, current))
return (False, None)
def Beam(maze:list, start_state:tuple):
pass