home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / P_ROBOTS.ZIP / P-ROBT21.ZOO / pitbull.pr < prev    next >
Encoding:
Text File  |  1989-10-31  |  7.2 KB  |  167 lines

  1. (**************************************************************************)
  2. (*                             W A R N I N G                              *)
  3. (*                                                                        *)
  4. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  5. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  6. (**************************************************************************)
  7.  
  8.   PROCEDURE PITBULL;
  9. {
  10. T.J.Lyman
  11. PROBOTS simulation for individual robot competition
  12.  
  13.  This robot is designed primarily to be fast and to keep moving, to
  14.  quickly scan for an enemy and fire, then move before the enemy can
  15.  detect it. It is constantly moving in a clockwise direction in a
  16.  circle of radius 400 (roughly) around the center point of the arena.
  17.  Each new target point to which it travels is 80 degrees clockwise
  18.  on the circle from the previous point. This minimizes the amount of
  19.  times the robot needs to slow down to turn but also prevents it from
  20.  staying in the same direction for too long, thus becoming trackable
  21.  by another robot.
  22.  
  23.  The robot performs only two or three scan operations in any given
  24.  pass through its main loop. It checks in two scan directions for the
  25.  enemy: the last scan direction calculated in the last pass through
  26.  loop plus the last scan direction it found an enemy at. If it finds
  27.  the enemy, it quickly does another search of scan width plus or minus
  28.  5 degrees to zero in on the enemy position. Based on geometric
  29.  calculations this should land the shell within 40 spaces of the point
  30.  at which the enemy was sighted (of course, the enemy could have moved)
  31.  if the enemy is within 450 spaces. More searches to test for other
  32.  possible enemy positions, e.g. 20 degrees removed from the last known
  33.  x,y coordinates were tested but not included in the program since
  34.  they slowed the robot down. The same was true for zeroing in closer
  35.  on the enemy angle. If the enemy was also on the move, zeroing
  36.  in closer was not too effective.
  37.  
  38.  It then fires two cannon shots: one directly at where it thinks the
  39.  enemy is and a second shot in the same direction but 100 space further
  40.  out. This is to account for the robot and its enemy both being in
  41.  motion. The enemy could have moved in any direction since being seen.
  42.  A spot 100 spaces out was chosen since it was easy and quick to
  43.  calculate and seemed to have the added advantage of being effective
  44.  when the enemy was close to a wall. Logic was also tested to detect
  45.  the enemy's direction and speed but was not included in the program
  46.  because it slowed it down. A total of two shots is fired since only
  47.  two shells can be in the air at the same time.
  48.  
  49.  If the enemy is found in a new scan direction, its x,y coordinates
  50.  are calculated and saved. If the enemy is not found in either of the
  51.  two scan directions, it sets a new scan direction 20 clockwise from the
  52.  current one. The scan direction seemed to be more effective when
  53.  moving in the same direction as the robot. Since this robot moves
  54.  clockwise around the circle, its scan direction also moves clockwise.
  55.  
  56.  PITBULL is able to shed logic by building protections inherently into
  57.  its algorithm. Its circular motion never brings it close enough to
  58.  the walls to check for hitting the wall or firing at close range
  59.  toward the wall. Since it is constantly on the run, it does not check
  60.  itself for damage. It also takes a calculated risk that it will not
  61.  fire its cannon within a range of 40 spaces at its enemy. It is
  62.  willing to take the trade in damage. Minimal use is also made of
  63.  subroutines to avoid any unnecessary overhead. Thus some small pieces
  64.  of logic are duplicated in a few places.
  65.  
  66.  PITBULL is a general purpose robot but designed primarily to compete
  67.  against robots that are constantly moving. It will not be as effective
  68.  as other possible robots at finding and destroying a stationary target.
  69.  It is, however, relentless. It keeps coming back, which is how it got
  70.  its name.
  71. }
  72.   VAR
  73.     xe, ye, scandir, scandist, movedir : Integer;
  74.  
  75.     PROCEDURE GOTO(x, y : Integer);
  76.     BEGIN ;
  77. {
  78.     Record the direction to the next point on the circle. Keep moving
  79.     in that direction at speed 100 until within 200 spaces of the
  80.     target point.
  81.  
  82. }
  83.       movedir := Angle_To(x, y);
  84.       WHILE (distance(loc_x, loc_y, x, y) > 200) DO
  85.         BEGIN
  86.           DRIVE(movedir, 100);
  87. {
  88.     Scan in direction set in last pass through the program. If the
  89.     enemy is found, zero in within 5 degrees, fire two shells and
  90.     record the enemy's x,y coordinates. If the enemy is not found,
  91.     then scan in the direction of the last recorded enemy x,y
  92.     coordinates. If the enemy is found here, zero in and fire.
  93.     If the enemy is not found in either scan direction, advance the
  94.     scan 20 degrees clockwise for the next pass through the program.
  95. }
  96.           scandist := SCAN(scandir, 10);
  97.           IF scandist <> 0
  98.           THEN
  99.             BEGIN
  100.               IF SCAN((scandir+5) MOD 360, 5) <> 0
  101.               THEN
  102.                 BEGIN
  103.                   CANNON((scandir+5) MOD 360, scandist);
  104.                   CANNON((scandir+5) MOD 360, scandist+100);
  105.                 END
  106.               ELSE
  107.                 BEGIN
  108.                   CANNON((scandir+355) MOD 360, scandist);
  109.                   CANNON((scandir+355) MOD 360, scandist+100);
  110.                 END;
  111.               xe := loc_x+Round(scandist*Cos(scandir));
  112.               ye := loc_y+Round(scandist*Sin(scandir));
  113.             END
  114.           ELSE
  115.             BEGIN
  116.               scandist := SCAN(Angle_To(xe, ye), 10);
  117.               IF scandist <> 0
  118.               THEN
  119.                 BEGIN
  120.                   scandir := Angle_To(xe, ye);
  121.                   IF SCAN((scandir+5) MOD 360, 5) <> 0
  122.                   THEN
  123.                     BEGIN
  124.                       CANNON((scandir+5) MOD 360, scandist);
  125.                       CANNON((scandir+5) MOD 360, scandist+100);
  126.                     END
  127.                   ELSE
  128.                     BEGIN
  129.                       CANNON((scandir+355) MOD 360, scandist);
  130.                       CANNON((scandir+355) MOD 360, scandist+100);
  131.                     END;
  132.                 END
  133.               ELSE scandir := (scandir+340) MOD 360;
  134.             END;
  135.         END;
  136. {
  137.       Robot is now within 200 spaces of target point. Enter slow down
  138.       command and exit loop to calculate a new target point.
  139. }
  140.       DRIVE(movedir, 0);
  141.     END;
  142.  
  143.   BEGIN ;
  144. {
  145.     Move initially to the closest point on the circle of radius 400
  146.     from the center point. Set initial scan and enemy position
  147.     coordinates to the center point.
  148. }
  149.     movedir := (Angle_To(500, 500)+180) MOD 360;
  150.     scandir := Angle_To(500, 500);
  151.     xe := 500;
  152.     ye := 500;
  153.     scandist := 200;
  154. {
  155.     Set a target point on the circle based on the move direction
  156.     calculated the last time through. When the next point is reached
  157.     calculate a new point 80 degrees clockwise from the previous and
  158.     repeat the loop. Keep repeating the process until one of the robots
  159.     has been destroyed.
  160. }
  161.     REPEAT
  162.       GOTO(500+Round(400.0*Cos(movedir)), 500+Round(400.0*Sin(movedir)));
  163.       movedir := (movedir+280) MOD 360;
  164.     UNTIL DEAD OR WINNER;
  165.  
  166.   END;
  167.