Пример #1
0
int main(int argc, char **argv) {
    // Randomise random unmber generator initial state.
    srandom(time(0));

    int board_size = 4;
    int **board = board_create(board_size);
    if (!board) {
        printf("failed to create board.\n");
        exit(0);
    }
    board_spawn_tile(board_size, board);
    board_spawn_tile(board_size, board);

    int tile = 0;

    while (1) {
        board_display(board_size, board);
        printf("Next move? ");
        fflush(stdout);
        int action = read_input();
        switch (action) {
            case GO_LEFT:
                tilt_board_left(board_size, board);
                break;
            case GO_RIGHT:
                tilt_board_right(board_size, board);
                break;
            case GO_UP:
                tilt_board_up(board_size, board);
                break;
            case GO_DOWN:
                tilt_board_down(board_size, board);
                break;
            case GO_NOWHERE:
                break;
            case INVALID_INPUT:
            default:
                printf("Invalid input. Type l, r, u or d to tilt board.\n");
                break;
        }

        if (action == INVALID_INPUT) {
            printf("Invalid input. Type l, r, u or d to tilt board.\n");
        }
        else {
            tile = board_spawn_tile(board_size, board);
        }
        if (tile == 1) {
            break;
        }
    }
    return 0;
}
Пример #2
0
int wb0(){
printf("\nin wb255 \n");
fflush(stdout);
int e=0;
e+=tilt_line_left(0,NULL);
e+=tilt_line_right(0,NULL);
e+=board_rotate_right(0,NULL);
e+=board_rotate_left(0,NULL);
e+=tilt_board_up(0,NULL);
e+=tilt_board_down(0,NULL);
e+=tilt_board_left(0,NULL);
e+=tilt_board_right(0,NULL);
if(e == (0-8)) {
printf("upper boundary 1 tests for all 8 tilt functions: PASS\n");
}else{
printf("upper boundary 1 tests for all 8 tilt functions: FAIL: %d \n",e);
}
fflush(stdout);
return 0;
}