-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathids.py
More file actions
29 lines (22 loc) · 826 Bytes
/
ids.py
File metadata and controls
29 lines (22 loc) · 826 Bytes
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
from puzzle import Puzzle
from node import Node
def dls(start: Puzzle, goal: Puzzle, depth: int) -> (list[str], int):
depth_limit: int = depth
nodes: list[Node] = [Node(start, None, None, 0)]
count: int = 0
explored: list[Puzzle] = []
while nodes:
node: Node = nodes.pop(0)
count += 1
explored.append(node.get_puzzle())
if node.get_puzzle() == goal:
return node.path_from_start(), count
if node.depth < depth_limit:
for item in node.expand():
if item.get_puzzle() not in explored:
nodes.insert(0, item)
def ids(start: Puzzle, goal: Puzzle, depth: int = 50) -> (list[str], int):
for i in range(depth):
result = dls(start, goal, i)
if result is not None:
return result