亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? astarlibrary - demo 5.bb

?? 國外的一個A*算法演示
?? BB
?? 第 1 頁 / 共 3 頁
字號:
;A* Pathfinder by Patrick Lester. Used by permission.
;==================================================================
;Last updated 4/7/04

;This version of the aStar library has been modified to handle 
;pathfinding around other units.

;An article describing A* and this code in particular can be found at:
;http://www.policyalmanac.org/games/aStarTutorial.htm

;If you want to use this AStar Library, you may do so free of charge so 
;long as the author byline (above) is retained. Thank you to CaseyC 
;at the Blitz Forums for suggesting the use of binary heaps for the open 
;list. Email comments and questions to Patrick Lester at 
;pwlester@policyalmanac.org.

;==========================================================
;DECLARE VARIABLES
.declareVariables

	;Adjust these variables to match your map dimensions
	Global tileSize = 25, mapWidth = 32, mapHeight = 24

	;Create needed arrays
	Dim walkability(mapWidth+1,mapHeight+1) ;array that holds wall/obstacle information	
	Dim openList(mapWidth*mapHeight+2) ;1 dimensional array holding ID# of open list items
	Dim whichList(mapWidth+1,mapHeight+1)  ;2 dimensional array used to record 
		;whether a cell is on the open list or on the closed list.
	Dim openX(mapWidth*mapHeight+2) ;1d array stores the x location of an item on the open list
	Dim openY(mapWidth*mapHeight+2) ;1d array stores the y location of an item on the open list
	Dim parentX(mapWidth+1,mapHeight+1) ;2d array to store parent of each cell (x)
	Dim parentY(mapWidth+1,mapHeight+1) ;2d array to store parent of each cell (y)
	Dim Fcost(mapWidth*mapHeight+2)	;1d array to store F cost of a cell on the open list
	Dim Gcost(mapWidth+1,mapHeight+1) 	;2d array to store G cost for each cell.
	Dim Hcost(mapWidth*mapHeight+2)	;1d array to store H cost of a cell on the open list		
	
	Dim tempUnwalkability(mapWidth+1,mapHeight+1) ;array that holds info about adjacent units
	Dim nearByPath(mapWidth+1,mapHeight+1) 		
	Dim claimedNode.unit(mapWidth+1,mapHeight+1); array that stores claimed nodes	
	Dim gGroupUnit.unit(1) ;used to sort a selected group of units		
	Dim island(mapWidth+1,mapHeight+1) 
		
	;Declare constants
	Global onClosedList = 10 ;openList variable	
	Const notfinished = 0, notStarted = 0, found = 1 ; pathStatus constants 
	Const nonexistent = 2, tempStopped = 3; pathStatus constants 
	Const walkable = 0, unwalkable = 1 ; walkability array constants	
	Global gDiagonalBlockage, gPathCost
	
	;FindPath() mode constants
	Const normal = 0, randomMove = 1

;==========================================================
;FIND PATH: This function finds the path and saves it. Non-Blitz users please note,
;the first parameter is a pointer to a user-defined object called a unit, which contains all
;relevant info about the unit in question (its current location, speed, etc.). As an
;object-oriented data structure, types are similar to structs in C.
;	Please note that targetX and targetY are pixel-based coordinates relative to the
;upper left corner of the map, which is 0,0.
Function FindPath(unit.unit,targetX,targetY,mode=normal)

	;Random move mode is used when a unit's main target is
	;currently unreachable. After the random move, the unit
	;will try to pathfind to its original target again. Random
	;moves can break up units that happen to be approaching
	;each other from opposite directions down tight corridors.
	;See the UpdatePath() function.
	If mode = randomMove Then useDijkstras = True	

;1.	Convert location data (in pixels) to coordinates in the walkability array.
	startX = Floor(unit\xLoc/tileSize) : startY = Floor(unit\yLoc/tileSize)	
	targetX = Floor(targetX/tileSize) : targetY = Floor(targetY/tileSize)

