{----------------------------------------------------------------------- File : control.pas (Turbo-/Borland-Pascal version) Contents: hamster control program Author : Christian Borgelt History : 24.03.1999 file created from file control.c 14.04.1999 adapted to Turbo-/Borland-Pascal -----------------------------------------------------------------------} UNIT control; INTERFACE USES phamster; {----------------------------------------------------------------------- Function Prototype -----------------------------------------------------------------------} PROCEDURE hms_ctrl (hms : HAMSTER); {----------------------------------------------------------------------- Hamster Control Function -----------------------------------------------------------------------} IMPLEMENTATION PROCEDURE hms_ctrl (hms : HAMSTER); VAR x, y : INTEGER; { coordinates of current field } movecnt : INTEGER; { number of moves made } turn : INTEGER; { turn direction (HMS_POS/HMS_NEG) } d : INTEGER; { dummy for return values } BEGIN { --- hamster control function } movecnt := 0; { initialize the move counter } WHILE (movecnt < 50) DO BEGIN { make 50 (field to field) moves } hms_pos(hms, x, y); { get current position in maze } IF (x = 0) AND (y = 0) { if we are at home (initial position) } THEN d := hms_drop(hms, HC_MAXLOAD) { drop all the corn we have } ELSE IF (hms_corn(hms) > 0) { if there is corn on the field, take } THEN d := hms_take(hms, HC_MAXLOAD); { as much as we can carry } IF (hms_look(hms) = HC_WALL) OR (Random(4) THEN BEGIN { or just because its funny, } IF (Random(2) THEN turn := HC_POS ELSE turn := HC_NEG; REPEAT hms_turn(hms,turn);{ turn hamster in random direction } UNTIL (hms_look(hms) HC_WALL); END; { until no wall blocks the way } d := hms_move(hms); { move the hamster forward } movecnt := movecnt +1; { and count the move made } END; END; { hms_ctrl() } {----------------------------------------------------------------------} END.