Skip to content

Commit

Permalink
dfs now uses sets in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
PjrCodes committed Sep 2, 2024
1 parent 110600a commit a7ced18
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions search/dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def dhokla_first_search(start_node: Node):
prev_marble_count = start_node.board.num_marbles

open: list[Node] = [start_node]
closed: list = []
closed: set = set()

while open != []:
parent = open.pop()
if parent.board.goal_test():
Expand All @@ -17,7 +18,7 @@ def dhokla_first_search(start_node: Node):
prev_marble_count = parent.board.num_marbles
print(f"Marbles left: {parent.board.num_marbles}")

closed.append(parent.board)
closed.add(parent.board)
children: list = parent.board.move_gen()

children = [child for child in children if child not in closed]
Expand All @@ -43,7 +44,7 @@ def stepped_dhokla_first_search(node: Node, open: list[Node] | None, closed: set
children: list = parent.board.move_gen()

children = [child for child in children if child not in closed]

for child in children:
open.append(Node(child, parent))

Expand Down

0 comments on commit a7ced18

Please sign in to comment.