crobs/hunter.r
01 | /* Hunter */ |
02 | /* This robot is a modified version of Mark Davis's Topgun. */ |
03 | /* It chases rather than evades. It calculates 'clicks' by */ |
04 | /* dividing the distance from hitRange. */ |
05 |
06 | /* by B. Thomson 11/86 */ |
07 |
08 | /* external variables, that can be used by any function */ |
09 |
10 | int hitAngle,hitRange; /* used to pin-point opponent */ |
11 | int travelCount; /* number of 'clicks' to travel in random direction */ |
12 |
13 | /* main */ |
14 | main() |
15 | { |
16 | travelCount = 5; /* 'clicks' to travel in given direction */ |
17 | hitAngle = 50; |
18 | while (1) /* loop is executed forever */ |
19 | { |
20 | attack(); /* make sure movment is in the right direction */ |
21 | scan_n_shoot(); /* scan for opponent and shoot if in range */ |
22 | } |
23 |
24 | } /* end of main */ |
25 |
26 |
27 | /* make sure the robot is moving in the right direction */ |
28 | attack() |
29 | { |
30 | if (--travelCount || speed() < 51) |
31 | { |
32 | drive(hitAngle,0); |
33 | travelCount = (hitRange / 80); |
34 | while (speed() > 49); |
35 | drive(hitAngle,100); |
36 | } |
37 | } /* end of attack */ |
38 |
39 | /* scan with increaseing resolution until a shot can be taken */ |
40 | scan_n_shoot() |
41 | { |
42 | int limit; /* set the scan limit */ |
43 |
44 | limit = hitAngle + 360; |
45 | hitAngle -= 60; |
46 | /* increased increment on hitAngle to 25 */ |
47 | while (((hitRange = scan((hitAngle += 25),10)) == 0 || hitRange > 700) && hitAngle <= limit) |
48 | ; |
49 |
50 | if (hitRange < 200 && hitRange > 0) |
51 | { |
52 | cannon(hitAngle,hitRange); |
53 | while ((hitRange = scan(hitAngle,10)) < 200 && hitRange > 0) |
54 | cannon(hitAngle,hitRange); |
55 | } |
56 | else |
57 | if (hitAngle <= limit) |
58 | { |
59 | limit = hitAngle + 20; |
60 | /* altered decrement operator to norman '-=' */ |
61 | hitAngle -= 30; |
62 | while (((hitRange = scan((hitAngle += 10),5)) == 0 || hitRange > 700) && hitAngle <= limit) |
63 | ; |
64 |
65 | if (hitRange < 400 && hitRange > 0) |
66 | { |
67 | cannon(hitAngle,hitRange); |
68 | while ((hitRange = scan(hitAngle,5)) < 400 && hitRange > 0) |
69 | cannon(hitAngle,hitRange); |
70 | } |
71 | else |
72 | if (hitAngle <= limit) |
73 | { |
74 | limit = hitAngle + 20; |
75 | hitAngle -= 24; |
76 | while (((hitRange = scan((hitAngle += 4),2)) == 0 || hitRange > 700) && hitAngle <= limit) |
77 | ; |
78 |
79 | if (hitRange > 0) |
80 | { |
81 | cannon(hitAngle,hitRange); |
82 | if ((hitRange = scan((hitAngle -= 10),10)) > 0) |
83 | while ( ! cannon(hitAngle,hitRange) ); /* fire again */ |
84 | else |
85 | if ((hitRange = scan((hitAngle += 20),10)) > 0) |
86 | while ( ! cannon(hitAngle,hitRange) ); /* fire again */ |
87 | } |
88 | } |
89 | } |
90 | } /* end of scan_n_shoot */ |
91 | ��������������� |