




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
A*路徑搜索
A*PathfindingWearegoingtodiscussthefundamentalsoftheA*pathfindingalgorithm.基本A*路徑搜索算法TheA*Algorithmprovidesaneffectivesolutiontotheproblemofpathfinding.A*路徑搜索
A*PathfindingWearego1定義搜索區(qū)域
DefiningthesearchareaThefirststepinpathfindingistodefinethesearcharea.首先定義搜索區(qū)域。Thegameworldneedstoberepresentedbypointsthatboththegamecharactersandobjectscanoccupy.Weneedtoreducethenodestoamanageablenumber,whichiswhatwemeanwhenwesayweneedtosimplifythesearcharea.減少搜索區(qū)域的節(jié)點(diǎn)數(shù)量,簡化搜索區(qū)域。
定義搜索區(qū)域
Definingthesearchare2定義搜索區(qū)域
Definingthesearcharea定義搜索區(qū)域
Definingthesearchare3基于方塊的搜索區(qū)域
Tiledsearcharea基于方塊的搜索區(qū)域
Tiledsearcharea4StartingthesearchWewillusetheA*algorithmtofindtheshortestpathbetweenanytwonodeswhileavoidingtheobstacles.避開障礙在任意兩點(diǎn)之間用A*算法獲得最短路徑。OpenList-Weneedawaytokeeptrackofwhichtilesneedtobesearched.可以作為后備檢測的點(diǎn)的集合;ClosedList-thetilesthatalreadywerechecked.已經(jīng)檢測完成的點(diǎn)的集合。StartingthesearchWewilluse5A*偽代碼
A*pseudocodeAddthestartingnodetotheopenlistWhiletheopenlistisnotempty{currentnode=nodefromopenlistwiththelowestcostifcurrentnode=goalnodethenpathcompleteelsemovecurrentnodetotheclosedlistexamineeachnodeadjacenttothecurrentnodeforeachadjacentnodeifitisn’tontheopenlistandisn’tontheclosedlistanditisn’tanobstaclethenmoveittoopenlistandcalculatecost}A*偽代碼
A*pseudocodeAddthest6A*偽代碼
A*pseudocode將開始點(diǎn)加到OpenList表中;重復(fù)一下過程,直到OpenList表空為止:{當(dāng)前點(diǎn)=OpenList表中代價(jià)值最小的點(diǎn);如果當(dāng)前點(diǎn)為目標(biāo)點(diǎn),則搜索完成;否則將當(dāng)前點(diǎn)移到ClosedList表中;對與當(dāng)前點(diǎn)相連的每一點(diǎn),重復(fù)執(zhí)行:如果該點(diǎn)不在OpenList、ClosedList,并且不是障礙點(diǎn)則將該點(diǎn)移到OpenList表中,計(jì)算該點(diǎn)的代價(jià)值;}A*偽代碼
A*pseudocode將開始點(diǎn)加到Open7CreateatiledsearchareaSpider-startingpointHumancharacter-destinationSolidblacksquares-wallobstaclesCreateatiledsearchareaSpid8AdjacenttilestoconsiderWeproceedtocheckeachoftheeightadjacenttilesandthenaddeachvalidtiletotheopenlist.對與蜘蛛相鄰的八個(gè)點(diǎn)檢查,不在任何表中和不是障礙的點(diǎn)加入OpenList表中。AdjacenttilestoconsiderWep9將開始點(diǎn)移到ClosedList表中
MovingthestartingtiletotheclosedlistStartpoint開始點(diǎn)將開始點(diǎn)移到ClosedList表中
Movingthe10LinkingtotheparentsLinktoparentsLinkingtotheparentsLinkto11賦予數(shù)值
ScoringWewillusepathscoringtodeterminethebestpathfromthestartingtiletothedestinationtile.(1)Welookatthecosttomovefromthestartingtiletoanygiventile.(2)Welookatthecosttomovefromthegiventiletothedestinationtile.(3)Wetakethesumofthecostofeachtilethatleadsbacktotheinitiallocation.賦予數(shù)值
ScoringWewillusepaths12CalculatingthepathscoreScore=Costfromstart+HeuristicWewillcheckthetileswiththelowestcost.Alowercostwillequatetoashorterpath.StartpointgivenpointdestinationCostfromstartheuristicCalculatingthepathscoreScor13InitialtilepathscoresInitialtilepathscores14初始化每一點(diǎn)的數(shù)值
InitialtilepathscoresThesvalueisthecostofgettingtherefromthestartingtile.s=從開始點(diǎn)到當(dāng)前點(diǎn)的累計(jì)代價(jià)值Thehvalueistheheuristicwhichisanestimateofthenumberofstepsfromthegiventiletothedestinationtile.h=從當(dāng)前點(diǎn)到目標(biāo)點(diǎn)的步數(shù)值Thecvalueisthesumofsandh.c=s+h初始化每一點(diǎn)的數(shù)值
Initialtilepathsc15Examiningtile(5,6)Examiningtile(5,6)16Examiningtile(5,5)Examiningtile(5,5)17Examiningtile(5,4)Examiningtile(5,4)18Examiningallthetiles
withacostof5Examiningallthetiles
with19Examiningalltiles
withacostof6Examiningalltiles
withaco20Examiningtile(3,4)Examiningtile(3,4)21Examiningtiles(2,5)and(3,5)Examiningtiles(2,5)and(3,522Examiningtiles(1,6)(2,6)(3,6)Examiningtiles(1,6)(2,6)(3,623最終路徑
ThecompletedpathS=6543210最終路徑
ThecompletedpathS=24FindingadeadendFindingadeadend25exerciseexercise26區(qū)域代價(jià)值
TerrainCostTheshortestpathisn’talwaysthefastestpath.最短路徑不一定是最快路徑。Alongwalkalongaroadmightbefasterthanashorterwalkthroughaswamp.如有沼澤地的情況。區(qū)域代價(jià)值
TerrainCostTheshortest27對區(qū)域代價(jià)賦予數(shù)值
ScoringwithterraincostTotalcostfromstart=costfromstart+terraincostScore=totalcostfromstart+heuristic每一點(diǎn)總代價(jià)值=從開始點(diǎn)到當(dāng)前點(diǎn)的累計(jì)代價(jià)值+區(qū)域代價(jià)值+啟發(fā)式數(shù)值。對區(qū)域代價(jià)賦予數(shù)值
Scoringwithterrain28區(qū)域的種類
TypesofterrainOpenterrain平坦區(qū)域Cost=1Grassland草地Cost=3Swampland沼澤地Cost=5區(qū)域的種類
TypesofterrainOpenter29AddingdifferentterrainelementsAddingdifferentterraineleme30OriginalpathoverterrainelementsOriginalpathoverterrainele31Calculatingthelowest-costpathCalculatingthelowest-costpa32Thelowest-costpathThelowest-costpath33InfluenceMappingOtherelementscaninfluencepathcostwhencalculatingapathwithA*.其他因素也能影響路徑代價(jià)。Nodesthatpassthroughthelineofsightofanyenemymightpresentahighercost.如在敵人的視線范圍內(nèi),區(qū)域代價(jià)比較高。InfluenceMappingOtherelement34InfluenceMappingInfluenceMappingisawaytovarythecostoftheA*nodesdependingonwhatishappeninginthegame.依賴游戲的不同,給節(jié)點(diǎn)不同的代價(jià)值。InfluenceMappingInfluenceMap35敵人炮火影響的區(qū)域代價(jià)
Influencedbytheenemyfiringzone敵人炮火影響的區(qū)域代價(jià)
Influencedbythe36記錄事件計(jì)算代價(jià)
RecordinggameincidentsWecanrecordindividualgameincidentsinaninfluencemap.Weareusingwhatthecharacterdoes.Iftheplayerrepeatedlyambushesandkillscomputer-controlledcharactersatagivendoorway,thatthedoorwaymightincreaseincost.如果玩家在門口重復(fù)地伏擊并殺死角色,則門口的代價(jià)增加。記錄事件計(jì)算代價(jià)
Recordinggameincide37InfluencedbythenumberofkillsInfluencedbythenumberofki38小結(jié)A*算法的基本思想;對區(qū)域代價(jià)的搜索實(shí)現(xiàn)的算法分析;在運(yùn)行過程中代價(jià)的改變。小結(jié)A*算法的基本思想;39思考題(1)A*算法的核心思想是什么?(2)A*算法與其他(如基本路徑搜索)算法有何不同?(3)在路徑搜索算法中為什么A*算法是最有效的算法?(4)A*算法有何不足?遇到什么樣情況不是最快的搜索算法?思考題(1)A*算法的核心思想是什么?40本次實(shí)驗(yàn)內(nèi)容用A*算法實(shí)現(xiàn)路徑搜索。如有時(shí)間,可以考慮區(qū)域代價(jià)情況的搜索。在實(shí)現(xiàn)過程中,對代價(jià)可采用數(shù)組方式記錄代價(jià)值。感興趣可以將根據(jù)運(yùn)行狀況改變代價(jià)值的思想,運(yùn)用到實(shí)際的游戲或優(yōu)化系統(tǒng)中。本次實(shí)驗(yàn)內(nèi)容用A*算法實(shí)現(xiàn)路徑搜索。41A*路徑搜索
A*PathfindingWearegoingtodiscussthefundamentalsoftheA*pathfindingalgorithm.基本A*路徑搜索算法TheA*Algorithmprovidesaneffectivesolutiontotheproblemofpathfinding.A*路徑搜索
A*PathfindingWearego42定義搜索區(qū)域
DefiningthesearchareaThefirststepinpathfindingistodefinethesearcharea.首先定義搜索區(qū)域。Thegameworldneedstoberepresentedbypointsthatboththegamecharactersandobjectscanoccupy.Weneedtoreducethenodestoamanageablenumber,whichiswhatwemeanwhenwesayweneedtosimplifythesearcharea.減少搜索區(qū)域的節(jié)點(diǎn)數(shù)量,簡化搜索區(qū)域。
定義搜索區(qū)域
Definingthesearchare43定義搜索區(qū)域
Definingthesearcharea定義搜索區(qū)域
Definingthesearchare44基于方塊的搜索區(qū)域
Tiledsearcharea基于方塊的搜索區(qū)域
Tiledsearcharea45StartingthesearchWewillusetheA*algorithmtofindtheshortestpathbetweenanytwonodeswhileavoidingtheobstacles.避開障礙在任意兩點(diǎn)之間用A*算法獲得最短路徑。OpenList-Weneedawaytokeeptrackofwhichtilesneedtobesearched.可以作為后備檢測的點(diǎn)的集合;ClosedList-thetilesthatalreadywerechecked.已經(jīng)檢測完成的點(diǎn)的集合。StartingthesearchWewilluse46A*偽代碼
A*pseudocodeAddthestartingnodetotheopenlistWhiletheopenlistisnotempty{currentnode=nodefromopenlistwiththelowestcostifcurrentnode=goalnodethenpathcompleteelsemovecurrentnodetotheclosedlistexamineeachnodeadjacenttothecurrentnodeforeachadjacentnodeifitisn’tontheopenlistandisn’tontheclosedlistanditisn’tanobstaclethenmoveittoopenlistandcalculatecost}A*偽代碼
A*pseudocodeAddthest47A*偽代碼
A*pseudocode將開始點(diǎn)加到OpenList表中;重復(fù)一下過程,直到OpenList表空為止:{當(dāng)前點(diǎn)=OpenList表中代價(jià)值最小的點(diǎn);如果當(dāng)前點(diǎn)為目標(biāo)點(diǎn),則搜索完成;否則將當(dāng)前點(diǎn)移到ClosedList表中;對與當(dāng)前點(diǎn)相連的每一點(diǎn),重復(fù)執(zhí)行:如果該點(diǎn)不在OpenList、ClosedList,并且不是障礙點(diǎn)則將該點(diǎn)移到OpenList表中,計(jì)算該點(diǎn)的代價(jià)值;}A*偽代碼
A*pseudocode將開始點(diǎn)加到Open48CreateatiledsearchareaSpider-startingpointHumancharacter-destinationSolidblacksquares-wallobstaclesCreateatiledsearchareaSpid49AdjacenttilestoconsiderWeproceedtocheckeachoftheeightadjacenttilesandthenaddeachvalidtiletotheopenlist.對與蜘蛛相鄰的八個(gè)點(diǎn)檢查,不在任何表中和不是障礙的點(diǎn)加入OpenList表中。AdjacenttilestoconsiderWep50將開始點(diǎn)移到ClosedList表中
MovingthestartingtiletotheclosedlistStartpoint開始點(diǎn)將開始點(diǎn)移到ClosedList表中
Movingthe51LinkingtotheparentsLinktoparentsLinkingtotheparentsLinkto52賦予數(shù)值
ScoringWewillusepathscoringtodeterminethebestpathfromthestartingtiletothedestinationtile.(1)Welookatthecosttomovefromthestartingtiletoanygiventile.(2)Welookatthecosttomovefromthegiventiletothedestinationtile.(3)Wetakethesumofthecostofeachtilethatleadsbacktotheinitiallocation.賦予數(shù)值
ScoringWewillusepaths53CalculatingthepathscoreScore=Costfromstart+HeuristicWewillcheckthetileswiththelowestcost.Alowercostwillequatetoashorterpath.StartpointgivenpointdestinationCostfromstartheuristicCalculatingthepathscoreScor54InitialtilepathscoresInitialtilepathscores55初始化每一點(diǎn)的數(shù)值
InitialtilepathscoresThesvalueisthecostofgettingtherefromthestartingtile.s=從開始點(diǎn)到當(dāng)前點(diǎn)的累計(jì)代價(jià)值Thehvalueistheheuristicwhichisanestimateofthenumberofstepsfromthegiventiletothedestinationtile.h=從當(dāng)前點(diǎn)到目標(biāo)點(diǎn)的步數(shù)值Thecvalueisthesumofsandh.c=s+h初始化每一點(diǎn)的數(shù)值
Initialtilepathsc56Examiningtile(5,6)Examiningtile(5,6)57Examiningtile(5,5)Examiningtile(5,5)58Examiningtile(5,4)Examiningtile(5,4)59Examiningallthetiles
withacostof5Examiningallthetiles
with60Examiningalltiles
withacostof6Examiningalltiles
withaco61Examiningtile(3,4)Examiningtile(3,4)62Examiningtiles(2,5)and(3,5)Examiningtiles(2,5)and(3,563Examiningtiles(1,6)(2,6)(3,6)Examiningtiles(1,6)(2,6)(3,664最終路徑
ThecompletedpathS=6543210最終路徑
ThecompletedpathS=65FindingadeadendFindingadeadend66exerciseexercise67區(qū)域代價(jià)值
TerrainCostTheshortestpathisn’talwaysthefastestpath.最短路徑不一定是最快路徑。Alongwalkalongaroadmightbefasterthanashorterwalkthroughaswamp.如有沼澤地的情況。區(qū)域代價(jià)值
TerrainCostTheshortest68對區(qū)域代價(jià)賦予數(shù)值
ScoringwithterraincostTotalcostfromstart=costfromstart+terraincostScore=totalcostfromstart+heuristic每一點(diǎn)總代價(jià)值=從開始點(diǎn)到當(dāng)前點(diǎn)的累計(jì)代價(jià)值+區(qū)域代價(jià)值+啟發(fā)式數(shù)值。對區(qū)域代價(jià)賦予數(shù)值
Scoringwithterrain69區(qū)域的種類
TypesofterrainOpenterrain平坦區(qū)域Cost=1Grassland草地Cost=3Swampland沼澤地Cost=5區(qū)域的種類
TypesofterrainOpenter70AddingdifferentterrainelementsAddingdifferentterraineleme71OriginalpathoverterrainelementsOriginalpathoverterrainele72Calculatingthelowest-costpathCalculatingthelowest-costpa73Thelowest-costpathThelowest-costpath74Inf
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國過氧化鋅市場發(fā)展現(xiàn)狀及前景趨勢分析報(bào)告
- 2025-2030年中國調(diào)壓箱市場發(fā)展?fàn)顩r及營銷戰(zhàn)略研究報(bào)告
- 2025-2030年中國裝飾天花板制造行業(yè)運(yùn)行狀況及發(fā)展趨勢預(yù)測報(bào)告
- 2025-2030年中國蜜蜂養(yǎng)殖與蜂產(chǎn)品加工行業(yè)運(yùn)營狀況與發(fā)展?jié)摿Ψ治鰣?bào)告
- 2025-2030年中國萵苣和菊苣行業(yè)運(yùn)營狀況與發(fā)展?jié)摿Ψ治鰣?bào)告
- 2025-2030年中國膜片式微孔曝氣器行業(yè)前景趨勢及發(fā)展?jié)摿Ψ治鰣?bào)告
- 2025-2030年中國聚萘二甲酸乙二醇酯pen行業(yè)運(yùn)行趨勢及投資戰(zhàn)略研究報(bào)告
- 2025-2030年中國粗糧飲料市場發(fā)展趨勢及前景調(diào)研分析報(bào)告
- 2025-2030年中國硝酸異辛酯行業(yè)運(yùn)行狀況及發(fā)展趨勢分析報(bào)告
- 2025-2030年中國眼影市場運(yùn)行現(xiàn)狀及發(fā)展前景分析報(bào)告
- 綜合實(shí)踐項(xiàng)目 制作細(xì)胞模型 教學(xué)設(shè)計(jì)-2024-2025學(xué)年人教版生物七年級上冊
- 青島版二年級數(shù)學(xué)下冊課程綱要
- 光伏電氣設(shè)備試驗(yàn)方案
- 經(jīng)濟(jì)法律法規(guī)基礎(chǔ)知識單選題100道及答案
- 新蘇教版三年級科學(xué)下冊全冊課件【全套】
- 2024-2030年中國精細(xì)化工行業(yè)發(fā)展分析及發(fā)展前景與投資研究報(bào)告
- 2024至2030年中國非標(biāo)自動(dòng)化行業(yè)需求領(lǐng)域與供需平衡預(yù)測分析報(bào)告
- 2024年重慶市高考生物試卷(含答案解析)
- 2024年(學(xué)習(xí)強(qiáng)國)思想政治理論知識考試題庫與答案
- DL∕T 540-2013 氣體繼電器檢驗(yàn)規(guī)程
- 數(shù)控機(jī)床技術(shù)先進(jìn)性
評論
0/150
提交評論