人工智能课件第三次课_第1页
人工智能课件第三次课_第2页
人工智能课件第三次课_第3页
人工智能课件第三次课_第4页
人工智能课件第三次课_第5页
已阅读5页,还剩47页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

运动模式

PatternMovementThecomputer-controlledcharactersmoveaccordingtosomepredefinedpatternthatmakesitappearasthoughtheyareperformingcomplex,thought-outmaneuvers.计算机控制的人物按照某种预定的运动模式移动,好像他们执行复杂的、预先想好的策略执行。circle、square、zigzag、curve运动模式

PatternMovementThecompu1标准算法

StandardAlgorithmThestandardpatternmovementalgorithmuseslistsorarraysofencodedinstructions,orcontrolinstructions,thattellthecomputer-controlledcharacterhowtomoveeachstepthroughthegameloop.标准运动模式算法用预先编好的指令或控制指令存于列表或数组,能够指导计算机控制的人物如何在游戏循环中移动每一步。

标准算法

StandardAlgorithmThesta2控制指令数据结构

controlinstructionsdatastructureControlData{doubleturnRight;//右转doubleturnLeft;//左转doublestepForward;//前进doublestepBackward;//后退}控制指令数据结构

controlinstructions3变量说明turnRight,turnLeft//thenumberofdegrees角度stepForward,stepBackward//thenumberofdistanceunitsortiled长度变量说明turnRight,turnLeft4模式初始化

PatterninitializationPattern[0].turnRight=0;Pattern[0].turnLeft=0;Pattern[0].stepForward=2;Pattern[0].stepBackward=0;模式初始化

PatterninitializationPa5处理模式数组

ProcessingthepatternarrayVoidGameLoop(void){…Object.orientation+=Pattern[CurrentIndex].turnRight;Object.orientation-=Pattern[CurrentIndex].turnLeft;Object.x+=Pattern[CurrentIndex].stepForward;Object.x-=Pattern[CurrentIndex].stepBackward;CurrentIndex++;…}处理模式数组

Processingthepattern6基于方块的模式运动

PatternMovementintile-basedenvironmentsPathswillbemadeupoflinesegments.路径是由一些线段组成。Eachlineisonlyasegmentoftheoverallpattern.每一条线段是整个运动模式的一部分。基于方块的模式运动

PatternMovementin7初始化路径数组

InitializepatharraysVoidInitializePathArrays(void){inti;for(i=0;i<kMaxPathLength;i++){pathRow[i]=-1;pathCol[i]=-1;}}初始化路径数组

Initializepatharrays8CalculatelinesegmentVoidai_Entity::BuildPathSegment(void){inti;intnextCol=col;intnextRow=row;intdeltaRow=endRow-row;intdeltaCol=endCol-col;intstepCol;intstepRow;intcurrentStep;intfraction;inti;CalculatelinesegmentVoidai_9for(i=0;i<kMaxPathLength;i++)if((pathRow[i]==-1)&&(pathCol[i]==-1)){currentStep=i;break;}if(deltaRow<0)stepRow=-1;elsestepRow=1;if(deltaCol<0)steoCol=-1;elsestepCol=1;deltaRow=abs(deltaRow*2);deltaCol=abs(deltaCol*2);pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;for(i=0;i<kMaxPathLength;i++)10if(currentStep>=kMaxPathLength)return;if(deltaCol>deltaRow){fraction=deltaRow*2-deltaCol;while(nextCol!=endCol){if(fraction>=0){nextRow+=stepRow;fraction=fraction-deltaCol;}

if(currentStep>=kMaxPathLength11nextCol=nextCol+stepCol;fraction=fraction+deltaRow;pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;if(currentStep>=kMaxPathLength)return;}}

nextCol=nextCol+stepCol12else{fraction=deltaCol*2-deltaRow;while(nextRow!=endRow){if(fraction>=0){nextCol=nextCol+stepCol;fraction=fraction-deltaRow;}

else13nextRow=nextRow+stepRow;fraction=fraction+deltaCol;pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;if(currentStep>=kMaxPathLength)return;}}}nextRow=nextRow+stepRow;14矩形模式

RectangularpatternentityList[1].InitializaPathArrays();entityList[1].BuildPathSegment(10,3,18,3);entityList[1].BuildPathSegment(18,3,18,12);entityList[1].BuildPathSegment(18,12,10,12);entityList[1].BuildPathSegment(10,12,10,3);entityList[1].NormalizePattern();entityList[1].patternRowOffet=5;entityList[1].patternColOffet=2;矩形模式

Rectangularpatternentity15RectangularpatternmovementRectangularpatternmovement16NormalizePatternfunctionvoidai_Entity::NormalizePattern(void){inti;introwOrigin=pathRow[0];intcolOrigin=pathCol[0];for(i=0;i<kMaxPathLength;i++)if((pathRow[i]==-1)&&(pathCol[i]==-1)){pathSize=i-1;break;}for(i=0;i<=pathSize;i++){pathRow[i]=pathRow[i]-rowOrigin;pathCol[i]=pathCol[i]-colOrigin;}}NormalizePatternfunctionvoid17SimplepatrollingpatternentityList[1].InitializePathArrays();entityList[1].BuildPathSegment(10,3,18,3);entityList[1].BuildPathSegment(18,3,10,3);entityList[1].NormalizePattern();entityList[1].patternRowOffset=5;entityList[1].patternColOffset=2;Simplepatrollingpatternentit18ComplexpatrollingpatternentityList[1].BuildPathSegment(4,2,4,11);entityList[1].BuildPathSegment(4,11,2,24);entityList[1].BuildPathSegment(2,24,13,27);entityList[1].BuildPathSegment(13,27,16,24);entityList[1].BuildPathSegment(16,24,13,17);entityList[1].BuildPathSegment(13,17,13,13);entityList[1].BuildPathSegment(13,13,17,5);entityList[1].BuildPathSegment(17,5,4,2);entityList[1].NormalizePattern();entityList[1].patternRowOffset=5;entityList[1].patternColOffset=2;Complexpatrollingpatternenti19ComplextilepatternmovementComplextilepatternmovement20初始化模式矩阵

Initializepatternmatrixfor(i=0;i<kMaxRows;i++)for(j=0;j<kMaxCols;j++)pattern[i][j]=0;初始化模式矩阵

Initializepatternmat21PatternSetupBuildPatternSegment(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);PatternSetupBuildPatternSegme22Followpatternmatrixvoidai_Entity::FollowPattern(void){inti,j;intpossibleRowPath[8]={0,0,0,0,0,0,0,0};intpossibleColPath[8]={0,0,0,0,0,0,0,0};introwOffset[8]={-1,-1,-1,0,0,1,1,1};intcolOffset[8]={-1,0,1,-1,1,-1,0,1};

Followpatternmatrixvoidai_E23关于rowOffset,colOffset说明关于rowOffset,colOffset说明24j=0;for(i=0;i<8;i++)if(pattern[row+rowOffset[i]][col+colOffset[i]]==1)if(!(((row+rowOffset[i])==previousRow)&&((col+colOffset[i])==previousCol))){possibleRowPath[j]=row+rowOffset[i];possibleColPath[j]=col+colOffset[i];j++;}i=Rnd(0,j-1);//随机函数previousRow=row;previousCol=col;row=possibleRowPath[i];col=possibleColPath[i];}j=0;25实验2说明本次实验可以完成上次的实验内容。已完成上次实验,可以设计运动模式。如矩形、圆或其他模式。编写实验报告。实验2说明本次实验可以完成上次的实验内容。26运动模式

PatternMovementThecomputer-controlledcharactersmoveaccordingtosomepredefinedpatternthatmakesitappearasthoughtheyareperformingcomplex,thought-outmaneuvers.计算机控制的人物按照某种预定的运动模式移动,好像他们执行复杂的、预先想好的策略执行。circle、square、zigzag、curve运动模式

PatternMovementThecompu27标准算法

StandardAlgorithmThestandardpatternmovementalgorithmuseslistsorarraysofencodedinstructions,orcontrolinstructions,thattellthecomputer-controlledcharacterhowtomoveeachstepthroughthegameloop.标准运动模式算法用预先编好的指令或控制指令存于列表或数组,能够指导计算机控制的人物如何在游戏循环中移动每一步。

标准算法

StandardAlgorithmThesta28控制指令数据结构

controlinstructionsdatastructureControlData{doubleturnRight;//右转doubleturnLeft;//左转doublestepForward;//前进doublestepBackward;//后退}控制指令数据结构

controlinstructions29变量说明turnRight,turnLeft//thenumberofdegrees角度stepForward,stepBackward//thenumberofdistanceunitsortiled长度变量说明turnRight,turnLeft30模式初始化

PatterninitializationPattern[0].turnRight=0;Pattern[0].turnLeft=0;Pattern[0].stepForward=2;Pattern[0].stepBackward=0;模式初始化

PatterninitializationPa31处理模式数组

ProcessingthepatternarrayVoidGameLoop(void){…Object.orientation+=Pattern[CurrentIndex].turnRight;Object.orientation-=Pattern[CurrentIndex].turnLeft;Object.x+=Pattern[CurrentIndex].stepForward;Object.x-=Pattern[CurrentIndex].stepBackward;CurrentIndex++;…}处理模式数组

Processingthepattern32基于方块的模式运动

PatternMovementintile-basedenvironmentsPathswillbemadeupoflinesegments.路径是由一些线段组成。Eachlineisonlyasegmentoftheoverallpattern.每一条线段是整个运动模式的一部分。基于方块的模式运动

PatternMovementin33初始化路径数组

InitializepatharraysVoidInitializePathArrays(void){inti;for(i=0;i<kMaxPathLength;i++){pathRow[i]=-1;pathCol[i]=-1;}}初始化路径数组

Initializepatharrays34CalculatelinesegmentVoidai_Entity::BuildPathSegment(void){inti;intnextCol=col;intnextRow=row;intdeltaRow=endRow-row;intdeltaCol=endCol-col;intstepCol;intstepRow;intcurrentStep;intfraction;inti;CalculatelinesegmentVoidai_35for(i=0;i<kMaxPathLength;i++)if((pathRow[i]==-1)&&(pathCol[i]==-1)){currentStep=i;break;}if(deltaRow<0)stepRow=-1;elsestepRow=1;if(deltaCol<0)steoCol=-1;elsestepCol=1;deltaRow=abs(deltaRow*2);deltaCol=abs(deltaCol*2);pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;for(i=0;i<kMaxPathLength;i++)36if(currentStep>=kMaxPathLength)return;if(deltaCol>deltaRow){fraction=deltaRow*2-deltaCol;while(nextCol!=endCol){if(fraction>=0){nextRow+=stepRow;fraction=fraction-deltaCol;}

if(currentStep>=kMaxPathLength37nextCol=nextCol+stepCol;fraction=fraction+deltaRow;pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;if(currentStep>=kMaxPathLength)return;}}

nextCol=nextCol+stepCol38else{fraction=deltaCol*2-deltaRow;while(nextRow!=endRow){if(fraction>=0){nextCol=nextCol+stepCol;fraction=fraction-deltaRow;}

else39nextRow=nextRow+stepRow;fraction=fraction+deltaCol;pathRow[currentStep]=nextRow;pathCol[currentStep]=nextCol;currentStep++;if(currentStep>=kMaxPathLength)return;}}}nextRow=nextRow+stepRow;40矩形模式

RectangularpatternentityList[1].InitializaPathArrays();entityList[1].BuildPathSegment(10,3,18,3);entityList[1].BuildPathSegment(18,3,18,12);entityList[1].BuildPathSegment(18,12,10,12);entityList[1].BuildPathSegment(10,12,10,3);entityList[1].NormalizePattern();entityList[1].patternRowOffet=5;entityList[1].patternColOffet=2;矩形模式

Rectangularpatternentity41RectangularpatternmovementRectangularpatternmovement42NormalizePatternfunctionvoidai_Entity::NormalizePattern(void){inti;introwOrigin=pathRow[0];intcolOrigin=pathCol[0];for(i=0;i<kMaxPathLength;i++)if((pathRow[i]==-1)&&(pathCol[i]==-1)){pathSize=i-1;break;}for(i=0;i<=pathSize;i++){pathRow[i]=pathRow[i]-rowOrigin;pathCol[i]=pathCol[i]-colOrigin;}}NormalizePatternfunctionvoid43SimplepatrollingpatternentityList[1].InitializePathArrays();entityList[1].BuildPathSegment(10,3,18,3);entityList[1].BuildPathSegment(18,3,10,3);entityList[1].NormalizePattern();entityList[1].patternRowOffset=5;entityList[1].patternColOffset=2;Simplepatrollingpatternentit44ComplexpatrollingpatternentityList[1].BuildPathSegment(4,2,4,11);entityList[1].BuildPathSegment(4,11,2,24);entityList[1].BuildPathSegment(2,24,13,27);entityList[1].BuildPathSegment(13,27,16,24);entityList[1].BuildPathSegment(16,24,13,17);entityList[1].BuildPathSegment(13,17,13,13);entityList[1].BuildPathSegment(13,13,17,5);entityList[1].BuildPathSegment(17,5,4,2);entityList[1].NormalizePattern();entityList[1].patternRowOffset=5;entityList[1].patternColOffset=2;Complexpatrollingpatternenti45Com

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论