人工智能課件第三次課_第1頁
人工智能課件第三次課_第2頁
人工智能課件第三次課_第3頁
人工智能課件第三次課_第4頁
人工智能課件第三次課_第5頁
已閱讀5頁,還剩47頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

運動模式

PatternMovementThecomputer-controlledcharactersmoveaccordingtosomepredefinedpatternthatmakesitappearasthoughtheyareperformingcomplex,thought-outmaneuvers.計算機控制的人物按照某種預定的運動模式移動,好像他們執(zhí)行復雜的、預先想好的策略執(zhí)行。circle、square、zigzag、curve運動模式

PatternMovementThecompu1標準算法

StandardAlgorithmThestandardpatternmovementalgorithmuseslistsorarraysofencodedinstructions,orcontrolinstructions,thattellthecomputer-controlledcharacterhowtomoveeachstepthroughthegameloop.標準運動模式算法用預先編好的指令或控制指令存于列表或數(shù)組,能夠指導計算機控制的人物如何在游戲循環(huán)中移動每一步。

標準算法

StandardAlgorithmThesta2控制指令數(shù)據(jù)結構

controlinstructionsdatastructureControlData{doubleturnRight;//右轉(zhuǎn)doubleturnLeft;//左轉(zhuǎn)doublestepForward;//前進doublestepBackward;//后退}控制指令數(shù)據(jù)結構

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處理模式數(shù)組

ProcessingthepatternarrayVoidGameLoop(void){…Object.orientation+=Pattern[CurrentIndex].turnRight;Object.orientation-=Pattern[CurrentIndex].turnLeft;Object.x+=Pattern[CurrentIndex].stepForward;Object.x-=Pattern[CurrentIndex].stepBackward;CurrentIndex++;…}處理模式數(shù)組

Processingthepattern6基于方塊的模式運動

PatternMovementintile-basedenvironmentsPathswillbemadeupoflinesegments.路徑是由一些線段組成。Eachlineisonlyasegmentoftheoverallpattern.每一條線段是整個運動模式的一部分?;诜綁K的模式運動

PatternMovementin7初始化路徑數(shù)組

InitializepatharraysVoidInitializePathArrays(void){inti;for(i=0;i<kMaxPathLength;i++){pathRow[i]=-1;pathCol[i]=-1;}}初始化路徑數(shù)組

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);//隨機函數(shù)previousRow=row;previousCol=col;row=possibleRowPath[i];col=possibleColPath[i];}j=0;25實驗2說明本次實驗可以完成上次的實驗內(nèi)容。已完成上次實驗,可以設計運動模式。如矩形、圓或其他模式。編寫實驗報告。實驗2說明本次實驗可以完成上次的實驗內(nèi)容。26運動模式

PatternMovementThecomputer-controlledcharactersmoveaccordingtosomepredefinedpatternthatmakesitappearasthoughtheyareperformingcomplex,thought-outmaneuvers.計算機控制的人物按照某種預定的運動模式移動,好像他們執(zhí)行復雜的、預先想好的策略執(zhí)行。circle、square、zigzag、curve運動模式

PatternMovementThecompu27標準算法

StandardAlgorithmThestandardpatternmovementalgorithmuseslistsorarraysofencodedinstructions,orcontrolinstructions,thattellthecomputer-controlledcharacterhowtomoveeachstepthroughthegameloop.標準運動模式算法用預先編好的指令或控制指令存于列表或數(shù)組,能夠指導計算機控制的人物如何在游戲循環(huán)中移動每一步。

標準算法

StandardAlgorithmThesta28控制指令數(shù)據(jù)結構

controlinstructionsdatastructureControlData{doubleturnRight;//右轉(zhuǎn)doubleturnLeft;//左轉(zhuǎn)doublestepForward;//前進doublestepBackward;//后退}控制指令數(shù)據(jù)結構

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處理模式數(shù)組

ProcessingthepatternarrayVoidGameLoop(void){…Object.orientation+=Pattern[CurrentIndex].turnRight;Object.orientation-=Pattern[CurrentIndex].turnLeft;Object.x+=Pattern[CurrentIndex].stepForward;Object.x-=Pattern[CurrentIndex].stepBackward;CurrentIndex++;…}處理模式數(shù)組

Processingthepattern32基于方塊的模式運動

PatternMovementintile-basedenvironmentsPathswillbemadeupoflinesegments.路徑是由一些線段組成。Eachlineisonlyasegmentoftheoverallpattern.每一條線段是整個運動模式的一部分。基于方塊的模式運動

PatternMovementin33初始化路徑數(shù)組

InitializepatharraysVoidInitializePathArrays(void){inti;for(i=0;i<kMaxPathLength;i++){pathRow[i]=-1;pathCol[i]=-1;}}初始化路徑數(shù)組

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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論