📄 slides_c.tex
字号:
\documentstyle[german,a4]{article}\pagestyle{empty}\advance\topmargin-20mm\textwidth240mm\textheight190mm\advance\oddsidemargin-10mm\begin{document}\special{landscape}\LARGE\begin{verbatim}/*---------------------------------------------------------------------- Type Definitions----------------------------------------------------------------------*/typedef struct hamster HAMSTER; /* a hamster *//*---------------------------------------------------------------------- Functions----------------------------------------------------------------------*//* --- enquiries --- */extern void hms_pos (HAMSTER *hms, int *x, int *y);extern int hms_dir (HAMSTER *hms);extern int hms_load (HAMSTER *hms);extern int hms_corn (HAMSTER *hms);extern int hms_look (HAMSTER *hms);/* --- actions --- */extern int hms_move (HAMSTER *hms);extern void hms_turn (HAMSTER *hms, int turn);extern int hms_take (HAMSTER *hms, int amount);extern int hms_drop (HAMSTER *hms, int amount);/* --- function to be provided by user --- */extern void hms_ctrl (HAMSTER *hms);\end{verbatim}\newpage\vspace*{-15mm}\begin{verbatim}/*---------------------------------------------------------------------- Preprocessor Definitions----------------------------------------------------------------------*/#define HMS_MAXXEXT 64 /* maximal x-extension of maze */#define HMS_MAXYEXT 64 /* maximal y-extension of maze */#define HMS_MAXLOAD 12 /* maximal load of corn in cheeks */#define HMS_MAXCORN 255 /* maximal size of corn heap *//* --- results of hms_dir() --- */#define HMS_EAST 0 /* hamster is looking east */#define HMS_NORTH 1 /* hamster is looking north */#define HMS_WEST 2 /* hamster is looking west */#define HMS_SOUTH 3 /* hamster is looking south *//* --- results of hms_look() --- */#define HMS_EMPTY 0 /* there is an empty field ahead */#define HMS_CORN 1 /* there is a field with corn ahead */#define HMS_WALL 2 /* there is a wall ahead *//* --- parameters of hms_turn() --- */#define HMS_POS 1 /* positive turn (counterclockwise) */#define HMS_NEG -1 /* negative turn (clockwise) */#define HMS_LEFT 1 /* left turn (counterclockwise) */#define HMS_RIGHT -1 /* right turn (clockwise) */\end{verbatim}\newpage\begin{verbatim}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 direction is blocked */ || (RAND_MAX/4 -rand() > 0)) { /* or just because its 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 hamster forward */ } /* and count the move made */} /* hms_ctrl() */\end{verbatim}\end{document}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -