资源简介
蚁群算法路径规划蚁群算法路径规划蚁群算法路径规划
代码片段和文件信息
#define SPACE 0x20
#define ESC 0x1b
#define ANT_CHAR_EMPTY ‘+‘
#define ANT_CHAR_FOOD 153
#define HOME_CHAR ‘H‘
#define FOOD_CHAR ‘F‘
#define FOOD_CHAR2 ‘f‘
#define FOOD_HOME_COLOR 12
#define BLOCK_CHAR 177
#define MAX_ANT 50
#define INI_SPEED 3
#define MAXX 80
#define MAXY 23
#define MAX_FOOD 10000
#define TARGET_FOOD 200
#define MAX_SMELL 5000
#define SMELL_DROP_RATE 0.05
#define ANT_ERROR_RATE 0.02
#define ANT_EYESHOT 3
#define SMELL_GONE_SPEED 50
#define SMELL_GONE_RATE 0.05
#define TRACE_REMEMBER 50
#define MAX_BLOCK 100
#define NULL 0
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define SMELL_TYPE_FOOD 0
#define SMELL_TYPE_HOME 1
#include “stdio.h“
#include “conio.h“
#include “dos.h“
#include “stdlib.h“
#include “dos.h“
#include “process.h“
#include “ctype.h“
#include “math.h“
void WorldInitial(void);
void BlockInitial(void);
void CreatBlock(void);
void SaveBlock(void);
void LoadBlock(void);
void HomeFoodInitial(void);
void AntInitial(void);
void WorldChange(void);
void AntMove(void);
void AntOneStep(void);
void DealKey(char key);
void ClearSmellDisp(void);
void DispSmell(int type);
int AntNextDir(int xxxint yyyint ddir);
int GetMaxSmell(int typeint xxxint yyyint ddir);
int IsTrace(int xxxint yyy);
int MaxLocation(int num1int num2int num3);
int CanGo(int xxxint yyyint ddir);
int JudgeCanGo(int xxxint yyy);
int TurnLeft(int ddir);
int TurnRight(int ddir);
int TurnBack(int ddir);
int MainTimer(void);
char WaitForKey(int secnum);
void DispPlayTime(void);
int TimeUse(void);
void HideCur(void);
void ResetCur(void);
/* --------------- */
struct HomeStruct
{
int xxxyyy;
int amount;
int TargetFood;
}home;
struct FoodStruct
{
int xxxyyy;
int amount;
}food;
struct AntStruct
{
int xxxyyy;
int dir;
int speed;
int SpeedTimer;
int food;
int SmellAmount[2];
int tracex[TRACE_REMEMBER];
int tracey[TRACE_REMEMBER];
int TracePtr;
int IQ;
}ant[MAX_ANT];
int AntNow;
int timer10ms;
struct time starttimeendtime;
int Smell[2][MAXX+1][MAXY+1];
int block[MAXX+1][MAXY+1];
int SmellGoneTimer;
int SmellDispFlag;
int CanFindFood;
int HardtoFindPath;
/* ----- Main -------- */
void main(void)
{
char KeyPress;
int tu;
clrscr();
HideCur();
WorldInitial();
do
{
timer10ms = MainTimer();
if(timer10ms) AntMove();
if(timer10ms) WorldChange();
tu = TimeUse();
if(tu>=60&&!CanFindFood)
{
gotoxy(1MAXY+1);
printf(“Can not find food maybe a block world.“);
WaitForKey(10);
WorldInitial();
}
if(tu>=180&&home.amount<100&&!HardtoFindPath)
{
gotoxy(1MAXY+1);
printf(“God! it is so difficult to find a path.“);
if(WaitForKey(10)==0x0d) WorldInitial();
else
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 32548 2006-01-03 19:16 ant.c
文件 75316 2006-01-03 19:16 ANT.EXE
文件 6546 2005-04-26 11:35 ant_doc.txt
- 上一篇:改进粒子群算法对BP神经网络的优化
- 下一篇:pan.txt
评论
共有 条评论