A Star Algorithm
A Star Algorithm
class AStarGraph(object):
def __init__(self):
self.barriers = []
self.barriers.append([(2,2),(2,3),(2,4),(2,5),(2,6),(3,6),(4,6),(5,6),(5,5),(5,4),(5,3),(5,2),(4,2),(3,2),(2
,2)])
#adjacent or diagonal
D=1
D2 = 1
dx = abs(start[0] - goal[0])
dy = abs(start[1] - goal[1])
n = []
x2 = pos[0] + dx
y2 = pos[1] + dy
continue
n.append((x2, y2))
return n
if b in barrier:
G[start] = 0
closedVertices = set()
openVertices = set([start])
cameFrom = {}
#Get the vertex in the open list with the lowest F score
current = None
currentFscore = None
currentFscore = F[pos]
current = pos
if current == end:
path = [current]
current = cameFrom[current]
path.append(current)
path.reverse()
openVertices.remove(current)
closedVertices.add(current)
if neighbour in closedVertices:
cameFrom[neighbour] = current
G[neighbour] = candidateG
H = graph.heuristic(neighbour, end)
F[neighbour] = G[neighbour] + H
if __name__=="__main__":
graph = AStarGraph()
#plt.xlim(-1,8)
#plt.ylim(-1,8)
plt.show()