第一范文网 - 专业文章范例文档资料分享平台

有限状态机

来源:用户分享 时间:2026/8/31 14:40:19 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

大作业:有限状态机

姓名:

班级: 学号:

一、实验目的

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

二、实验仪器

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; }

搜索更多关于: 有限状态机 的文档
有限状态机.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6ki4069gyt2xn8u9vo3r_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top