8 Puzzle Problem
8 Puzzle Problem
8 Puzzle Problem
"""
Created on Mon Oct 16 12:38:47 2017
@author: drkhan
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 22 20:48:1 2017
@author: zia
"""
# 0 1 2
# 3 4 5
# 6 7 8
#%%
def result(statein,action):
if action == 'Up':
idx = statein.index(0)
stateout[idx] = statein[idx-3]
stateout[idx-3] = 0
return tuple(stateout)
return successors
# searching alogrithm
#def search(start,goal):
if goaltest(start,goal):
# return
print('goal reached')
else:
frontier = []
explored = []
frontier.append(start)
while frontier:
# if len(frontier) >=300:
# break
current = frontier.pop(0)
print('current:',current)
print('frontier',len(frontier))
print('explored',len(explored))
if goaltest(current,goal):
print('gaoal reached')
break
explored.append(current)
children = expand(current)
for child in children:
if child not in frontier and child not in explored:
frontier.append(child)