人工智能课件第四次课.ppt

上传人:b****2 文档编号:2644553 上传时间:2022-11-04 格式:PPT 页数:63 大小:2.07MB
下载 相关 举报
人工智能课件第四次课.ppt_第1页
第1页 / 共63页
人工智能课件第四次课.ppt_第2页
第2页 / 共63页
人工智能课件第四次课.ppt_第3页
第3页 / 共63页
人工智能课件第四次课.ppt_第4页
第4页 / 共63页
人工智能课件第四次课.ppt_第5页
第5页 / 共63页
点击查看更多>>
下载资源
资源描述

人工智能课件第四次课.ppt

《人工智能课件第四次课.ppt》由会员分享,可在线阅读,更多相关《人工智能课件第四次课.ppt(63页珍藏版)》请在冰豆网上搜索。

人工智能课件第四次课.ppt

基本路径搜索和航点应用BasicPathfindingandWaypointsAtitsmostbasiclevel,pathfindingissimplytheprocessofmovingthepositionofagamecharacterfromitsinitiallocationtoadesireddestination.基本路径搜索是从初始位置移动到目标位置的过程。

基本路径搜索Basicpathfindingalgorithmif(positionXdestinationX)positionX-;elseif(positionXdestinationY)positionY-;elseif(positionYdestinationY)positionY+;限制条件SomelimitationsSimplepathmovementLine-of-sightpathmovement障碍问题Problemswithobstacles

(1)随机运动避开障碍RandomMovementObstacleAvoidanceRandommovementcanbeasimpleandeffectivemethodofobstacleavoidance.随机运动能够简单而有效地解决避开障碍。

Randommovementobstacleavoidancealgorithmifplayerinlineofsightfollowingstraightpathtoplayerelsemoveinrandomdirection

(2)围绕障碍物的追踪TracingAroundObstaclesThismethodcanbeeffectivewhenattemptingtofindapatharoundlargeobstacles,suchasamountainrangeinastrategyorrole-playinggame.解决围绕大障碍物寻找路径的问题。

基本追踪BasictracingComputer-controlledcharacterItsgoal存在的问题ProblemwithtracingDecidingwhentostoptracing?

什么时候停止追踪?

Weneedawaytodeterminewhenweshouldswitchfromthetracingstatebacktoasimplepathfindingstate.如何从追踪状态转换为路径搜索状态?

Onewayofaccomplishingthisistocalculatealinefromthepointthetracingstartstothedesireddestination.解决方法-计算从追踪开始点到目标点的直线距离。

改进的追踪Improvedtracing改进的追踪ImprovedtracingTracingtheoutskirtsoftheobstacleuntilthelineconnectingthestartingpointanddesireddestinationiscrossedensuresthatthepathdoesntloopbacktothestaringpoint.沿着障碍物外围追踪时,穿过障碍物连接开始点和目标点,防止追踪路径又回到起点。

视线追踪Tracingwithlineofsight视线追踪TracingwithlineofsightWefollowtheoutskirtsoftheobstacle,butateachstepwechecktoseeifthedestinationisinthecomputer-controlledcharacterslineofsight.每一步检测是否处在视线之内。

Ifso,weswitchfromatracingstatetoaline-of-sightpathfindingstate.处在视线之内,路径搜索从追踪状态转换为视线搜索状态。

(3)标记路径搜索BreadcrumbPathfindingBreadcrumbpathfindingcanmakecomputer-controlledcharactersseemveryintelligentbecausetheplayerisunknowinglycreatingthepathforthecomputer-controlledcharacter.带标记的路径搜索是玩家无意地留下轨迹。

Eachtimetheplayertakesastep,heunknowinglyleavesaninvisiblemarker,orbreadcrumb,onthegameworld.每次玩家走一步,它就留下一个不可见的标记。

BreadcrumbtrailAtrollrandomlymovesaboutthetile-basedenvironmentuntilitdetectsabreadcrumbonanadjacentlocation.ai_Entityclass#definekMaxTrailLength15classai_Entitypublic:

introw;intcol;inttype;intstate;inttrailRowkMaxTrailLength;inttrailColkMaxTrailLength;ai_Entity();ai_Entity();变量说明#definestatementsetsthemaximumnumberofplayerstepstotrack.设置kMaxTrailLength为玩家标记轨迹的最大步骤数。

trailRow,trailColarraysstoretherowandcolumncoordinatesoftheprevious15stepstakenbytheplayer.trailRow,trailCol保存由玩家标记的15步的横、纵坐标。

标记数组的初始化Trailarrayinitializationinti;for(i=0;ikMaxTrailLength;i+)trailRowi=-1;trailColi=-1;记录玩家的位置Recordingtheplayerpositionsvoidai_World:

KeyDown(intkey)inti;if(key=kUpKey)for(i=0;i0)entityListi.row-;DropBreadCrumb();if(key=kDownKey)for(i=0;ikMaxEntities;i+)if(entityListi.state=kPlayer)if(entityListi.row=kMaxRows-1)entityListi.row+;DropBreadCrumb();if(key=kLeftKey)for(i=0;i0)entityListi.col-;DropBreadCrumb();if(key=kRightKey)for(i=0;ikMaxEntities;i+)if(entityListi.state=kPlayer)if(entityListi.colkMaxCols-1)entityListi.col+;DropBreadCrumb();设置标记DroppingabreadCrumbvoidai_World:

DropBreadCrumb(void)inti;for(i=kMaxTrailLength-1;i-)entityList0.trailRowi=entityList0.trailRowi-1;entityList0.trailColi=entityList0.trailColi-1;entityList0.trailRow0=entityList0.row;entityList0.trailCol0=entityList0.Col;追踪标记FollowingthebreadcrumbsThegoalistodetermineifanyoftheeightpositionsadjacenttothecomputer-controlledtrollcontainabreadcrumb.是否在八个相邻方向之一中有标记。

Followingthebreadcrumbsfor(i=0;ikMaxEntities;i+)r=entityListi.row;c=entityListi.col;foundCrumb=-1;for(j=0;j=0)entityListi.row=entityList0.trailRowfoundCrumb;entityListi.col=entityList0.trailColfoundCrumb;elseentityListi.row=entityList0.row+Rnd(0,2)-1;entityListi.col=entityList0.col+Rnd(0,2)-1;if(entityListi.row0)entityListi.row=0;if(entityListi.col=kMaxRows)entityListi.row=kMaxRows-1;if(entityListi.col=kMaxCols)entityListi.col=kMaxCols-1;Followingtheshortestpath12,11,10,9,8,7,6,2(4)PathFollowingItisnecessarytomovecomputer-controlledcharactersinagameenvironmentinarealisticwayeventhoughtheymightnothaveanultimatedestination.没有目的地的移动Car-racinggame赛车navigatearoadwaywantthecarstostayontheroadPathFollowing2-road1-outofbounds地域分析TerrainanalysisWeneedtoanalyzethesurroundingterrainanddecideonthebestmove.分析周围的地域并决定选取最佳移动。

Weexaminealleightdirectionsandtheneliminatethosethatarenotpartoftheroad.对八个方向检测,消除不在路上的部分。

Theproblembecomesoneofdecidingwhichoftheremainingdirectionstotake.决定选取哪一个方向移动?

地域分析Terrainanalysisintr;intc;intterrainAnalysis9;r=entityListi.row;c=entityListi.col;terrainAnalysis1=terrainr-1c-1;terrainAnalysis2=terrainr-1c;terrai

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 材料科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1