ehamster.tex

来自「数据挖掘中de一个算法 hamster的实例」· TEX 代码 · 共 67 行

TEX
67
字号
\documentstyle[german,a4]{article}\pagestyle{empty}\advance\topmargin-10mm\advance\textheight10mm\textwidth150mm\oddsidemargin5mm\begin{document}\begin{verbatim}----------------------------------------------------------------------------- File    : control.e-- Contents: customized hamster control class-- Authors : Ilona Bl"umel and Christian Borgelt-- History : 11.03.1999 file created---------------------------------------------------------------------------class CONTROLinherit CLIENT  redefine controlendcreation  make----------------------------------------------------------------------------- Methods--------------------------------------------------------------------------- feature                   control (hamster: HAMSTER) is   -- hamster control function (random)local  movecnt: INTEGER;             -- number of moves made  turn   : INTEGER;             -- turn direction (left/right)  d      : INTEGER;             -- dummy variable for resultsdo  from    movecnt := 0;               -- initialize the move counter  until    movecnt = 50                -- make 50 field to field moves  loop    if     hamster.get_x = 0    -- if we are at home (initial position),    and    hamster.get_y = 0    -- drop all the corn we have    then   d := hamster.drop(hamster.max_load);    elseif hamster.get_corn > 0 -- if there is corn on the field    then   d := hamster.take(hamster.max_load);    end                         -- take as much as he can carry    if hamster.get_look = hamster.wall  -- if the way is blocked    or else random(4) <= 1      -- or just because it's funny (25%)    then if random(2) <= 1      -- randomly choose a turn direction         then turn := hamster.left;         else turn := hamster.right;         end                    -- (50% either way)         from           hamster.turn(turn);  -- turn the hamster         until                  -- in the chosen direction           hamster.get_look /= hamster.wall         loop                   -- repeat turning the hamster around           hamster.turn(turn);  -- until no wall blocks the way         end    end    d := hamster.move;          -- move the hamster forward    movecnt := movecnt +1;      -- and count the move made  endend  -- control------------------------------------------------------------------------end  -- CONTROL\end{verbatim}\end{document}

⌨️ 快捷键说明

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