有限状态机 联系客服

发布时间 : 星期日 文章有限状态机更新完毕开始阅读a85eb0a084254b35eefd34c7

大作业:有限状态机

姓名:

班级: 学号:

一、实验目的

有限状态机,实现书上的蚂蚁实例

二、实验仪器

Pc vc6.0

四、实验结果

五、实验心得

这次大作业做的比较简单,主要是因为没有用mfc做,按着书上一步一步来,基本能看懂。因为选择了win32,所以main函数的书写参考了网上的代码,全部的代码的实现过程已经弄懂了。算法还是比较简单的,相比于前几次实验,代码一步步在书上体现的比较全面。通过大作业的实践,对游戏人工智能有了更新的认识,毕竟是自己建起来的程序,虽然简单,希望下次能用mfc实现。

六、主要代码

#include \

//#include #include #include #include #include \

using namespace std;

ai_World ai_Entity

MainWorld;

entityList[kMaxEntities];

int terrainBackup[kMaxRows][kMaxCols]; int terrain[kMaxRows][kMaxCols];

ai_Entity::ai_Entity() { int i; for (i=0;i

/* for (i=0;i

entityList[i].New(kRedAnt,) } */ entityList[0].New(kRedAnt,kForage,5,5); entityList[1].New(kRedAnt,kForage,8,5); entityList[2].New(kBlackAnt,kForage,5,36); entityList[3].New(kBlackAnt,kForage,8,36); }

// ----------------------------------------------------------------- // ai_Entity::~ai_Entity()

// ----------------------------------------------------------------- // { }

// ----------------------------------------------------------------- //

void ai_Entity::Forage(void)

// ----------------------------------------------------------------- // { int rowMove; int colMove; int newRow; int newCol; int foodRow; int foodCol; int poisonRow; int poisonCol; rowMove=rand()%3-1; colMove=rand()%3-1; newRow=row+rowMove; newCol=col+colMove; if (newRow<1) return; if (newCol<1) return; if (newRow>=kMaxRows-1) return; if (newCol>=kMaxCols-1) return; if ((terrain[newRow][newCol]==kGround) || (terrain[newRow][newCol]==kWater)) { row=newRow; col=newCol; } if (terrain[newRow][newCol]==kFood) { row=newRow; col=newCol; terrain[row][col]=kGround; state=kGoHome; do { /////////////////////please makesure about the begin and the end////////// foodRow=rand()%(kMaxRows-3)+1; foodCol=rand()%(kMaxCols-3)+1; } while (terrain[foodRow][foodCol]!=kGround); terrain[foodRow][foodCol]=kFood; }