




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、大作业:有限状态机姓名: 班级: 学号:一、实验目的有限状态机,实现书上的蚂蚁实例二、实验仪器Pc vc6.0四、实验结果五、实验心得这次大作业做的比较简单,主要是因为没有用 mfc 做,按着书上一步一步来, 基本能看懂。因为选择了 win32,所以 main 函数的书写参考了网上的代码,全 部的代码的实现过程已经弄懂了。算法还是比较简单的,相比于前几次实验, 代码一步步在书上体现的比较全面。通过大作业的实践,对游戏人工智能有了 更新的认识,毕竟是自己建起来的程序,虽然简单,希望下次能用 mfc 实现。六、主要代码#include ant.h/#include#include#include#
2、include #include ant.cppusing namespace std;ai_World ai_EntityMainWorld; entityListkMaxEntities;intintai_Entity:ai_Entity()intterrainBackupkMaxRowskMaxCols;terrainkMaxRowskMaxCols;i;for (i=0;ikMaxEntities;i+)entityListi.row=0;entityListi.col=0;entityListi.type=0;entityListi.state=0;/* for (i=0;iKBeg
3、Ent;i+)entityListi.New(kRedAnt,)*/entityList0.New(kRedAnt,kForage,5,5); entityList1.New(kRedAnt,kForage,8,5);entityList2.New(kBlackAnt,kForage,5,36);entityList3.New(kBlackAnt,kForage,8,36);/ /ai_Entity:ai_Entity()/ /void ai_Entity:Forage(void)/intintintintintintrowMove; colMove; newRow; newCol;foodR
4、ow; foodCol;intintpoisonRow; poisonCol;rowMove=rand()%3-1;colMove=rand()%3-1;newRow=row+rowMove; newCol=col+colMove;if (newRow1) return;if (newCol=kMaxRows-1) return;if (newCol=kMaxCols-1) return;if (terrainnewRownewCol=kGround) | (terrainnewRownewCol=kWater)row=newRow; col=newCol;if (terrainnewRown
5、ewCol=kFood)row=newRow;col=newCol;terrainrowcol=kGround;state=kGoHome;do /please makesure about the begin and the end/ foodRow=rand()%(kMaxRows-3)+1; foodCol=rand()%(kMaxCols-3)+1; while (terrainfoodRowfoodCol!=kGround); terrainfoodRowfoodCol=kFood;if (terrainnewRownewCol=kPoison) row=newRow; col=ne
6、wCol; terrainrowcol=kGround; state=kDead; do poisonRow=rand()%(kMaxRows-3)+1; poisonCol=rand()%(kMaxCols-3)+1; while (terrainpoisonRowpoisonCol!=kGround); terrainpoisonRowpoisonCol=kPoison;/ /void ai_Entity:Dead(void)/ / type=0; row=0; col=0; state=0;/ /void ai_Entity:Thirsty(void)/ /introwMove;intc
7、olMove;intnewRow;intnewCol;intfoodRow;intfoodCol;intpoisonRow;intpoisonCol;rowMove=rand()%3-1;colMove=rand()%3-1;newRow=row+rowMove;newCol=col+colMove;if (newRow1) return;if (newCol=kMaxRows-1) return;if (newCol=kMaxCols-1) return;if (terrainnewRownewCol=kGround) | (terrainnewRownewCol=kFood) row=ne
8、wRow; col=newCol;if (terrainnewRownewCol=kWater)row=newRow;col=newCol;terrainrowcol=kGround;state=kForage;do foodRow=rand()%(kMaxRows-3)+1; foodCol=rand()%(kMaxCols-3)+1; while (terrainfoodRowfoodCol!=kGround); terrainfoodRowfoodCol=kWater;if (terrainnewRownewCol=kPoison)row=newRow; col=newCol;terra
9、inrowcol=kGround;state=kDead;do poisonRow=rand()%(kMaxRows-3)+1; poisonCol=rand()%(kMaxCols-3)+1; while (terrainpoisonRowpoisonCol!=kGround); terrainpoisonRowpoisonCol=kPoison;/ /void ai_Entity:GoHome(void)/ /introwMove;intcolMove;intnewRow;intnewCol;inthomeRow;inthomeCol;inti;intpoisonRow;intpoison
10、Col;if (type=kRedAnt)homeRow=kRedHomeRow; homeCol=kRedHomeCol;elsehomeRow=kBlackHomeRow; homeCol=kBlackHomeCol;if (rowhomeRow)rowMove=-1;elserowMove=0;if (colhomeCol)colMove=-1;elsecolMove=0;newRow=row+rowMove;newCol=col+colMove;if (newRow1) return;if (newCol=kMaxRows-1) return;if (newCol=kMaxCols-1
11、) return;if (terrainnewRownewCol!=kPoison)row=newRow;col=newCol;elserow=newRow;col=newCol;terrainrowcol=kGround;state=kDead;do poisonRow=rand()%(kMaxRows-3)+1; poisonCol=rand()%(kMaxCols-3)+1; while (terrainpoisonRowpoisonCol!=kGround); terrainpoisonRowpoisonCol=kPoison;if (newRow=homeRow) & (newCol
12、=homeCol)row=newRow;col=newCol;state=kThirsty;for (i=0;ikMaxEntities;i+)if (entityListi.type=0)entityListi.row=homeRow;entityListi.col=homeCol; entityListi.type=type; entityListi.state=kForage; break;/ / /void ai_Entity:New(int theType, int theState, int theRow, int theCol) / /type=theType;row=theRo
13、w;col=theCol;state=theState;/ /ai_World:ai_World()/ /inti;intj;for (i=0;ikMaxRows;i+)for (j=0;jkMaxCols;j+) terrainij=kGround;terrainkRedHomeRowkRedHomeCol=kRedHome; terrainkBlackHomeRowkBlackHomeCol=kBlackHome;for (i=0;ikMaxWater;i+) terrainrand()%(kMaxRows-3)+1rand()%(kMaxCols-3)+1=kWater;for (i=0
14、;ikMaxPoison;i+) terrainrand()%(kMaxRows-3)+1rand()%(kMaxCols-3)+1=kPoison;for (i=0;ikMaxFood;i+) terrainrand()%(kMaxRows-3)+1rand()%(kMaxCols-3)+1=kFood;/for (i=0;ikMaxRows;i+)/ for (j=0;jkMaxCols;j+)/ terrainBackupij=terrainij;/ /ai_World:ai_World()/ / /void ai_World:UpdateWorld(void)/ / int i;for
15、 (i=0;ikMaxEntities;i+)switch (entityListi.state)case kForage: entityListi.Forage(); break;case kGoHome: entityListi.GoHome(); break;case kThirsty: entityListi.Thirsty(); break;case kDead: entityListi.Dead(); break;int main()int again;doint terrain2kMaxRowskMaxCols=0;int row,col;coutGround 2-Water 3-BlackHome 4-redhome 5-poision 6-foodendl;for(int i=1;ikMaxCols;i+)for(int j=1;jkMaxRows;j+)coutterrainij;coutendl;coutthis is the ant location endl;for(int i=0;ikMaxEntities;i+) if(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- BIM在建筑项目设备与设施管理中的应用
- 云计算培训试题及答案
- 2025年皮革行业安全生产基础知识试题及答案
- 2025产科考试历年真题及答案
- 2025曹县教师考试真题及答案
- 小学教育学试题及答案
- 混凝土冻结施工技术方案
- 房屋施工现场环境管理方案
- 《餐饮服务与管理》我在五星级饭店餐厅的体验-富丽堂皇(2)(课后自测)答案版
- 面试加班看法题及答案
- 外研版-高一英语单词表-必修一默写纠正打印版-实用见效
- 2-绵阳一诊地理评讲(2021级2024届)
- 易制爆化学品防盗抢应急预案
- 医学图像存储和传输系统课件
- 手汗症的护理
- 酒店客房价格折扣规定
- 颜色科学-第二章孟塞尔颜色系统课件
- 康养文化课件
- 阿里巴巴国际站规则
- GB/T 6329-1996胶粘剂对接接头拉伸强度的测定
- GB/T 23711.2-2009氟塑料衬里压力容器耐低温试验方法
评论
0/150
提交评论