数据挖掘中de一个算法 hamster的实例

源代码在线查看: control.p

软件大小: 138 K
上传用户: pipinooad
关键词: hamster 数据挖掘 算法
下载地址: 免注册下载 普通下载 VIP

相关代码

				{-----------------------------------------------------------------------				  File    : control.p				  Contents: hamster control program				  Author  : Christian Borgelt				  History : 24.03.1999 file created from file control.c				-----------------------------------------------------------------------}				MODULE control;				EXPORT control = (hms_ctrl);				IMPORT hamster;								{-----------------------------------------------------------------------				  Function Prototype				-----------------------------------------------------------------------}				PROCEDURE hms_ctrl (hms : HAMSTER);								END;				{-----------------------------------------------------------------------				  Hamster Control Function				-----------------------------------------------------------------------}								PROCEDURE hms_ctrl;				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_ELSE (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.							

相关资源