;2.	Check for redirects	
	result = CheckRedirect(unit,targetX,targetY)	
	If result = failed Then Goto noPath ;target is unwalkable and could not find a redirect.
	If result = succeeded Then targetX = gInt1 : targetY = gInt2		

	;If starting location and target are in the same location...
	If startX = targetX And startY = targetY 
		unit\pathLength = 0 : unit\pathLocation = 0	
		PokeShort unit\pathBank,0,startX ;store starting x value	
		PokeShort unit\pathBank,2,startY ;store starting y value		
		Return found
	End If

;3.	a. Reset some variables that need to be cleared
	If onClosedList > 1000000 ;occasionally redim whichList
		Dim whichList(mapWidth,mapHeight) : onClosedList = 10
	End If	
	onClosedList = onClosedList+5 ;changing the values of onOpenList and onClosed list is faster than redimming whichList() array
	onOpenList = onClosedList-1
	tempUnwalkable = onClosedList-2
	penalized = onClosedList-3 
	unit\pathLength = notstarted ;i.e, = 0
	unit\pathLocation = notstarted ;i.e, = 0
	Gcost(startX,startY) = 0 ;reset starting square's G value to 0

	;b. Create a footprint for any nearby unit that the pathfinding unit 
	;may be about to collide with. Such nodes are designated as tempUnwalkable.	
	CreateFootPrints(unit.unit)

;4.	Add the starting location to the open list of squares to be checked.
	numberOfOpenListItems = 1
	openList(1) = 1 ;assign it as the top (and currently only) item in the open list, which is maintained as a binary heap (explained below)
	openX(1) = startX : openY(1) = startY

;5.	Do the following until a path is found or deemed nonexistent.
	Repeat
	
;6.	If the open list is not empty, take the first cell off of the list.
	;This is the lowest F cost cell on the open list.
	If numberOfOpenListItems <> 0 Then

	;Pop the first item off the open list.
	parentXval = openX(openList(1)) : parentYVal = openY(openList(1)) ;record cell coordinates of the item
	whichList(parentXval,parentYVal) = onClosedList ;add the item to the closed list

	;Open List = Binary Heap: Delete this item from the open list, which
	;is maintained as a binary heap. For more information on binary heaps, see:
	;http://www.policyalmanac.org/games/binaryHeaps.htm
	numberOfOpenListItems = numberOfOpenListItems - 1 ;reduce number of open list items by 1	
	openList(1) = openList(numberOfOpenListItems+1) ;move the last item in the heap up to slot #1
	v = 1	
	Repeat ;Repeat the following until the new item in slot #1 sinks to its proper spot in the heap.
		u = v	
		If 2*u+1 <= numberOfOpenListItems ;if both children exist
		 	;Check if the F cost of the parent is greater than each child.
			;Select the lowest of the two children.	
			If Fcost(openList(u)) >= Fcost(openList(2*u)) Then v = 2*u
			If Fcost(openList(v)) >= Fcost(openList(2*u+1)) Then v = 2*u+1		
		Else
			If 2*u <= numberOfOpenListItems ;if only child #1 exists
			 	;Check if the F cost of the parent is greater than child #1	
				If Fcost(openList(u)) >= Fcost(openList(2*u)) Then v = 2*u
			End If	
		End If
		If u<>v ;if parent's F is > one of its children, swap them
			temp = openList(u)
			openList(u) = openList(v)
			openList(v) = temp				
		Else
			Exit ;otherwise, exit loop
		End If	
	Forever

	
