/* Ravi Prakash 2nd Year CSE, 2005 Amity School Of Engg. & Tech. */ int nrobots, opt_safe_dist, r1x, r1y, r2x, r2y, r3x, r3y; int slowb4, tolerance, resol, edgetol; /* nrobots = 1-3 -> There are 1-3 other robots than mine = 4-7 -> Assume that there are 1-3 other robots = 8 -> Find out for yourself opt_safe_dist -> Distance at which I have to move tangentially from enemy slowb4 -> Square of the distance at which I have to slow down tolerance -> Square of the distance within which moveto() returns resol -> Resolution at which scanning is done while moving edgetol -> Tolerance of edge when scanning */ /*Move to position x,y */ getangle(x,y) { int deg; if(x-loc_x()!=0) deg=atan( (100000*(y-loc_y()))/(x-loc_x()) ); else if(y>loc_y()) deg=90; else deg=270; if(xslowb4) { deg=getangle(x,y); drive(deg,100); find=scan(toshoot, resol); if(find!=0 && find<=700) cannon(toshoot, find); toshoot+=2*resol; dist = (x-loc_x())*(x-loc_x())+(y-loc_y())*(y-loc_y()); } while(dist>tolerance) { speed=sqrt(dist); /*Function to slow down as distance to x,y decreases */ deg=getangle(x,y); drive(deg, speed); dist = (x-loc_x())*(x-loc_x())+(y-loc_y())*(y-loc_y()); } drive(deg,0); }/*End of moveto() */ /*takes resolution of scan and stores enemy positions and no. of enemies in notoret in global variables*/ getenempos(res, notoret) { int startdeg, enddeg, nenem; nenem=0; if(loc_x()999-edgetol) {startdeg=270;enddeg=360;} else {startdeg=270;enddeg=450;} } else if(loc_x()>999-edgetol) { if(loc_y()999-edgetol) {startdeg=180;enddeg=270;} else {startdeg=90;enddeg=270;} } else if(loc_y()999-edgetol) {startdeg=180;enddeg=360;} else {startdeg=0;enddeg=359;} while(startdeg90&°<270) danger=1; if(loc_x()>999-slowb4 && ((deg<0&°<90)||(deg>270&°<360))) danger=1; if(loc_y()180&°<360) danger=1; if(loc_y()>999-slowb4 &°>0&°<180) danger=1; if(danger==0) drive(deg, speed); }/*End of safedrive()*/ scanaround(angle, range, reso) { int st, en, found; if(range>360) range=360; st=angle-range/2; found=0; while(st=opt_safe_dist*2) { range=15; reso=2; toadd=0; while(scanaround(getangle(r1x, r1y)+toadd, range, reso)==0) /*If not found in 1 scan then rescan with wider range */ { range*=4; reso=5; toadd=0; } safedrive(getangle(r1x, r1y), 100); dist=(r1x-loc_x())*(r1x-loc_x())+(r1y-loc_y())*(r1y-loc_y()); } while(distopt_safe_dist) { reso=5; range=30;toadd=0; while(scanaround(getangle(r1x, r1y)+toadd, range, reso)==0) /*If not found in 1 scan then rescan with wider range */ { range*=4; reso=10; toadd=0; } safedrive(getangle(r1x, r1y), 50); dist=(r1x-loc_x())*(r1x-loc_x())+(r1y-loc_y())*(r1y-loc_y()); } while(dist<=opt_safe_dist) { reso=10; range=30;toadd=0; while(scanaround(getangle(r1x, r1y)+toadd, range, reso)==0) /*If not found in 1 scan then rescan with wider range */ { range*=4; reso=10; toadd=0; } safedrive(getangle(r1x, r1y)+90,50); dist=(r1x-loc_x())*(r1x-loc_x())+(r1y-loc_y())*(r1y-loc_y()); } }/*End of onlyone()*/ /* nrobots = 1-3 -> There are 1-3 other robots than mine = 4-7 -> Assume that there are 1-3 other robots = 8 -> Find out for yourself opt_safe_dist -> Square of the distance at which I have to move tangentially from enemy slowb4 -> Square of the distance at which I have to slow down tolerance -> Square of the distance within which moveto() returns resol -> Resolution at which scanning is done while moving edgetol -> Tolerance of edge when scanning */ main() { nrobots=1; opt_safe_dist=40000; slowb4=60; tolerance=20; edgetol=50; resol=10; onlyone(); }/*End of main*/ /* Ravi Prakash 2nd Year CSE, 2005 Amity School Of Engg. & Tech. */