/* AI Bots II v2.07b sample driving program * * SHOOT IMproved * */ #include "aibots.h" #include static int scandir,scanbot,scanrange; static int flagenemy; void movetoxy_ret(int,int); void movetoxy(int,int); void seekAndDestroy(); void seekAndDestroy_flag(); void look(); void seektoxy_flag(int,int); void seektoxy_all(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; } } void seekAndDestroy() { int t = 0; while(t < 10) { scan(scandir,&scanbot,&scanrange); if(scanrange == -1) { scandir += 5; t++; } else { t = 0; if(scanrange >20) move(scandir,scanrange - 12); else if(scanrange < 5) move((180 - scanrange)%360, 12 - scanrange); else if(scanrange > 12) { fire(scandir,scanrange); move(scandir,scanrange - 12); } else fire(scandir,scanrange); } } } void seekAndDestroy_flag() { int i = 0,t = 0; if(scanrange > 22) move(scandir,scanrange - 12); else if(scanrange < 5) move(scandir+120,5); else if(scanrange < 12) { fire(scandir,scanrange); move(scandir,scanrange - 12); } else fire(scandir,scanrange); while(flagenemy == scanbot || flagenemy == -1) { scan(scandir,&scanbot,&scanrange); if(scanrange == -1) { scandir += 5; i++; if( i == 50) return; } else { if(scanrange > 22) move(scandir,scanrange - 12); else if(scanrange < 5) move(scandir+120,5); else if(scanrange > 12) { fire(scandir,scanrange); move(scandir,scanrange - 12); } else fire(scandir,scanrange); t++; t %= 4; if(t == 3) { flagenemy = whohasmyflag(); } } } } void look() { scan(scandir,&scanbot,&scanrange); flagenemy = whohasmyflag(); if(flagenemy != scanbot) { fire(scandir,scanrange); scandir += 9; scandir %= 360; } else { seekAndDestroy_flag(); } } void seektoxy_flag(int x,int y) { if(flagenemy == -1) seektoxy_all(x,y); else { int ismoving; movetoxy_ret(x,y); ismoving = 1; while(ismoving) { getinfo(NULL,NULL,&ismoving,NULL,NULL,NULL); look(); } } } void seektoxy_all(int x,int y) { int ismoving; movetoxy_ret(x,y); ismoving = 1; while(ismoving) { getinfo(NULL,NULL,&ismoving,NULL,NULL,NULL); seekAndDestroy(); seekAndDestroy(); } } int main() { int ret,teamid,botid,range = 5; int x,y,x0,y0; int enemyid,ismoving; scandir = 0; ret = init("S.A.D. Bot"); botid = ret; if(botid %5 == 0) { while(1) { seektoxy_flag(24,24); seektoxy_flag(24,75); seektoxy_flag(75,75); seektoxy_flag(75,24); } } if(botid % 5 == 1) { while(1) { seektoxy_all(49,70); seektoxy_all(49,29); } } if(botid % 5 == 2) { while(1) { seektoxy_all(10,29); seektoxy_all(10,80); } } if(botid % 5 == 3) { while(1) { seektoxy_all(50,50); seektoxy_all(87,87); seektoxy_all(87,12); seektoxy_all(50,50); seektoxy_all(12,12); seektoxy_all(12,87); } } if(botid % 5 == 4) { while(1) { hisflagpos(&x,&y); movetoxy(x,y); movetoxy(x,y); if(whohashisflag() != botid) { getinfo(&x0,&y0,NULL,NULL,NULL,NULL); move(180/M_PI*(90 - atan2((float)(y - y0),(float)(x - x0))),2); movetoxy(x,y); movetoxy(x,y); } movetoxy_ret(40,10); while(whohashisflag() == botid); } } while(1) getinfo(NULL,NULL,NULL,NULL,NULL,NULL); }