A* help!

Blitz3D Forums/Blitz3D Beginners Area/A* help!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

well, i fixed the TYPO, but now I appear to be having logic flaws (?)
kinda hard to explain, cause I have NO idea what's going on.

Graphics3D 1280, 1024, 32, 1

Const gridscale = 1
Global goalx, goaly, startx, starty
Global currentx, currenty

Global lf = 10000000000

startx = 300
starty = 300
currentx = startx
currenty = starty
goalx = 800
goaly = 600


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

Type hlnode
	Field x
	Field y
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 0, 200, 0
	For hnode.hlnode = Each hlnode
		Rect hnode\x, hnode\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
	Cls
	RenderWorld()
	 
		If KeyHit(29) Then Stop 
		Text 0, 0, currentx + ", " + currenty

		;find the surrounding 8 nodes and replace them with potentialnodes (closing the normal ones)
		For node.goodnode = Each goodnode
			If ((node\x = currentx - (gridscale*100)) And (node\y = currenty)) Or ((node\x = currentx) + (gridscale*100) And (node\y = currenty)) Or ((node\y = currenty - (gridscale*100)) And (node\x = currentx)) Or ((node\y = currenty + (gridscale*100)) 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 + (gridscale*100)) And (node\y = currenty + (gridscale*100))) Or ((node\x = currentx + (gridscale*100)) And (node\y = currenty - (gridscale*100))) Or ((node\x = currentx - (gridscale*100)) And (node\y = currenty + (gridscale*100))) Or ((node\x = currentx - (gridscale*100)) And (node\y = currenty - (gridscale*100))) 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 - (gridscale*100)) And (node\y = currenty)) Or ((node\x = currentx) + (gridscale*100) And (node\y = currenty)) Or ((node\y = currenty - (gridscale*100)) And (node\x = currentx)) Or ((node\y = currenty + (gridscale*100)) 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
				lf = 10000000
				hnode.hlnode = New hlnode
				hnode\x = pnode\x
				hnode\y = pnode\y
			EndIf
			Delete pnode
			
		Next
		 
		
	Until currentx = goalx And currenty = goaly Or KeyHit(1)
End Function 


**EDIT**updated the code