/* PINGPONG.R */ /* A Crobot by Robert Osorio - 71676,434 */ /* This is a non-minimal robot designed to destroy minimal robots. PINGPONG.R is built around Tom Poindexter's SNIPER.R robot. PINGPONG.R was designed to beat Steve Glynn's minimal robot T.R and also works well against minimal robot HAK3.R by John Hardin. STRATEGY: PINGPONG.R takes advantage of T.R's single-minded nature and forces T.R into the center of the battle field by bouncing back and forth between two opposite corners. Since T.R always follows directly behind it's opponent, PINGPONG.R can always expect to find T.R directly ahead or behind it's movement heading as it bounces back and forth. PINGPONG.R never bothers scanning any direction other than it's present heading and 180 degrees opposite it's present heading. */ int corner; /* current corner 0, 1, 2, or 2 */ int c1x, c1y; /* corner 1 x and y */ int c2x, c2y; /* " 2 " " " */ int c3x, c3y; /* " 3 " " " */ int c4x, c4y; /* " 4 " " " */ int s1, s2, s3, s4; /* starting scan position for corner 1 - 4 */ int sc; /* current scan start */ int d; main() { /* initialize the corner info */ /* x and y location of a corner */ c1x = 10; c1y = 10; s1 = 5; c2x = 10; c2y = 990; s2 = 275; c3x = 990; c3y = 990; s3 = 185; c4x = 990; c4y = 10; s4 = 95; corner = 2; while (1) { if (corner == 0) corner = 2; else corner = 0; new_corner(); } } /* end of main */ /* new corner function to move to a different corner */ new_corner() { int x, y; int angle; int new; int vector; int far; if (corner == 0) { /* set new x,y and scan start */ x = c1x; y = c1y; sc = s1; } if (corner == 1) { x = c2x; y = c2y; sc = s2; } if (corner == 2) { x = c3x; y = c3y; sc = s3; } if (corner == 3) { x = c4x; y = c4y; sc = s4; } angle = plot_course(x,y); drive(angle,100); while (distance(loc_x(),loc_y(),x,y) > 100 && speed() > 0) { vector = angle + 180; far = scan (vector,5); if (far > 0) { far -= 10; cannon (vector,far); } far = scan (angle,5); if (far > 0) { far -= 15; cannon (angle,far); } } drive(angle,20); while (distance(loc_x(),loc_y(),x,y) > 10 && speed() > 0) { vector = angle + 180; far = scan (vector,5); if (far > 0) cannon (vector,far); } drive(angle,0); } /* end of new_corner */ /* classical pythagorean distance formula */ distance(x1,y1,x2,y2) int x1; int y1; int x2; int y2; { int x, y; x = x1 - x2; y = y1 - y2; d = sqrt((x*x) + (y*y)); return(d); } /* plot course function, return degree heading to */ /* reach destination x, y; uses atan() trig function */ plot_course(xx,yy) int xx, yy; { int d; int x,y; int scale; int curx, cury; scale = 100000; /* scale for trig functions */ curx = loc_x(); /* get current location */ cury = loc_y(); x = curx - xx; y = cury - yy; /* atan only returns -90 to +90, so figure out how to use */ /* the atan() value */ if (x == 0) { /* x is zero, we either move due north or south */ if (yy > cury) d = 90; /* north */ else d = 270; /* south */ } else { if (yy < cury) { if (xx > curx) d = 360 + atan((scale * y) / x); /* south-east, quadrant 4 */ else d = 180 + atan((scale * y) / x); /* south-west, quadrant 3 */ } else { if (xx > curx) d = atan((scale * y) / x); /* north-east, quadrant 1 */ else d = 180 + atan((scale * y) / x); /* north-west, quadrant 2 */ } } return (d); }