/* Assassin */ /* version 1.00 */ /* by John R. Naleszkiewicz */ /* Scanning routine calls itself recursively with successively */ /* smaller scan widths until the opponent is destroyed or lost */ /* This robot is always moving to a new random point. */ /* external variables, can be used by any function */ int x,y; /* traveling toward this location */ int travelCount; /* change direction every so often */ int angle; /* angle of travel for the robot */ int hitAngle,hitRange; /* used to pin-point opponent */ int scale; /* constant used in the plot_course function */ int switch; /* scanning increment 0 = minus, 1 = plus */ /* main */ main() { scale = 100000; /* scale for trig functions */ hitAngle = 0; /* scanning angle */ switch = 0; /* scanning increment direction */ travelCount = 0; /* intialize travel count */ evade(); /* make sure movment is in the right direction */ while (1) /* loop is executed forever */ { find_n_fire(8,23); /* find the opponent and shoot */ } } /* end of main */ /* make sure the robot is moving in the right direction */ evade() { if (--travelCount || speed() < 51) { drive(angle,0); x = rand(800) + 100; y = rand(800) + 100; angle = plot_course(x,y); travelCount = 4; while(speed() > 49); drive(angle,100); } } /* end of evade */ /* scan and fire with increaseing resolution until target is lost */ find_n_fire(width, missCount) int width; /* scan width */ int missCount; /* how many scans before reversing direction */ { int width2; if (width < 2) { width = 2; evade(); } width2 = width * 2; if (switch) hitAngle -= width2 * 2; else hitAngle += width2 * 2; while ( ((hitRange = scan(nextHitAngle(width2),width)) == 0 || hitRange > 700) && --missCount ) ; if (hitRange) { cannon(hitAngle,hitRange); find_n_fire((width/2),10); } else { if (scan(nextHitAngle(13),10) == 0) { switch = !switch; nextHitAngle(13); } evade(); } } /* end of find_n_fire */ nextHitAngle(increment) int increment; { if (switch) return((hitAngle += increment)); else return((hitAngle -= increment)); } /* end of nextHitAngle */ /* plot course function, return degree heading to */ /* reach destination x, y; uses atan() trig function */ /* Improved by John R. Naleszkiewicz */ plot_course(xx,yy) int xx, yy; { int d; int x,y; int curx, cury; y = (cury = loc_y()) - yy; /* atan only returns -90 to +90, so figure out how to use */ /* the atan() value. */ /* x is zero, we either move due north or south */ if ((x = (curx = loc_x()) - xx) == 0) { if (yy > cury) d = 90; /* north */ else d = 270; /* south */ } else { if (xx < curx) d = 180 + atan((scale * y) / x); /* north/south-west, quadrant 2,3 */ else { if (yy < cury) d = 360 + atan((scale * y) / x); /* south-east, quadrant 4 */ else d = atan((scale * y) / x); /* north-east, quadrant 1 */ } } return (d); }