#!/usr/bin/env python3 from environment import State, goalTest, actions, result, equals from collections import deque class ClosedList: """List with deep membership check""" def __init__(self): self.list = [] def append(self, state): self.list.append(state) def contains(self, state): for elem in self.list: if equals(elem, state): return True return False # Example of goal-oriented agent. frontier = deque() # Initialize the frontier as a queue closedList = ClosedList() # Initialize the closed list as a list node = State() # Generate the initial state while not goalTest(node): # Apply the goal test for action in actions(node): # Expand the node frontier.append(result(node, action)) node = frontier.popleft() while closedList.contains(node): node = frontier.popleft() closedList.append(node) state.printState()