示例#1
0
  /* Given move, execute it */
  void execute_move(const Move &m) {
    board_move(m.src);
    pick_up_all();

    board_move(m.dst);
    put_down_all();
  }
示例#2
0
文件: main.c 项目: fenglyu/c2048
int main(int argc, char **argv) {
    int seed = time(NULL);
    //seed = 1394569404;
    //printf("Random seed: %d\n", seed);
    srand(seed);

    printf("%d %d %d\n", LSB(0x11), MSB(0x11), PopCnt(0xFFFF));

    precalc_init();

    if (argc == 2) {
        if (0 == strcmp(argv[1], "--human")) {
            board_t board = board_init();

            while (1) {
                board_print(board);

                printf("[hjkl] ");
                char key = getchar();
                getchar(); // eat newline

                if (key == 'k') {
                    board_move(&board, MOVE_UP);
                }
                else if (key == 'l') {
                    board_move(&board, MOVE_RIGHT);
                }
                else if (key == 'j') {
                    board_move(&board, MOVE_DOWN);
                }
                else if (key == 'h') {
                    board_move(&board, MOVE_LEFT);
                }
            }
        }
        else if (0 == strcmp(argv[1], "--test")) {
            test_status = DOING_TESTS; // disable board_fill_random_cell
            test_run_testcases();
            test_status = NOT_DOING_TESTS;
        }
        else if (0 == strcmp(argv[1], "--ai")) {
            ai_loop();
        }
        else {
            interface_main(argv[1]);
        }
    }
    else {
        printf("c2048, compiled with AI_DEPTH=%d AI_NUM_TRIES=%d\n\n", AI_DEPTH, AI_NUM_TRIES);
        puts("--human  Play on the console, using hjkl to move around");
        puts("--test   Runs some testcases");
        puts("--ai     Runs infinitly many games in a row, while tracking stats (avg, max, nps, etc.)");
        return 1;
    }

    return 0;
}
void test_board_evasive_capture() {
    puts("test_board_evasive_capture");
    board_t pos;
    assert(board_set_fen(&pos, "r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P1RPP/R2Q2K1 b af - 1 1"));
    board_move(&pos, move_make(SQ_B6, SQ_F2, 0));

    move_t moves[255];
    move_t *end = board_legal_moves(&pos, moves, BB_ALL, BB_ALL);
    assert(end - moves == 3);
}
示例#4
0
  /* Remove piece from board - i.e. jumping */
  void remove_piece(const iPair& capture) {
    std::cout << "Taking ";
    board_move(capture);
    pick_up_all();

    move_to( iPair(3,0) );
    put_down_all();
    nap();
    reset();
  }