;7.	Check the adjacent squares. (Its "children" -- these path children
	;are similar, conceptually, to the binary heap children mentioned
	;above, but don't confuse them. They are different. Path children
	;are portrayed in Demo 1 with grey pointers pointing toward
	;their parents.) Add these adjacent child squares to the open list
	;for later consideration if appropriate (see various if statements
	;below).
	For b = parentYVal-1 To parentYVal+1
	For a = parentXval-1 To parentXval+1

	;If not off the map (do this first to avoid array out-of-bounds errors)
	If a <> -1 And b <> -1 And a <> mapWidth And b <> mapHeight

	;If not already on the closed list (items on the closed list have
	;already been considered and can now be ignored).			
	If whichList(a,b) <> onClosedList 
	
	;If not a wall/obstacle square
	If walkability(a,b) <> unwalkable
	
	;If not an adjacent node that is temporarily unwalkable
	;as defined by CreateFootprints()
	If tempUnwalkability(a,b) <> tempUnwalkable
	
	;If not occupied by a stopped unit
	node = unwalkable
	If claimedNode(a,b) = Null
		node = walkable
	Else If claimedNode(a,b)\pathStatus <> stopped 
		node = walkable	
	End If
	If node = walkable
			
	;Don't cut across corners (this is optional)
	corner = walkable	
	If a = parentXVal-1 
		If b = parentYVal-1 
			If walkability(parentXval-1,parentYval) = unwalkable Then corner = unwalkable
			If walkability(parentXval,parentYval-1) = unwalkable Then corner = unwalkable						
		Else If b = parentYVal+1 
			If walkability(parentXval,parentYval+1) = unwalkable Then corner = unwalkable 
			If walkability(parentXval-1,parentYval) = unwalkable Then corner = unwalkable 							
		End If
	Else If a = parentXVal+1 
		If b = parentYVal-1 
			If walkability(parentXval,parentYval-1) = unwalkable Then corner = unwalkable 
			If walkability(parentXval+1,parentYval) = unwalkable Then corner = unwalkable 							
		Else If b = parentYVal+1 
			If walkability(parentXval+1,parentYval) = unwalkable Then corner = unwalkable 
			If walkability(parentXval,parentYval+1) = unwalkable Then corner = unwalkable 			
		End If
	End If			
	If corner = walkable
	
	;If not already on the open list, add it to the open list.			
	If whichList(a,b) <> onOpenList	

		;Create a new open list item in the binary heap.
		newOpenListItemID = newOpenListItemID + 1; each new item has a unique ID #
		m = numberOfOpenListItems+1
		openList(m) = newOpenListItemID	 ;place the new open list item (actually, its ID#) at the bottom of the heap
		openX(newOpenListItemID) = a : openY(newOpenListItemID) = b ;record the x and y coordinates of the new item

		;Figure out its base G cost
		If Abs(a-parentXval) = 1 And Abs(b-parentYVal) = 1 Then
			addedGCost = 14 ;cost of going to diagonal squares	
		Else	
			addedGCost = 10 ;cost of going to non-diagonal squares				
		End If
		Gcost(a,b) = Gcost(parentXval,parentYVal)+addedGCost
		
		;If the node lies along the path of a nearby unit, add a penalty G cost.		
		If nearByPath(a,b) = penalized
			Gcost(a,b) = Gcost(a,b)+20
		Else If a<>parentXval And b<>parentYval
			If nearByPath(a,parentYval) = penalized
				If nearByPath(parentXval,b) = penalized
					Gcost(a,b) = Gcost(a,b)+28
				End If
			End If	
		End If		
			
		;Figure out its H and F costs and parent
		If useDijkstras = False
			Hcost(openList(m)) = 10*(Abs(a - targetx) + Abs(b - targety)) ; record the H cost of the new square
		Else
			Hcost(openList(m)) = 0	
		End If		
		Fcost(openList(m)) = Gcost(a,b) + Hcost(openList(m)) ;record the F cost of the new square
		parentX(a,b) = parentXval : parentY(a,b) = parentYVal	;record the parent of the new square	
		
		;Move the new open list item to the proper place in the binary heap.
		;Starting at the bottom, successively compare to parent items,
		;swapping as needed until the item finds its place in the heap
		;or bubbles all the way to the top (if it has the lowest F cost).
		While m <> 1 ;While item hasn't bubbled to the top (m=1)	
			;Check if child's F cost is < parent's F cost. If so, swap them.	
			If Fcost(openList(m)) <= Fcost(openList(m/2)) Then
				temp = openList(m/2)
				openList(m/2) = openList(m)
				openList(m) = temp
				m = m/2
			Else
				Exit
			End If
		Wend 
		numberOfOpenListItems = numberOfOpenListItems+1 ;add one to the number of items in the heap

		;Change whichList to show that the new item is on the open list.
		whichList(a,b) = onOpenList


;8.	If adjacent cell is already on the open list, check to see if this 
	;path to that cell from the starting location is a better one. 
	;If so, change the parent of the cell and its G and F costs.	
	Else; If whichList(a,b) = onOpenList
	
		;Figure out the base G cost of this possible new path
		If Abs(a-parentXval) = 1 And Abs(b-parentYVal) = 1 Then
			addedGCost = 14;cost of going to diagonal tiles	
		Else	
			addedGCost = 10 ;cost of going to non-diagonal tiles				
		End If
		tempGcost = Gcost(parentXval,parentYVal)+addedGCost
		
		;If the node lies along the path of a nearby unit, add a penalty G cost.			
		If nearByPath(a,b) = penalized
			tempGcost  = tempGcost+20
		Else If a<>parentXval And b<>parentYval
			If nearByPath(a,parentYval) = penalized
				If nearByPath(parentXval,b) = penalized
					tempGcost  = tempGcost+28
				End If
			End If	
		End If				
		
		;If this path is shorter (G cost is lower) then change
		;the parent cell, G cost and F cost. 		
		If tempGcost < Gcost(a,b) Then 	;if G cost is less,
			parentX(a,b) = parentXval 	;change the square's parent
			parentY(a,b) = parentYVal
			Gcost(a,b) = tempGcost 	;change the G cost			

			;Because changing the G cost also changes the F cost, if
			;the item is on the open list we need to change the item's
			;recorded F cost and its position on the open list to make
			;sure that we maintain a properly ordered open list.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区四区蜜桃| 欧美精品一区二区三区蜜桃| 日韩电影在线免费| 日韩亚洲欧美在线观看| 国产成人av资源| 亚洲男人电影天堂| 亚洲成人免费影院| 日韩亚洲欧美在线观看| 成人综合婷婷国产精品久久 | 欧美三级三级三级| 久久99精品久久久久久动态图| 国产99精品国产| 国产日产欧美一区二区视频| 一区二区三区免费网站| 欧美手机在线视频| 久久精品国产久精国产爱| www.在线欧美| 日韩国产欧美三级| 中文字幕一区免费在线观看| 91精品免费观看| 亚洲精品一区二区三区精华液| 成人福利视频在线| 男男成人高潮片免费网站| 91亚洲大成网污www| 免费在线观看成人| 亚洲视频在线一区二区| 国产东北露脸精品视频| 午夜一区二区三区视频| 欧美国产欧美综合| 日韩三级免费观看| 欧美性色综合网| 99re6这里只有精品视频在线观看| 日av在线不卡| 午夜精品久久久久久久久| 中文字幕一区二区三区四区不卡| 欧美一区二区在线视频| www.在线欧美| 国产91综合网| 三级精品在线观看| 一色屋精品亚洲香蕉网站| 精品日韩一区二区| 一本高清dvd不卡在线观看| 国产suv精品一区二区三区| 理论片日本一区| 日日摸夜夜添夜夜添亚洲女人| 亚洲激情在线激情| 国产精品卡一卡二| 中文子幕无线码一区tr| 欧美tickling挠脚心丨vk| 欧美猛男gaygay网站| 国产精品你懂的在线| 日韩欧美高清在线| 欧美一二三区在线观看| 欧美精品久久天天躁| 欧美婷婷六月丁香综合色| 91麻豆国产在线观看| 99精品久久99久久久久| 成人精品免费看| 丰满亚洲少妇av| 成人av网站在线观看免费| 波多野结衣亚洲| 国产91精品免费| 高清在线观看日韩| 成人黄色在线网站| 国产成人丝袜美腿| 久久99精品久久只有精品| 蜜桃av一区二区在线观看| 精品一区二区综合| 黑人巨大精品欧美一区| 国产99久久精品| 91在线精品一区二区三区| 一本色道亚洲精品aⅴ| 91精彩视频在线| 欧美日韩色综合| 欧美高清激情brazzers| 日韩午夜在线影院| 久久精品亚洲乱码伦伦中文 | 国产激情视频一区二区三区欧美 | 国产精品一区二区果冻传媒| 国产一区二区三区四| 成人中文字幕电影| 99久久久精品| 91黄色激情网站| 欧美在线制服丝袜| 制服视频三区第一页精品| 日韩欧美一级在线播放| 国产日韩欧美麻豆| 一区二区三区av电影| 奇米影视在线99精品| 韩国女主播一区| 99久久99久久精品免费看蜜桃| 91美女蜜桃在线| 日韩视频在线你懂得| 久久久99免费| 亚洲国产成人精品视频| 久久99蜜桃精品| 99精品桃花视频在线观看| 欧美日韩国产综合久久| 精品国产sm最大网站免费看| 日韩美女主播在线视频一区二区三区| 久久婷婷综合激情| 亚洲欧洲综合另类| 捆绑调教美女网站视频一区| 豆国产96在线|亚洲| 欧美在线观看视频在线| 精品国产91久久久久久久妲己 | 午夜精品久久久久久久99樱桃| 国产麻豆成人精品| 欧美综合亚洲图片综合区| 26uuu国产电影一区二区| 亚洲男人的天堂在线aⅴ视频| 一区二区三区精品| 国产精品一区在线| 欧美福利视频导航| 国产精品久久久久桃色tv| 日韩电影在线观看网站| 99久久国产免费看| 欧美日韩国产综合视频在线观看 | 久久午夜色播影院免费高清| 亚洲与欧洲av电影| 国产福利一区二区三区视频在线| 99久久久久免费精品国产| 久久影院视频免费| 日韩成人免费看| 欧美在线制服丝袜| 国产精品久久久久久妇女6080 | 成人h精品动漫一区二区三区| 色噜噜狠狠色综合中国| 欧美变态凌虐bdsm| 亚洲国产成人高清精品| www.久久精品| 久久在线观看免费| 美女视频黄 久久| 欧美三区在线视频| 亚洲视频免费看| 国产高清成人在线| 亚洲精品一区二区三区影院 | 亚洲国产精品av| 天堂av在线一区| 91在线视频免费91| 精品久久一区二区| 日韩精品久久久久久| 欧美视频一区在线观看| 亚洲免费资源在线播放| av在线免费不卡| 国产欧美日韩另类一区| 国产精品影音先锋| 久久久久久久久久久黄色| 久久精品72免费观看| 91精品国产91久久久久久最新毛片| 亚洲综合在线免费观看| 国产精品18久久久久久vr| 337p日本欧洲亚洲大胆精品| 久久狠狠亚洲综合| 欧美一级片在线观看| 午夜精品国产更新| 在线观看免费视频综合| 亚洲欧洲美洲综合色网| 成人av资源站| 亚洲欧美日韩电影| 欧美在线观看一二区| 亚洲成人精品一区| 在线播放视频一区| 久久精品国产亚洲aⅴ| 日韩色视频在线观看| 激情小说亚洲一区| 国产午夜一区二区三区| 成人久久18免费网站麻豆| 国产精品久久久久久久久果冻传媒| 成人app软件下载大全免费| 亚洲婷婷国产精品电影人久久| 91视频在线看| 国产蜜臀av在线一区二区三区 | 国产在线精品一区二区不卡了| 精品盗摄一区二区三区| 国产91精品一区二区| 亚洲图片欧美综合| 国产丝袜欧美中文另类| 欧美图区在线视频| 国产馆精品极品| 亚洲成人av在线电影| 久久夜色精品国产欧美乱极品| 99在线热播精品免费| 麻豆精品一区二区三区| 自拍偷拍欧美精品| 欧美一级欧美一级在线播放| av午夜一区麻豆| 日本伊人午夜精品| 亚洲美女精品一区| 久久日一线二线三线suv| 欧洲av一区二区嗯嗯嗯啊| 国产精品1区二区.| 日韩国产在线一| 亚洲免费av高清| 国产欧美日韩视频在线观看| 在线成人午夜影院| 色综合天天天天做夜夜夜夜做| 日韩一区二区三区电影在线观看| av一区二区三区黑人| 久久成人免费日本黄色|