please help!

I keep getting this error : (-3, -3, IndexError('list index out of range',))

class SokobanProblem(search.Problem):

def __init__(self, initial):  ##-------- creates an object of the class  ##
    tmp_list = list(initial)
    row_len = len(tmp_list)
    column_len = len(tmp_list[0])-1
    goal_list = []
    for i in xrange(0, row_len):
        tmp = list(tmp_list[i])
        goal_list.append(tmp)
    goal_tuple = ()
    for i in xrange(0, row_len):
        for j in xrange(0, column_len):
               if goal_list[i][j] == 1 :
                   goal_list[i][j] = 5
               if goal_list[i][j] == 3 :
                   goal_list[i][j] = 5
               if goal_list[i][j] == 4 :
                   goal_list[i][j] = 0
               if goal_list[i][j] == 2 :
                   goal_list[i][j] = 0
        goal_list[i] = tuple(goal_list[i])
    goal_tuple = tuple(goal_list)
    search.Problem.__init__(self, initial, goal_tuple)

def successor(self, state):   ##-------- creates an object of the class  ##
    row_len = len(state)
    column_len = len(state[0])-1
    successors = []
    list_state = []
    tmp_list = list(state)
    for i in xrange(0, row_len):
        tmp = list(tmp_list[i])
        list_state.append(tmp)
    for  i in xrange(0, row_len):
        for j in xrange(0, column_len):
            if (list_state[i][j] == 2 or list_state[i][j] == 3) :
                #"UP" option
                if ((i-1) >= 0 and (list_state[i-1][j] == 0 or list_state[i-1][j] == 1)):
                    state_up =copy.deepcopy(list_state)
                    state_up[i-1][j] = state_up[i-1][j] +2
                    state_up[i][j] = state_up[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_up[i] = tuple(state_up[i])
                    tuple_state = tuple(state_up)
                    successors.append(["U", tuple_state])
                if (((i-2) >= 0) and (list_state[i-1][j] == 4) and ((list_state[i-2][j] == 0) or (list_state[i-2][j] == 1))):
                    state_up =copy.deepcopy(list_state)
                    state_up[i-2][j] = state_up[i-2][j] +4
                    state_up[i-1][j] = state_up[i-1][j] -2
                    state_up[i][j] = state_up[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_up[i] = tuple(state_up[i])
                    tuple_state = tuple(state_up)
                    successors.append(["U", tuple_state])
                #"DOWN" option
                if ((i+1) < row_len and (list_state[i+1][j] == 0 or list_state[i+1][j] == 1)):
                    state_down =copy.deepcopy(list_state)
                    state_down[i+1][j] = state_down[i+1][j] +2
                    state_down[i][j] = state_down[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_down[i] = tuple(state_down[i])
                    tuple_state = tuple(state_down)
                    successors.append(["D", tuple_state])
                if (((i+2) < row_len) and (list_state[i+1][j] == 4) and ((list_state[i+2][j] == 0) or (list_state[i+2][j] == 1))):
                    state_down =copy.deepcopy(list_state)
                    state_down[i+2][j] = state_down[i+2][j] +4
                    state_down[i+1][j] = state_down[i+1][j] -2
                    state_down[i][j] = state_down[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_down[i] = tuple(state_down[i])
                    tuple_state = tuple(state_down)
                    successors.append(["D", tuple_state])
                #"LEFT" option
                if ((j-1) >= 0 and (list_state[i][j-1] == 0 or list_state[i][j-1] == 1)):
                    state_left =copy.deepcopy(list_state)
                    state_left[i][j-1] = state_left[i][j-1] +2
                    state_left[i][j] = state_left[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_left[i] = tuple(state_left[i])
                    tuple_state = tuple(state_left)
                    successors.append(["L", tuple_state])
                if (((j-2) >= 0) and (list_state[i][j-1] == 4) and ((list_state[i][j-2] == 0) or (list_state[i][j-2] == 1))):
                    state_left =copy.deepcopy(list_state)
                    state_left[i][j-2] = state_left[i][j-2] +4
                    state_left[i][j-1] = state_left[i][j-1] -2
                    state_left[i][j] = state_left[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_left[i] = tuple(state_left[i])
                    tuple_state = tuple(state_left)
                    successors.append(["L", tuple_state])
                #"RIGHT" option
                if ((j+1) < column_len and (list_state[i][j+1] == 0 or list_state[i][j+1] == 1)):
                    state_right =copy.deepcopy(list_state)
                    state_right [i][j+1] = state_right [i][j+1] +2
                    state_right [i][j] = state_right[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_right[i] = tuple(state_right[i])
                    tuple_state = tuple(state_right)
                    successors.append(["R", tuple_state])
                if (((j+2) < column_len) and (list_state[i][j+1] == 4) and ((list_state[i][j+2] == 0) or (list_state[i][j+2] == 1))):
                    state_right =copy.deepcopy(list_state)
                    state_right[i][j+2] = state_right[i][j+2] +4
                    state_right[i][j+1] = state_right[i][j+1] -2
                    state_right[i][j] = state_right[i][j] -2
                    tuple_state = ()
                    for i in xrange(0, row_len):
                        state_right[i] = tuple(state_right[i])
                    tuple_state = tuple(state_right)
                    successors.append(["R", tuple_state])
    successors_tuple = ()
    for i in xrange(0,4):
        successors[i] = tuple(successors[i])
    successors_tuple = tuple(successors)    
    return successors_tuple

def goal_test(self, state):
    row_len = len(state)
    column_len = len(state[0])-1
    state_list = []
    tmp_state = list(state)
    state_tuple = ()
    for i in xrange(0, row_len):
        tmp = list(tmp_state[i])
        state_list.append(tmp)
    for  i in xrange(0, row_len):
        for j in xrange(0, column_len):
            if (state_list[i][j] == 2):
                state_list[i][j] = 0
        state_list[i] = tuple(state_list[i])
    state_tuple = tuple(state_list)
    return state_tuple == self.goal

 def create_sokoban_problem(game):

     sokoban_problem=SokobanProblem(game)

 return sokoban_problem

any suggestions?

any help will be much appreciated !

Where is the error occurring? If you post the traceback - the entire traceback, please - it should show what line in the code the problem lies in.

Also, what is the search.Problem class? I wouldn't need details, just a general overview of the parent class so I can better unerstand the class you're developing.

This article has been dead for over six months. Start a new discussion instead.