📄 slides_e.tex
字号:
\documentstyle[german,a4]{article}\pagestyle{empty}\advance\topmargin-15mm\textwidth190mm\textheight250mm\advance\oddsidemargin-25mm\begin{document}\Large\begin{verbatim}-------------------------------------------------------------------------- Hamster Methods-------------------------------------------------------------------------- enquiries --get_x: INTEGER -- get hamster x-positionget_y: INTEGER -- get hamster y-positionget_dir: INTEGER -- get hamster directionget_look: INTEGER -- get outlook in current directionget_corn: INTEGER -- get amount of corn on fieldget_load: INTEGER -- get amount of corn in cheeks-- actions --move: INTEGER -- move hamster forwardturn (t: INTEGER) -- turn hamster 90 degreestake (amount: INTEGER): INTEGER -- take some corndrop (amount: INTEGER): INTEGER -- drop some corn-------------------------------------------------------------------------- Hamster Control Function------------------------------------------------------------------------class CONTROLinherit CLIENT redefine controlendcreation makefeaturecontrol (hamster: HAMSTER) isdo ...end -- control\end{verbatim}\newpage\begin{verbatim}-------------------------------------------------------------------------- Constants------------------------------------------------------------------------max_x: INTEGER is 64; -- maximal x-extension of mazemax_y: INTEGER is 64; -- maximal y-extension of mazemax_corn: INTEGER is 255; -- maximal size of corn heapmax_load: INTEGER is 12; -- maximal load of corn in cheeks-- results of get_direast: INTEGER is 0; -- hamster is looking eastnorth: INTEGER is 1; -- hamster is looking northwest: INTEGER is 2; -- hamster is looking westsouth: INTEGER is 3; -- hamster is looking south-- results of get_lookempty: INTEGER is 0; -- there is an empty field aheadcorn: INTEGER is 1; -- there is a field with corn aheadwall: INTEGER is 2; -- there is a wall ahead-- parameters of turnpos: INTEGER is 1; -- positive turn (counterclockwise)neg: INTEGER is -1; -- negative turn (clockwise)left: INTEGER is 1; -- left turn (counterclockwise)right: INTEGER is -1; -- right turn (clockwise)\end{verbatim}\newpage\begin{verbatim}-------------------------------------------------------------------------- Example Hamster Control Function------------------------------------------------------------------------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{verbatim}\end{document}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -