I'm near done with my first A* test. But this dang bug won't leave me alone! After much testing, I have found that the potentialnodes (surrounding 8 nodes to be checked) are not being created. Any ideas?
(sorry about those long spots in the code screwing up the window)
any help is greatly appreciated, I'll be debugging while i wait for a response to tell me that it was a typo. Thanks for helping me get to sleep! (I'll have trouble sleeping until this works)
(sorry about those long spots in the code screwing up the window)
Graphics3D 1280, 1024, 32, 1 Const gridscale = 1 Global goalx, goaly, startx, starty Global currentx, currenty Global lf = 10000000000 startx = 2 starty = 2 currentx = startx currenty = starty goalx = 5 goaly = 6 Type goodnode Field x Field y Field open = False End Type Type badnode Field x Field y End Type Type potentialnode Field x Field y Field g Field h Field lf End Type setupgrid() While Not KeyHit(1) Cls() RenderWorld() drawgrid() If KeyDown(29) Then Stop EndIf If KeyHit(57) Then updatepath() Flip() Wend End Function setupgrid() For w = 0 To GraphicsWidth()-(gridscale*100) Step gridscale*100 For h = 0 To GraphicsHeight()-(gridscale*100) Step gridscale*100 node.goodnode = New goodnode node\x = w node\y = h Next Next End Function Function drawgrid() Color 0, 0, 200 For node.goodnode = Each goodnode Rect node\x, node\y, gridscale*100, gridscale*100, 0 Next Color 255, 255, 255 End Function ;g = 10 if vertical or horizontal ;g = 14 if diagonal ;h = 10*(abs(currentx - goalx) + abs(currenty - goaly)) Function updatepath() Repeat If KeyHit(29) Then Stop Text 0, 0, currentx + ", " + currenty + ", " + Rnd(0, 100) ;find the surrounding 8 nodes and replace them with potentialnodes (closing the normal ones) For node.goodnode = Each goodnode If ((node\x = currentx - 1) And (node\y = currenty)) Or ((node\x = currentx) + 1 And (node\y = currenty)) Or ((node\y = currenty - 1) And (node\x = currentx)) Or ((node\y = currenty + 1) And (node\x = currentx)) Then pnode.potentialnode = New potentialnode pnode\x = node\x pnode\y = node\y pnode\g = 10 node\open = False EndIf If ((node\x = currentx + 1) And (node\y = currenty + 1)) Or ((node\x = currentx + 1) And (node\y = currenty - 1)) Or ((node\x = currentx - 1) And (node\y = currenty + 1)) Or ((node\x = currentx - 1) And (node\y = currenty - 1)) Then pnode.potentialnode = New potentialnode pnode\x = node\x pnode\y = node\y pnode\g = 14 node\open = False EndIf Next ;determine h, f (g was found above), and lf(lowest f) For pnode.potentialnode = Each potentialnode pnode\h = 10 * (Abs(currentx - goalx) + Abs(currenty - goaly)) If pnode\h + pnode\g < lf Then lf = pnode\h + pnode\g pnode\lf = True EndIf n = n + 1 Next Text 0, 20, n n=0 ;delete all potentialnodes, open up the closed nodes, and set currentx and y to the location of the lowest f For node.goodnode = Each goodnode If ((node\x = currentx - 1) And (node\y = currenty)) Or ((node\x = currentx) + 1 And (node\y = currenty)) Or ((node\y = currenty - 1) And (node\x = currentx)) Or ((node\y = currenty + 1) And (node\x = currentx)) Then node\open = True Next For pnode.potentialnode = Each potentialnode If pnode\lf = True Then currentx = pnode\x currenty = pnode\y Stop EndIf Delete pnode Next Flip() Until currentx = goalx And currenty = goaly Or KeyHit(1) End Function
any help is greatly appreciated, I'll be debugging while i wait for a response to tell me that it was a typo. Thanks for helping me get to sleep! (I'll have trouble sleeping until this works)