Hi all,
I am confused how it is able to loop through and find all its neighbor and get the optimized path to the goal
in terms of code how does it get its neighbor?
I dont know whether this thinking is correct
So i need to loop to find its neighbor
[x-1][y-1] [x][y-1] [x+1][y-1]
[x-1][y] [x+1][y]
[x-1][y+1] [x][y+1] [x+1][y+1]
(assuming i dont hit a null object)
if there is obstacle i just take out that square
then take the target minus each of those coordinates to find the H of each square
After that add G + H to find F with G++
if that square F is less than other F, i move to that square
And then i will repeat to the desired path?
function A*(start,goal)
ClosedSet := {} // The set of nodes already evaluated.
[COLOR="Red"]OpenSet := {start}[/COLOR] // The set of tentative nodes to be evaluated, initially containing the start node
Came_From := the empty map // The map of navigated nodes.
g_score := map with default value of Infinity
g_score[start] := 0 // Cost from start along best known path.
// Estimated total cost from start to goal through y.
f_score := map with default value of Infinity
f_score[start] := heuristic_cost_estimate(start, goal)
[COLOR="red"]while OpenSet is not empty[/COLOR]
[COLOR="Blue"]current := the node in OpenSet having the lowest f_score[] value[/COLOR]
if current = goal
return reconstruct_path(Came_From, goal)
OpenSet.Remove(current)
ClosedSet.Add(current)
for each neighbor of current
if neighbor in ClosedSet
continue // Ignore the neighbor which is already evaluated.
tentative_g_score := g_score[current] + dist_between(current,neighbor) // length of this path.
if neighbor not in OpenSet // Discover a new node
[COLOR="red"]OpenSet.Add(neighbor)[/COLOR]
else if tentative_g_score >= g_score[neighbor]
continue // This is not a better path.
// This path is the best until now. Record it!
Came_From[neighbor] := current
g_score[neighbor] := tentative_g_score
f_score[neighbor] := g_score[neighbor] + heuristic_cost_estimate(neighbor, goal)
return failure
function reconstruct_path(Came_From,current)
total_path := [current]
while current in Came_From.Keys:
current := Came_From[current]
total_path.append(current)
return total_path
so if there is a wall or blockage, it is calculated at the neighbor?
if neighbor in ClosedSet
continue
Can i create an array of the desired path?