crobs/squirrel.r

01/* counter */
02/* scan in a counter-clockwise direction (increasing degrees) */
03/* moves when hit */
04 
05main()
06{
07  int angle, range;
08  int res;
09  register int d;
10  long i;
11 
12  res = 3;
13  d = damage();
14  angle = rand(360);
15  while(1) {
16    while ((range = scan(angle,res)) > 0) {
17      if (range > 700) { /* out of range, head toward it */
18        drive(angle,50);
19        i = 1;
20        while (i++ < 100) /* use a counter to limit move time */
21          ;
22        drive (angle,0);
23        if (d != damage()) {
24          d = damage();
25          run();
26        }
27        angle -= 3;
28      } else {
29        cannon(angle,range);
30        while (cannon(angle,range) == 0)
31          ;
32        if (d != damage()) {
33          d = damage();
34          run();
35        }
36        angle -=15;
37      }
38    }
39    if (d != damage()) {
40      d = damage();
41      run();
42    }
43    angle += res;
44    angle %= 360;
45  }
46}
47 
48 
49int last_dir;
50 
51/* run moves around the center of the field */
52 
53run()
54{
55  int x, y;
56  int i;
57 
58  x = loc_x();
59  y = loc_y();
60 
61  if (last_dir == 0) {
62    if (y > 512) {
63      last_dir = 1;
64      drive(270,100);
65      while (y -100 < loc_y() && i++ < 200)
66        ;
67      drive(270,0);
68    } else {
69      last_dir = 1;
70      drive(90,100);
71      while (y +100 > loc_y() && i++ < 200)
72        ;
73      drive(90,0);
74    }
75  } else {
76    if (x > 512) {
77      last_dir = 0;
78      drive(180,100);
79      while (x -100 < loc_x() && i++ < 200)
80        ;
81      drive(180,0);
82    } else {
83      last_dir = 0;
84      drive(0,100);
85      while (x +100 > loc_x() && i++ < 200)
86        ;
87      drive(0,0);[
88    }
89  }
90}
91 
92/* end of counter.r */
93 
94