⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.pas

📁 数据挖掘中de一个算法 hamster的实例
💻 PAS
字号:
{-----------------------------------------------------------------------  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;INTERFACEUSES phamster;{-----------------------------------------------------------------------  Function Prototype-----------------------------------------------------------------------}PROCEDURE hms_ctrl (hms : HAMSTER);{-----------------------------------------------------------------------  Hamster Control Function-----------------------------------------------------------------------}IMPLEMENTATIONPROCEDURE 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) <= 0)         { if the way is blocked }    THEN BEGIN                  { or just because its funny, }      IF (Random(2) <= 0)       { choose a random turn direction }      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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -