(**************************************************************************)
(*                             W A R N I N G                              *)
(*                                                                        *)
(*  This Robot has NOT been designed to take advantage of the advanced    *)
(*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
(**************************************************************************)

  PROCEDURE M66;
    { Based on C-Robot M66 : programmed by OBI-ONE }

  VAR
    drv_dir        : Integer; { drive direction }
    scn_dir        : Integer; { scan direction }
    step           : Integer; { scan step }
    degs           : Integer; { half of scan step }
    Range          : ARRAY[-2..2] OF Integer; { range to oponent }
    range_sv       : Integer; { range of last scan }
    found          : Boolean; { foe found ? }
    x, y           : Integer;


    PROCEDURE Move;
    BEGIN
      x := loc_x;
      y := loc_y;
      IF (x < 200)
      THEN drv_dir := Random(45)
      ELSE IF (x > 800) THEN drv_dir := Random(45)+180;

      IF (y < 200)
      THEN drv_dir := Random(45)+90
      ELSE IF (y > 800) THEN drv_dir := Random(45)+270;

      drive(drv_dir, 100);
    END; {Move}

    PROCEDURE attack;
    VAR I, Pick    : Integer;
    BEGIN
      IF ObjectScanned = Enemy
        THEN cannon(scn_dir, range_sv);{shoot at last foe postion}
      Pick := 99;
      FOR I := -2 TO 2 DO
        BEGIN
          Range[I] := scan(scn_dir+step*I, degs);
          IF Range[I] > 40 THEN
            BEGIN
              Pick := I;
              I := 2;
            END;
        END;
      IF Pick <> 99 THEN
        BEGIN
          found := True;
          range_sv := Range[Pick];
          scn_dir := scn_dir+step*Pick;
          IF ObjectScanned = Enemy
            THEN cannon(scn_dir, range_sv);
        END
      ELSE scn_dir := scn_dir+120;
    END; {Attack}

  BEGIN {M66 Main}
    drv_dir := Random(360); { initialize }
    scn_dir := drv_dir+120;
    found := False;
    range_sv := 700;
    step := 20;
    degs := step DIV 2;

    REPEAT { main loop }

      { drive at full speed.                       }
      { when close to wall, turn around at random. }

      Move;

      { scan every 20 degrees resolution. }
      { if you find a foe, then attack it with your cannon. }

      attack;

    UNTIL Dead OR Winner; { end of main loop }

  END; {M66 Main}
