#!/usr/bin/python class U2State : def __init__(self, leftbank=['Bono','Edge','Larry','Adam'],rightbank=[], timeElapsed=0, flashlight='Left', parent=None, depth=1) : self.leftbank = leftbank[:] self.rightbank=rightbank[:] self.timeElapsed=timeElapsed self.flashlight = flashlight self.parent = parent self.depth=depth self.fvalue = 1 ### you fill in __repr__ def __repr__(self) : ### We'll use a dictionary to implement the closed list. This requires ### us to override __eq__; two states should be equal if they have the ### bandmembers in the same place, have the same depth, and have the ### same f-value. def __eq__(self, other) : ### using the heapq module requires us to override <, <=, >, and >=. ### state1 should be < state 2 if the fvalue of state1 is lower. def __lt__ (self, other) : return self.fvalue < other.fvalue ### you do the others def __le__ (self, other) : def __gt__ (self, other) : def __ge__ (self, other) : ### dictionaries require that objects used as keys implement __hash__. def __hash__(self) : return hash(tuple(self.leftbank + self.rightbank + [self.timeElapsed, self.flashlight, self.depth])) ### return true if we are at the goal def isGoal(self) : ### return true if this state cannot lead to a solution def isFailure(self) : ### for a state, return a list containing all reachable states. In other ### words, consider all possible moves and, for each move, determine the ### resulting state. This will probably be the most complex method you ### write. def successors(self) : ### our search function - it should take as input a search queue and an initial ### state. By providing different queues, we can implement different algorithms. def search(queue, initialState) : ### code for printing out a sequence of states that leads to a solution def printSolution(state) : print "Solution ***" moves = [state] current = state while current.parent != None : moves.append(current) current = current.parent moves.reverse() for move in moves : print move class SearchQueue : def __init__(self) : self.q = [] def insert(self, item) : pass def pop(self) : pass def isEmpty(self) : return self.q == [] ### you complete this. class BFSQueue(SearchQueue) : ### you complete this. class DFSQueue(SearchQueue) : ### you complete this class AStarQueue(SearchQueue) :