示例#1
0
    # print expanded
    # policy search
    x = goal[0]
    y = goal[1]
    policy[x][y] = '*'
    path = []
    path.append([x, y])
    while ([x, y] != init):
        x1 = x - delta[action[x][y]][0]
        y1 = y - delta[action[x][y]][1]
        policy[x1][y1] = delta_name[action[x][y]]
        x = x1
        y = y1
        path.append([x, y])
    # print policy
    path.reverse()
    # print path
    smooth_path = gridworld.smooth_path(path)
    gridworld.draw_path(smooth_path)
    gridworld.show()
    return smooth_path


smooth_path = run_a_star(grid, heuristics, init, goal, cost=1)
for point in smooth_path:
    gridworld.draw_shape("circle", point, 8)
    gridworld.show()
    time.sleep(1)
gridworld.loop()