欢迎来到天天文库
浏览记录
ID:26285583
大小:115.00 KB
页数:29页
时间:2018-11-26
《蚂蚁算法 源代码如下》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、源代码如下:/*ant.c*/#defineSPACE0x20#defineESC0x1b#defineANT_CHAR_EMPTY'+'#defineANT_CHAR_FOOD153#defineHOME_CHAR'H'#defineFOOD_CHAR'F'#defineFOOD_CHAR2'f'#defineFOOD_HOME_COLOR12#defineBLOCK_CHAR177#defineMAX_ANT50#defineINI_SPEED3#defineMAXX80#defineMAXY23#defineMAX_FOOD10000#defi
2、neTARGET_FOOD200#defineMAX_SMELL5000#defineSMELL_DROP_RATE0.05#defineANT_ERROR_RATE0.02#defineANT_EYESHOT3#defineSMELL_GONE_SPEED50#defineSMELL_GONE_RATE0.05#defineTRACE_REMEMBER50#defineMAX_BLOCK100#defineNULL0#defineUP1#defineDOWN2#defineLEFT3#defineRIGHT4#defineSMELL_TYPE_FO
3、OD0#defineSMELL_TYPE_HOME1#include"stdio.h"#include"conio.h"#include"dos.h"#include"stdlib.h"#include"dos.h"#include"process.h"#include"ctype.h"#include"math.h"voidWorldInitial(void);voidBlockInitial(void);voidCreatBlock(void);voidSaveBlock(void);voidLoadBlock(void);voidHomeFoo
4、dInitial(void);voidAntInitial(void);voidWorldChange(void);voidAntMove(void);voidAntOneStep(void);voidDealKey(charkey);voidClearSmellDisp(void);voidDispSmell(inttype);intAntNextDir(intxxx,intyyy,intddir);intGetMaxSmell(inttype,intxxx,intyyy,intddir);intIsTrace(intxxx,intyyy);int
5、MaxLocation(intnum1,intnum2,intnum3);intCanGo(intxxx,intyyy,intddir);intJudgeCanGo(intxxx,intyyy);intTurnLeft(intddir);intTurnRight(intddir);intTurnBack(intddir);intMainTimer(void);charWaitForKey(intsecnum);voidDispPlayTime(void);intTimeUse(void);voidHideCur(void);voidResetCur(
6、void);/*---------------*/structHomeStruct{intxxx,yyy;intamount;intTargetFood;}home;structFoodStruct{intxxx,yyy;intamount;}food;structAntStruct{intxxx,yyy;intdir;intspeed;intSpeedTimer;intfood;intSmellAmount[2];inttracex[TRACE_REMEMBER];inttracey[TRACE_REMEMBER];intTracePtr;intI
7、Q;}ant[MAX_ANT];intAntNow;inttimer10ms;structtimestarttime,endtime;intSmell[2][MAXX+1][MAXY+1];intblock[MAXX+1][MAXY+1];intSmellGoneTimer;intSmellDispFlag;intCanFindFood;intHardtoFindPath;/*-----Main--------*/voidmain(void){charKeyPress;inttu;clrscr();HideCur();WorldInitial();d
8、o{timer10ms=MainTimer();if(timer10ms)AntMove();if(time
此文档下载收益归作者所有