Eights Puzzle (Breadth First Search)
<p>Can someone look at this code? I really am confused on what is wrong and I know that you guys hate me to put my entire code here but this was my last resort as I am a beginner and am trying to break down the problem.</p>

<pre><code>board_state = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]

start = [[0, 0, None]]

def swap(original, new):

    x = board_state[new[0]][new[1]]
    board_state[original[0]][original[1]] = x
    board_state[new[0]][[1]] = 0

    return board_state

def action(position):

    x = position[0]
    y = position[1]
    z = position[2]

    if z == None:
        return board_state
    elif z == 1:
        return swap([x + 1, y], [x, y])
    elif z == 2:
        return swap([x - 1, y], [x, y])
    elif z == 3:
        return swap([x, y + 1], [x, y])
    elif z == 4:
        return swap([x, y - 1], [x, y])


def next_states(current):

    row = current[0]
    column = current[1]

    l = [((row - 1), column, 1), #Move Up
          ((row + 1), column, 2), #Move Down
          (row, (column - 1), 3), #Move Left
          (row, (column + 1), 4)] #Move Right

    final = []

    for x in l:

        tempx = x[0]
        tempy = x[1]

        if tempx &gt; 2 or tempy &gt; 2:
            continue
        if tempx &lt; 0 or tempy &lt; 0:
            continue

        final.append(x)

    return final


def is_goal(x):

    goal = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
    return (x == goal)


def BFS():

    closed = []
    open = start   

    while len(open) &gt; 0:

        x = open.pop()

        if is_goal(action(x)):
            return x

        if (x in closed) == False:
            closed.append(x)
            open = open + next_states(x)

    return None

solution = BFS()

if solution:
    print "Yes"
    print solution
else:
    print "No"
</code></pre>
