人工智能课件第三次课.ppt
《人工智能课件第三次课.ppt》由会员分享,可在线阅读,更多相关《人工智能课件第三次课.ppt(26页珍藏版)》请在冰点文库上搜索。
运动模式PatternMovement,Thecomputer-controlledcharactersmoveaccordingtosomepredefinedpatternthatmakesitappearasthoughtheyareperformingcomplex,thought-outmaneuvers.计算机控制的人物按照某种预定的运动模式移动,好像他们执行复杂的、预先想好的策略执行。
circle、square、zigzag、curve,标准算法StandardAlgorithm,Thestandardpatternmovementalgorithmuseslistsorarraysofencodedinstructions,orcontrolinstructions,thattellthecomputer-controlledcharacterhowtomoveeachstepthroughthegameloop.标准运动模式算法用预先编好的指令或控制指令存于列表或数组,能够指导计算机控制的人物如何在游戏循环中移动每一步。
控制指令数据结构controlinstructionsdatastructure,ControlDatadoubleturnRight;/右转doubleturnLeft;/左转doublestepForward;/前进doublestepBackward;/后退,变量说明,turnRight,turnLeft/thenumberofdegrees角度stepForward,stepBackward/thenumberofdistanceunitsortiled长度,模式初始化Patterninitialization,Pattern0.turnRight=0;Pattern0.turnLeft=0;Pattern0.stepForward=2;Pattern0.stepBackward=0;,处理模式数组Processingthepatternarray,VoidGameLoop(void)Object.orientation+=PatternCurrentIndex.turnRight;Object.orientation-=PatternCurrentIndex.turnLeft;Object.x+=PatternCurrentIndex.stepForward;Object.x-=PatternCurrentIndex.stepBackward;CurrentIndex+;,基于方块的模式运动PatternMovementintile-basedenvironments,Pathswillbemadeupoflinesegments.路径是由一些线段组成。
Eachlineisonlyasegmentoftheoverallpattern.每一条线段是整个运动模式的一部分。
初始化路径数组Initializepatharrays,VoidInitializePathArrays(void)inti;for(i=0;ikMaxPathLength;i+)pathRowi=-1;pathColi=-1;,Calculatelinesegment,Voidai_Entity:
BuildPathSegment(void)inti;intnextCol=col;intnextRow=row;intdeltaRow=endRow-row;intdeltaCol=endCol-col;intstepCol;intstepRow;intcurrentStep;intfraction;inti;,for(i=0;ikMaxPathLength;i+)if(pathRowi=-1),if(currentStep=kMaxPathLength)return;if(deltaColdeltaRow)fraction=deltaRow*2-deltaCol;while(nextCol!
=endCol)if(fraction=0)nextRow+=stepRow;fraction=fraction-deltaCol;,nextCol=nextCol+stepCol;fraction=fraction+deltaRow;pathRowcurrentStep=nextRow;pathColcurrentStep=nextCol;currentStep+;if(currentStep=kMaxPathLength)return;,elsefraction=deltaCol*2-deltaRow;while(nextRow!
=endRow)if(fraction=0)nextCol=nextCol+stepCol;fraction=fraction-deltaRow;,nextRow=nextRow+stepRow;fraction=fraction+deltaCol;pathRowcurrentStep=nextRow;pathColcurrentStep=nextCol;currentStep+;if(currentStep=kMaxPathLength)return;,矩形模式Rectangularpattern,entityList1.InitializaPathArrays();entityList1.BuildPathSegment(10,3,18,3);entityList1.BuildPathSegment(18,3,18,12);entityList1.BuildPathSegment(18,12,10,12);entityList1.BuildPathSegment(10,12,10,3);entityList1.NormalizePattern();entityList1.patternRowOffet=5;entityList1.patternColOffet=2;,Rectangularpatternmovement,NormalizePatternfunction,voidai_Entity:
NormalizePattern(void)inti;introwOrigin=pathRow0;intcolOrigin=pathCol0;for(i=0;ikMaxPathLength;i+)if(pathRowi=-1),Simplepatrollingpattern,entityList1.InitializePathArrays();entityList1.BuildPathSegment(10,3,18,3);entityList1.BuildPathSegment(18,3,10,3);entityList1.NormalizePattern();entityList1.patternRowOffset=5;entityList1.patternColOffset=2;,Complexpatrollingpattern,entityList1.BuildPathSegment(4,2,4,11);entityList1.BuildPathSegment(4,11,2,24);entityList1.BuildPathSegment(2,24,13,27);entityList1.BuildPathSegment(13,27,16,24);entityList1.BuildPathSegment(16,24,13,17);entityList1.BuildPathSegment(13,17,13,13);entityList1.BuildPathSegment(13,13,17,5);entityList1.BuildPathSegment(17,5,4,2);entityList1.NormalizePattern();entityList1.patternRowOffset=5;entityList1.patternColOffset=2;,Complextilepatternmovement,初始化模式矩阵Initializepatternmatrix,for(i=0;ikMaxRows;i+)for(j=0;jkMaxCols;j+)patternij=0;,PatternSetup,BuildPatternSegment(3,2,16,2);BuildPatternSegment(16,2,16,11);BuildPatternSegment(16,11,9,11);BuildPatternSegment(9,11,9,6);BuildPatternSegment(9,6,3,6);BuildPatternSegment(3,6,3,2);,Followpatternmatrix,voidai_Entity:
FollowPattern(void)inti,j;intpossibleRowPath8=0,0,0,0,0,0,0,0;intpossibleColPath8=0,0,0,0,0,0,0,0;introwOffset8=-1,-1,-1,0,0,1,1,1;intcolOffset8=-1,0,1,-1,1,-1,0,1;,关于rowOffset,colOffset说明,j=0;for(i=0;i8;i+)if(patternrow+rowOffseticol+colOffseti=1)if(!
(row+rowOffseti)=previousRow),实验2说明,本次实验可以完成上次的实验内容。
已完成上次实验,可以设计运动模式。
如矩形、圆或其他模式。
编写实验报告。