Example #1
0
def reconstructPath(checked, xInit, yInit, xEnd, yEnd):

    Path = []
    currentCell = (xEnd, yEnd)
    # while the path is not back home yet
    while currentCell[0] != xInit or currentCell[1] != yInit:
        # set x and y values for current cell
        curr_x = currentCell[0]
        curr_y = currentCell[1]
        # print "path x", curr_x , "path y" , curr_y
        # get location of current cell in list
        currentIndex = getIndexPlace(checked, curr_x, curr_y)
        # set the next cell to be the came from cell of the current cell
        nextCell = checked[currentIndex].cameFrom
        # add the current cell to the list
        Path.append(currentCell)
        # change the current cell to be the next cell
        currentCell = nextCell

    initCell = (xInit, yInit)
    Path.append(initCell)
    # print "Path", Path
    return Path