Exemplo n.º 1
0
int main(int argc, char* argv[]) {
    setlocale(LC_ALL, "");

    board_t board;
    RESET_BOARD(board);
    char buffer[256];
    int len;

    hash_init();
    run_all_tests();
    print_board(&board);

    move_t m;
    while (1) {
    top:
        print_board(&board);
        move_t move = 0;
        while (move == 0)
        { 
            printf("enter move> ");
            fgets(buffer, 255, stdin);
            if (!strcmp(buffer, "undo\n")) {
                undo_move(&board, m);            
                goto top;
            } else if (!strcmp(buffer, "exit\n")) {
                return 0;
            }
            len = strlen(buffer);
            if (buffer[len-1] == '\n') buffer[len-1] = '\0';
            move = move_from_text(buffer, &board);
        }
        make_move(&board, move);
        print_board(&board);

        printf("Calculating...\n");
        m = think(&board);
        make_move(&board, m);
        printf("Done calculating...\n");
        print_move(m);
    }
    return 0;
}
Exemplo n.º 2
0
/*
    Tests `repetition_count` by making repetitive moves and checking the result.
*/
int test_repetition_count() {
    board_t board;
    initialize_testing_board(&board);

    board.to_move = BLACK;
    board.pieces[H8] = BLACK_ROOK;
    board.pieces[C3] = WHITE_ROOK;
    board.piece_bitboard[BLACK_ROOK] = SQUARE_MASK[H8];
    board.piece_bitboard[WHITE_ROOK] = SQUARE_MASK[C3];
    board.color_bitboard[BLACK] = board.piece_bitboard[BLACK_ROOK];
    board.color_bitboard[WHITE] = board.piece_bitboard[WHITE_ROOK];
    board.all_pieces_bitboard = board.color_bitboard[WHITE] | board.color_bitboard[BLACK];

    make_move(&board, move_from_text("h8h7", &board));
    make_move(&board, move_from_text("c3c5", &board));
    make_move(&board, move_from_text("h7h8", &board));
    make_move(&board, move_from_text("c5c3", &board));

    make_move(&board, move_from_text("h8h7", &board));
    make_move(&board, move_from_text("c3c5", &board));
    make_move(&board, move_from_text("h7h8", &board));
    make_move(&board, move_from_text("c5c3", &board));

    if (repetition_count(&board) != 3) {
        fprintf(stderr, "test_repetition_count -- Test 1 failed.\n");
        return TEST_ERROR;
    }

    make_move(&board, move_from_text("h8h7", &board));
    make_move(&board, move_from_text("c3c5", &board));
    make_move(&board, move_from_text("h7h8", &board));
    make_move(&board, move_from_text("c5c3", &board));

    if (repetition_count(&board) != 4) {
        fprintf(stderr, "test_repetition_count -- Test 2 failed.\n");
        return TEST_ERROR;
    }

    make_move(&board, move_from_text("h8h6", &board));

    if (repetition_count(&board) != 1) {
        fprintf(stderr, "test_repetition_count -- Test 3 failed.\n");
        return TEST_ERROR;
    }

    return TEST_SUCCESS;
}
Exemplo n.º 3
0
/*
    Performs a very simple test of the hashing mechanism. In the first test, moves a knight around the board
    and back to its starting position to test if the hashes are the same. In the second test, the same movement
    is done except the knight captures a piece to test if the hashes are different.
*/
int test_hash() {
    board_t board;
    initialize_testing_board(&board);

    board.to_move = BLACK;
    board.can_castle = BLACK_CASTLE_OO;
    board.pieces[E8] = BLACK_KING;
    board.pieces[H8] = BLACK_ROOK;
    board.pieces[B8] = BLACK_KNIGHT;
    board.pieces[C3] = WHITE_ROOK;
    board.pieces[D1] = WHITE_KING;
    board.piece_bitboard[BLACK_ROOK] = SQUARE_MASK[H8];
    board.piece_bitboard[BLACK_KNIGHT] = SQUARE_MASK[B8];
    board.piece_bitboard[WHITE_ROOK] = SQUARE_MASK[C3];
    board.king_position[WHITE] = D1;
    board.king_position[BLACK] = E8;
    board.color_bitboard[BLACK] = board.piece_bitboard[BLACK_ROOK] | board.piece_bitboard[BLACK_KNIGHT] | SQUARE_MASK[board.king_position[BLACK]];
    board.color_bitboard[WHITE] = board.piece_bitboard[WHITE_ROOK] | SQUARE_MASK[board.king_position[WHITE]];
    board.all_pieces_bitboard = board.color_bitboard[WHITE] | board.color_bitboard[BLACK];

    key_t key = board.hash_key;

    make_move(&board, move_from_text("b8c6", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("c6e7", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("e7d5", &board)); board.to_move = BLACK;

    make_move(&board, move_from_text("d5e7", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("e7c6", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("c6b8", &board)); board.to_move = BLACK;

    if (key != board.hash_key) {
        fprintf(stderr, "test_hash -- Test 0 failed.");
        return TEST_ERROR;
    }

    make_move(&board, move_from_text("b8c6", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("c6e7", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("e7d5", &board)); board.to_move = BLACK;

    make_move(&board, move_from_text("d5c3", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("c3d5", &board)); board.to_move = BLACK;

    make_move(&board, move_from_text("d5e7", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("e7c6", &board)); board.to_move = BLACK;
    make_move(&board, move_from_text("c6b8", &board)); board.to_move = BLACK;

    if (key == board.hash_key) {
        fprintf(stderr, "test_hash -- Test 1 failed.");
        return TEST_ERROR;
    }

    return TEST_SUCCESS;
}