自控第一章课件
自控第一章课件 /*ant.c*/ #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 xxx,int yyy,int ddir); int GetMaxSmell(int type,int xxx,int yyy,int ddir); int IsTrace(int xxx,int yyy); int MaxLocation(int num1,int num2,int num3); int CanGo(int xxx,int yyy,int ddir); int JudgeCanGo(int xxx,int 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 xxx,yyy; int amount; int TargetFood; }home; struct FoodStruct { int xxx,yyy; int amount; }food; struct AntStruct { int xxx,yyy; 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 starttime,endtime; int Smell[2][MAXX+1][MAXY+1]; int block[MAXX+1][MAXY+1]; int SmellGoneTimer; int SmellDispFlag; int CanFindFood; #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 xxx,int yyy,int ddir); int GetMaxSmell(int type,int xxx,int yyy,int ddir); int IsTrace(int xxx,int yyy); int MaxLocation(int num1,int num2,int num3); int CanGo(int xxx,int yyy,int ddir); int JudgeCanGo(int xxx,int 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 xxx,yyy; int amount; int TargetFood; }home; struct FoodStruct { int xxx,yyy; int amount; }food; struct AntStruct { int xxx,yyy; 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 starttime,endtime; int Smell[2][MAXX+1][MAXY+1]; int block[MAXX+1][MAXY+1]; int SmellGoneTimer; int SmellDispFlag; int CanFindFood;