#!/usr/bin/python# -*- coding:utf-8 -*-classNode():def__init__(self, state, parent, action):
self.state = state
self.parent = parent
self.action = action
classStackFrontier():def__init__(self):
self.frontier =[]defadd(self, node):
self.frontier.append(node)defcontains_state(self, state):returnany(node.state == state for node in self.frontier)defempty(self):returnlen(self.frontier)==0defremove(self):if self.empty():raise Exception("empty frontier")else:#please add your code here to get a node from the frontier, according to FIBO#请在下面添加你的代码,从frontier表中按照后进先出的顺序移除一个结点,并将移除的结点给node
node = self.frontier[-1]#after remove a node ,your frontier should adaptive accordingly#在移除了一个结点后,你的frontier表应该相应的更新del self.frontier[-1]return node
classQueueFrontier(StackFrontier):defremove(self):if self.empty():raise Exception("empty frontier")else:#请添加你的代码,按照先进先出的顺序移除结点
node = self.frontier[0]#请更新frontier表,使得frontier表为移除了一个结点剩下的结点组成del self.frontier[0]return node
classMaze():def__init__(self, filename):# Read file and set height and width of mazewithopen(filename)as f:
contents = f.read()# Validate start and goalif contents.count("A")!=1