Esempio n. 1
0
def get_direction(val):
    switcher = {
        1: ("Northwest", Pixel.Diag()),
        2: ("North", Pixel.Latitude()),
        3: ("Northeast", Pixel.Diag()),
        4: ("West", Pixel.Longitude()),
        5: ("East", Pixel.Longitude()),
        6: ("Southwest", Pixel.Diag()),
        7: ("South", Pixel.Latitude()),
        8: ("Southeast", Pixel.Diag())
    }

    return switcher.get(val)
Esempio n. 2
0
def A_star(init):
    #a* search
    pq = []
    costs = {}
    visited = []
    print(init)
    costs[init] = 0
    heapq.heappush(pq, (init.priority, init))
    path = []
    parents = {}
    parents[init] = None
    while True:
        state = heapq.heappop(pq)[1]
        if (state.isGoal()):
            print("finished")
            # build path
            while (state != None):
                path.append(state)
                state = parents[state]
            return path
            break
        for s in GetSuccessors(state):
            if not contains(visited, s):
                #print(s)
                visited.append(s)
                speed = 1
                if (float(s.elevation) > float(state.elevation)):
                    speed = float(s.elevation) / float(
                        state.elevation)  # slower uphill
                # movement in the y direction
                if (s.x == state.x):
                    costs[s] = costs[state] + (
                        1 / (s.terrain * speed)) * Pixel.Latitude()
                # movement in the x direction
                elif (s.y == state.y):
                    costs[s] = costs[state] + (
                        1 / (s.terrain * speed)) * Pixel.Longitude()
                # otherwise, diagonal movement
                else:
                    costs[s] = costs[state] + (
                        1 / (s.terrain * speed)) * Pixel.Diag()
                heapq.heappush(pq, (costs[s] + s.priority, s))
                parents[s] = state