📄 chamster.tex
字号:
\documentstyle[german,a4]{article}\pagestyle{empty}\advance\topmargin-10mm\advance\textheight10mm\textwidth150mm\oddsidemargin5mm\begin{document}\begin{verbatim}/*---------------------------------------------------------------------- File : control.c Contents: hamster control program Author : Christian Borgelt History : 16.10.1997 file created----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include "hamster.h"/*---------------------------------------------------------------------- Functions----------------------------------------------------------------------*/void hms_ctrl (HAMSTER *hms){ /* --- hamster control function */ int x, y; /* coordinates of current field */ int movecnt = 0; /* number of moves made */ int turn; /* turn direction (HMS_POS/HMS_NEG) */ while (movecnt < 50) { /* make 50 (field to field) moves */ hms_pos(hms, &x, &y); /* get current position in maze */ if ((x == 0) && (y == 0)) /* if we are at home (initial pos.), */ hms_drop(hms, HMS_MAXLOAD); /* drop all the corn we have */ else if (hms_corn(hms)) /* if there is corn on the field, */ hms_take(hms, HMS_MAXLOAD); /* take as much as we can carry */ if ((hms_look(hms) == HMS_WALL) /* if the way is blocked */ || (RAND_MAX/4 -rand() > 0)) { /* or just because it's funny */ turn = (RAND_MAX/2 -rand() > 0) ? HMS_POS : HMS_NEG; do { hms_turn(hms, turn); /* turn hamster in random direction */ } while (hms_look(hms) == HMS_WALL); } /* until no wall blocks the way */ hms_move(hms); movecnt++; /* move the hamster forward */ } /* and count the move made */} /* hms_ctrl() */\end{verbatim}\end{document}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -