/* Hunter */ /* This robot is a modified version of Mark Davis's Topgun. */ /* It chases rather than evades. It calculates 'clicks' by */ /* dividing the distance from hitRange. */ /* by B. Thomson 11/86 */ /* external variables, that can be used by any function */ int hitAngle,hitRange; /* used to pin-point opponent */ int travelCount; /* number of 'clicks' to travel in random direction */ /* main */ main() { travelCount = 5; /* 'clicks' to travel in given direction */ hitAngle = 50; while (1) /* loop is executed forever */ { attack(); /* make sure movment is in the right direction */ scan_n_shoot(); /* scan for opponent and shoot if in range */ } } /* end of main */ /* make sure the robot is moving in the right direction */ attack() { if (--travelCount || speed() < 51) { drive(hitAngle,0); travelCount = (hitRange / 80); while(speed() > 49); drive(hitAngle,100); } } /* end of attack */ /* scan with increaseing resolution until a shot can be taken */ scan_n_shoot() { int limit; /* set the scan limit */ limit = hitAngle + 360; hitAngle -= 60; /* increased increment on hitAngle to 25 */ while (((hitRange = scan((hitAngle += 25),10)) == 0 || hitRange > 700) && hitAngle <= limit) ; if (hitRange < 200 && hitRange > 0) { cannon(hitAngle,hitRange); while ((hitRange = scan(hitAngle,10)) < 200 && hitRange > 0) cannon(hitAngle,hitRange); } else if (hitAngle <= limit) { limit = hitAngle + 20; /* altered decrement operator to norman '-=' */ hitAngle -= 30; while (((hitRange = scan((hitAngle += 10),5)) == 0 || hitRange > 700) && hitAngle <= limit) ; if (hitRange < 400 && hitRange > 0) { cannon(hitAngle,hitRange); while ((hitRange = scan(hitAngle,5)) < 400 && hitRange > 0) cannon(hitAngle,hitRange); } else if (hitAngle <= limit) { limit = hitAngle + 20; hitAngle -= 24; while (((hitRange = scan((hitAngle += 4),2)) == 0 || hitRange > 700) && hitAngle <= limit) ; if (hitRange > 0) { cannon(hitAngle,hitRange); if ((hitRange = scan((hitAngle -= 10),10)) > 0) while ( ! cannon(hitAngle,hitRange) ); /* fire again */ else if ((hitRange = scan((hitAngle += 20),10)) > 0) while ( ! cannon(hitAngle,hitRange) ); /* fire again */ } } } } /* end of scan_n_shoot */