home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff331.lzh / CRobots / rook.r < prev    next >
Text File  |  1990-03-21  |  1KB  |  85 lines

  1. CRobots, Inc.
  2. T. Poindexter
  3. /* rook.r  -  scans the battlefield like a rook, i.e., only 0,90,180,270 */
  4. /* move horizontally only, but looks horz and vertically */
  5.  
  6. int course;
  7. int boundary;
  8. int d;
  9.  
  10. main()
  11. {
  12.   int y;
  13.  
  14.   /* move to center of board */
  15.   if (loc_y() < 500) {
  16.     drive(90,70);                /* start moving */
  17.     while (loc_y() - 500 < 20 && speed() > 0)    /* stop near center */
  18.       ;
  19.   } else {
  20.     drive(270,70);                /* start moving */
  21.     while (loc_y() - 500 > 20 && speed() > 0)    /* stop near center */
  22.       ;
  23.   }
  24.   drive(y,0);
  25.  
  26.   /* initialize starting parameters */
  27.   d = damage();
  28.   course = 0;
  29.   boundary = 995;
  30.   drive(course,30);
  31.  
  32.   /* main loop */
  33.  
  34.   while(1) {
  35.  
  36.     /* look all directions */
  37.     look(0);
  38.     look(90);
  39.     look(180);
  40.     look(270);
  41.  
  42.     /* if near end of battlefield, change directions */
  43.     if (course == 0) {
  44.       if (loc_x() > boundary || speed() == 0) 
  45.     change();
  46.     }
  47.     else {
  48.       if (loc_x() < boundary || speed() == 0) 
  49.     change();
  50.     }
  51.   }
  52.     
  53. }
  54.  
  55. /* look somewhere, and fire cannon repeatedly at in-range target */
  56. look(deg)
  57. int deg;
  58. {
  59.   int range;
  60.  
  61.   while ((range=scan(deg,2)) > 0 && range <= 700)  {
  62.     drive(course,0);
  63.     cannon(deg,range);
  64.     if (d+20 != damage()) {
  65.       d = damage();
  66.       change();
  67.     }
  68.   }
  69. }
  70.  
  71.  
  72. change() {
  73.   if (course == 0) {
  74.     boundary = 5;
  75.     course = 180;
  76.   } else {
  77.     boundary = 995;
  78.     course = 0;
  79.   }
  80.   drive(course,30);
  81. }
  82.  
  83.  
  84. /* end of rook.r */
  85.