?? control.c
字號:
/*---------------------------------------------------------------------- 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() */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -