home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 1113.dms / 1113.adf / CRobots / counter.r < prev    next >
Text File  |  1993-03-02  |  2KB  |  98 lines

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