home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
PASCAL
/
P_ROBO31.ZIP
/
WIMP.PR
< prev
Wrap
Text File
|
1993-02-10
|
5KB
|
128 lines
(**************************************************************************)
(* 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 Wimp;
{ Based on C-Robot "Hunter-Killer"
Original by John Hardin
strategy: Move at medium speed in the direction of the last detected
robot while scanning 360 degrees quickly. If a robot is
detected, charge at it at high speed, firing when in range.
If hit while scanning, run to a random location and resume.
Don't worry about running into a wall or another robot, since
that only causes 2% damage. }
{ Wimp "globals" }
VAR
d : Integer; { last damage check }
dir : Integer; { direction looking & firing }
Range : Integer;
PROCEDURE go(dest_x, dest_y : Integer);
{ go to the point specified }
VAR
course : Integer;
BEGIN
course := Angle_To(dest_x, dest_y);
drive(course, 100); { full speed ahead! }
WHILE (distance(loc_x, loc_y, dest_x, dest_y) > 100) AND (speed > 0)
DO {nothing} ;
END;
PROCEDURE run;
{ RUN AWAY!! }
BEGIN
go(50+Random(900), 50+Random(900));
END; { end of run }
PROCEDURE Sweep;
{ sweepscan arena for target }
VAR
Range : Integer;
return : Boolean;
BEGIN
return := False;
drive(dir, 40); { drive at medium spped towards last target }
dir := dir DIV 10; { scan only even 10-degree slices }
dir := dir*10;
WHILE NOT return DO { scan until we see another robot }
BEGIN
d := damage; { save current level of damage }
WHILE (damage = d) DO { scan until we take a hit }
BEGIN
dir := dir+10; { increment scan direction }
dir := dir MOD 360; { MOD 360 }
Range := scan(dir, 10); { wide-range scan }
IF (Range > 0) THEN
BEGIN
return := True; { GOT ONE! }
d := -10;
END;
END; { continue scanning }
IF NOT return THEN run; { Ouch! let's get out of here! }
END;
END; { end of sweep }
FUNCTION attack(direc : Integer) : Integer;
{ attack robot at direc }
VAR
gotone : Integer; { got robot flag }
BEGIN
gotone := 0; { don't got one }
dir := direc; { look in direc }
Range := scan(dir, 3); { narrow resolution }
WHILE (Range > 0) DO { keep attacking while he's there }
BEGIN
IF (Range > 150) THEN drive(dir, 100) { charge! }
ELSE drive(dir+180, 100); { we're too close - back up! }
IF (Range > 40) THEN cannon(dir+3, Range); { fire! }
Range := scan(dir, 3); { check target again }
gotone := 1; { flag that we've a target }
END;
IF (gotone = 0) THEN drive(dir, 50); { if we've lost him, trundle along }
attack := gotone; { towards where we last saw him }
END; { end of attack }
PROCEDURE target;
{ search for and attack target }
VAR
startdir : Integer; { direction robot originally seen at }
curdir : Integer; { direction we're currently looking }
BEGIN
d := damage; { save current damage }
startdir := dir; { save original direction }
curdir := dir-5; { back up 5 degrees }
WHILE (curdir < startdir+7) AND (d = damage) DO
{ until we've looked through ten degrees }
IF (attack(curdir) > 0) THEN { is somebody there? }
BEGIN
startdir := dir; { yes - Blast him! }
curdir := startdir-6; { back up the scanner again so we don't }
END; { lose him and keep looking }
curdir := curdir+2; { increment scan direction }
END; { start scanning again }
BEGIN {Wimp main}
d := damage; { get starting damage }
dir := 0; { starting scan direction }
run;
WHILE True DO { loop is executed forever }
BEGIN
Sweep; { sweep arena at high speed }
target; { acquire and attack detected robot }
END;
END; { end of Wimp main }