/* AI Bots II v2.08 sample driving program * * Catch me if you can. * */ #include "aibots.h" #include static int scandir,scanbot,scanrange; static int flagenemy; void movetoxy_ret(int,int); void movetoxy(int,int); void movetoxy_ret(int x,int y) { int x0,y0,dx,dy,dir,range,ismoving; getinfo(&x0,&y0,NULL,NULL,NULL,NULL); dx = x - x0; dy = y - y0; range = (int) sqrt(dx*dx +dy*dy); dir = (int) (atan2((float)dy,(float)dx)/M_PI*180.0); move(dir,range); } void movetoxy(int x,int y) { int ismoving = 1; movetoxy_ret(x,y); while(ismoving) { getinfo(NULL,NULL,&ismoving,NULL,NULL,NULL); scan(scandir,&scanbot,&scanrange); if(scanrange > 4 && scanrange <23) fire(scandir,scanrange); else scandir += 5; } } int diffdir(int dir1,int dir2) { int diff; int temp1,temp2; dir1 %= 360; dir2 %= 360; if(dir1 > dir2) { diff = dir1 - dir2; if(diff > 180) return (360 - diff); else return (-diff); } diff = dir2 - dir1; if(diff > 180) return (diff - 360); else return diff; } int main() { int ret,teamid,botid,range = 5; int x,y,x0,y0,fx,fy,efx,efy; float dx,dy; int enemyid,ismoving; int nextbot; int ang; int shotcount; unsigned long gtime; scandir = 0; botid = init("Catch me"); shotcount = 0; gtime = 0; ismoving = 1; hisflagpos(&efx,&efy); if(botid % 5 <= 4) { while(1) { while(ismoving) { scan(scandir,&scanbot,&scanrange); if(scanrange > 4 && scanrange < 26) { if(fire(scandir,scanrange)) { shotcount++; if(shotcount % 20 == 0 && gtime > 70000) printf("Catch me %d: %d\n",botid,shotcount); } } else if(scanrange == -1) { scandir += 10; scandir %= 360; } getinfo(&x,&y,&ismoving,NULL,NULL,>ime); ang = (int) ( atan2( (float)(y - 50), (float)(x - 50) )*180.0/M_PI); dx = (float)(x0 - x); dy = (float)(y0 - y); if( (dx * dx + dy * dy) < 4.5) ismoving = 0; } ang += 19; ang %= 360; x0 = efx + (int) (40.5 * cos( ( (float)ang ) * M_PI/180.0)); y0 = efy - 40 + (int) (40.5 * sin( ( (float)ang ) * M_PI/180.0)); movetoxy_ret(x0,y0); ismoving = 1; hisflagpos(&x,&y); if(x != -1) { efx = x; efy = y; } } } }