import numpy as npfrom copy import deepcopyimport timeimport resourcefrom collections import dequefrom queue import PriorityQueuefrom sys import argvmax_depth = 0max_frontier = 0count = 0class Node(object):    def __init__(self, state = None):        self.state = state        self.depth = 0        self.parent = None        self.opt = None        self.blank = def getPos(state, val):    for i in range(0, len(state)):        for j in range(0, len(state)):            if (stateij == val):                return i, jdef move(currNode, x, y):    n = len(currNode.state)    pos_old = currNode.blank    x_new = pos_old0 + x    y_new = pos_old1 + y    if (x_new < 0 or x_new >= n or y_new < 0 or y_new >= n):        pass    else:        newNode = Node(deepcopy(currNode.state))        newNode.depth = currNode.depth + 1        newNode.blank = x_new, y_new        newNode.statepos_old0pos_old1, newNode.statex_newy_new = newNode.statex_newy_new, newNode.statepos_old0pos_old1        return newNodedef up(currNode):    return move(currNode, -1, 0)def down(currNode):    return move(currNode, 1, 0)def left(currNode):    return move(currNode, 0, -1)def right(currNode):    return move(currNode, 0, 1)def search(initNode, goalNode, frontier, method, f_limit = None, valueRecord = None):    global max_depth   # to record the max depth    global max_frontier    # to record the max size of frontier    global count   # to count the number of expanded nodes    path =    # to record the path            frontier.append(initNode)    explored = set()    explored.add(”.join(str(n) for n in initNode.state))    # print (explored)    while (frontier):                    max_frontier = max(max_frontier, len(frontier))            # print(max_frontier)        node = Node()                    node = frontier.popleft()                flag = True        for i in range(0, len(node.state)):            for j in range(0, len(node.state)):                if node.stateij != goalNode.stateij:                    flag = False        if flag:            while (node):                neighbor = ”.join(str(n) for n in node.state)                # path.append(parentneighbor1)                # state = parentneighbor0                path.append(node.opt)                node = node.parent                            len_frontier = len(frontier)            return path::-11:, len(path) – 1, count, len_frontier, max_frontier, len(path) – 1, max_depth        count += 1        upNode = up(node)        downNode = down(node)        leftNode = left(node)        rightNode = right(node)        def appendNode(node, neighborNode, s, order):            global max_depth            if (neighborNode):                neighbor = ”.join(str(n) for n in neighborNode.state)                    if neighbor not in explored:                        max_depth = max(node.depth + 1, max_depth)                                                    frontier.append(neighborNode)                        explored.add(neighbor)                neighborNode.parent = node                neighborNode.opt = s        if (method == ‘BFS’):            appendNode(node, upNode, ‘Up’, 0)                        appendNode(node, downNode, ‘Down’, 1)                        appendNode(node, leftNode, ‘Left’, 2)                        appendNode(node, rightNode, ‘Right’, 3)                                return Nonedef BFS(initNode, goalNode):    frontier = deque()    return search(initNode, goalNode, frontier, ‘BFS’)if __name__ == ‘__main__’:    start_time = time.clock()