THIS IS A CODE FOR 8 PUZZLE PROBLEM SOLVED BY BFS . PLEASE ADD AFUNCTION TO THIS CODE TO FIND THE NUMBER OF NODES EXPLORED ! ASSOON AS POSSIBLE!!!! THE FUNCTION SHOULD BE IN THIS CODE AND INPYTHON
import copy
import time
start=time.clock()
#global count
“””start_state=[[1,2,3],[4,5,6],[7,8,0]]
goal_state=[[1,2,3],[0,4,5],[7,8,6]]”””
start_state=[[1,2,5],[3,4,0],[6,7,8]]
goal_state=[[0,1,2],[3,4,5],[6,7,8]]
def left_shift(pres_state):
global count
temp_state=copy.deepcopy(pres_state)
for i in range(3):
for j in range(3):
if temp_state[i][j]==0 and j>0:
count=count+1
(temp_state[i][j-1],temp_state[i][j])=(temp_state[i][j],temp_state[i][j-1])
return temp_state
return pres_state
def right_shift(pres_state):
global count
temp_state=copy.deepcopy(pres_state)
for i in range(3):
for j in range(3):
if temp_state[i][j]==0 and j<2:
count+=1
(temp_state[i][j+1],temp_state[i][j])=(temp_state[i][j],temp_state[i][j+1])
return temp_state
return pres_state
def upper_shift(pres_state):
global count
temp_state=copy.deepcopy(pres_state)
for i in range(3):
for j in range(3):
if temp_state[i][j]==0 and i>0:
count+=1
(temp_state[i-1][j],temp_state[i][j])=(temp_state[i][j],temp_state[i-1][j])
return temp_state
return pres_state
def lower_shift(pres_state):
global count
temp_state=copy.deepcopy(pres_state)
for i in range(3):
for j in range(3):
if temp_state[i][j]==0 and i<2:
count+=1
(temp_state[i+1][j],temp_state[i][j])=(temp_state[i][j],temp_state[i+1][j])
return temp_state
return pres_state
class Node:
def __init__(self,pres_state,parent,visited):
self.pres_state=pres_state
self.parent=parent
self.visited=False
def print_path(pres_node):
l=[]
while pres_node.parent!=None:
l.append(pres_node.pres_state)
pres_node=pres_node.parent
l.reverse()
for i in
PayPal Gateway not configured
PayPal Gateway not configured