示例#1
0
t_nodes do_perft(struct t_board *board, int depth)
{
    struct t_move_list move_list[1];
	struct t_move_list bad_move_list[1];
	bad_move_list->count = 0;
	bad_move_list->imove = 0;
    struct t_undo undo[1];

    t_nodes nodes = 0;
    int i;

    assert(integrity(board));
    if (board->in_check) {
        generate_evade_check(board, move_list);
        if (depth == 1) return move_list->count;
    }
    else {

        //generate_captures(board, move_list);
        //generate_quiet_moves(board, move_list);
        generate_moves(board, move_list);
        //if (!equal_move_lists(move_list, xmove_list)){
        //	write_board(board, "board.txt");
        //	write_move_list(xmove_list, "all.txt");
        //	write_move_list(move_list, "inc.txt");
        //}
        if (depth == 1) return legal_move_count(board, move_list);
    }

    for (i = move_list->count - 1; i >= 0; i--) {
        assert(lookup_move(board, move_as_str(move_list->move[i])) == move_list->move[i]);
        if (make_next_move(board, move_list, bad_move_list, undo)) {
            assert(integrity(board));

            //nodes++;
            if (depth > 1)
                nodes += do_perft(board, depth - 1);
            else
                nodes++;
            unmake_move(board, undo);
            assert(integrity(board));
        }
        else
            assert(integrity(board));
    }

    return nodes;

}
示例#2
0
文件: bpt_test.c 项目: sunneo/libs
int main(int argc, char** argv)
{
	if (argc < 2) {
		printf("please supply num\n");
		exit(EXIT_FAILURE);
	}
	integrity(atol(argv[1]));
	print_measure_ment();
	return 0;
}
//
// Run a single type test
//
void runtest(char type)
{	
	try {
		debug("SStest", "Start test <%c>", type);
		switch (type) {
		case '.':	// default
			integrity();
			break;
		case '-':
			adhoc();
			break;
		case 'a':
			acls();
			break;
		case 'A':
			authAcls();
			break;
		case 'b':
			blobs();
			break;
		case 'c':
			codeSigning();
			break;
		case 'd':
			databases();
			break;
		case 'e':
			desEncryption();
			break;
		case 'k':
			keychainAcls();
			break;
		case 'K':
			keyBlobs();
			break;
		case 's':
			signWithRSA();
			break;
		case 't':
			authorizations();
			break;
		case 'T':
			timeouts();
			break;
		default:
			error("Invalid test selection (%c)", type);
		}
		printf("** Test step complete.\n");
		debug("SStest", "End test <%c>", type);
	} catch (CssmCommonError &err) {
		error(err, "Unexpected exception");
	} catch (...) {
		error("Unexpected system exception");
	}
}
示例#4
0
BOOL test_make_unmake() {

    BOOL ok = TRUE;
    int i, j;

    struct t_move_list moves[1];
    struct t_undo undo[1];

    set_fen(position, "rnbqkb1r/ppppp1pp/7n/5p2/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -");
    assert(integrity(position));
    for (j = WHITE; j <= BLACK; j++) {
        generate_moves(position, moves);
        for (i = 0; i < moves->count; i++) {
            assert(integrity(position));
            if (make_move(position, moves->pinned_pieces, moves->move[i], undo)) {
                assert(integrity(position));
                unmake_move(position, undo);
                assert(integrity(position));
            }
        }
        flip_board(position);
    }
    ok = integrity(position);

    set_fen(position, "r3Rbk1/2p2p1p/p2p4/1p1P2q1/8/PBPQ2pP/1P3P1P/3R2K1 b - -");
    assert(integrity(position));
    for (j = WHITE; j <= BLACK; j++) {
        generate_moves(position, moves);
        for (i = 0; i < moves->count; i++) {
            assert(integrity(position));
            if (make_move(position, moves->pinned_pieces, moves->move[i], undo)) {
                assert(integrity(position));
                unmake_move(position, undo);
                assert(integrity(position));
            }
        }
        flip_board(position);
    }
    ok &= integrity(position);

    return ok;
}
示例#5
0
int execute_integrity(struct db_context_t *dbc, struct integrity_t *data)
{
        int rc;
        char *  vals[1];
        int nvals=1;

        rc=integrity(dbc, data, vals, nvals);

        if (rc == -1 )
        {
          LOG_ERROR_MESSAGE("TEST FINISHED WITH ERRORS \n");

          //should free memory that was allocated for nvals vars
          dbt2_free_values(vals, nvals);

          return ERROR;
        }
        return OK;
}
示例#6
0
BOOL test_genmove() {

    BOOL ok = TRUE;

    struct t_move_list moves[1];

    set_fen(position, "r5r1/n1q1pP1k/3pPppp/P1pP4/2P4N/R1B5/2Q3PP/7K w - -");
    assert(integrity(position));
    assert(is_square_attacked(position, E4, WHITE));
    assert(!is_square_attacked(position, A7, WHITE));
    assert(!is_square_attacked(position, F4, BLACK));
    assert(is_square_attacked(position, D8, BLACK));
    generate_moves(position, moves);
    ok = ok && (moves->count == 42);

    flip_board(position);
    generate_moves(position, moves);
    //write_move_list(moves, "movelist.txt");
    ok = ok && (moves->count == 42);

    set_fen(position, "1r2k2r/p1ppqpb1/b3pnp1/3PN3/1pn1P3/2N2Q1p/PPPBBPPP/R4K1R w - -");
    assert(integrity(position));
    generate_moves(position, moves);
    assert(move_list_integrity(position, moves));
    ok = ok && (moves->count == 44);

    set_fen(position, "4q3/3P1P2/b4N2/8/3Q2Bb/2p3B1/1k4N1/4K1Nr w - -");
    assert(integrity(position));
    generate_evade_check(position, moves);
    ok = ok && (moves->count == 18);

    flip_board(position);
    generate_evade_check(position, moves);
    ok = ok && (moves->count == 18);

    set_fen(position, "1r2k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R4K1R w --k- -");
    assert(integrity(position));
    generate_moves(position, moves);
    //write_move_list(moves, "movelist.txt");
    assert(move_list_integrity(position, moves));
    ok = ok && (moves->count == 46);

    flip_board(position);
    generate_moves(position, moves);
    ok = ok && (moves->count == 46);

	// Chess960 Examples
	set_fen(position, "Rr4kr/8/8/8/8/8/PPPP4/R1K5 w Ahb -");
	assert(integrity(position));
	generate_moves(position, moves);
	assert(move_list_integrity(position, moves));
	ok = ok && (moves->count == 18);

	flip_board(position);
	generate_moves(position, moves);
	ok = ok && (moves->count == 18);

	set_fen(position, "1r1kbb1r/1pp2ppp/3npn2/3pN3/1Q3P2/4PN2/2PP2PP/qR1KBB1R w HBhb -");
	assert(integrity(position));
	generate_legal_moves(position, moves);
	assert(move_list_integrity(position, moves));
	ok = ok && (moves->count == 48);

	set_fen(position, "rkrbqnb1/pp2p2p/3p1pp1/2p1nP2/2P1P3/3P2N1/PP4PP/RKRBQNB1 w CAca -");
	assert(integrity(position));
	generate_legal_moves(position, moves);
	write_move_list(moves, "movelist.txt");
	assert(move_list_integrity(position, moves));
	ok = ok && (moves->count == 34);

	flip_board(position);
	generate_legal_moves(position, moves);
	ok = ok && (moves->count == 34);


    return ok;
}
示例#7
0
BOOL test_fen() {
    set_fen(position, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -");
    assert(integrity(position));
    set_fen(position, "r5r1/n1q1pP1k/3pPppp/P1pP4/2P4N/R1B5/2Q3PP/7K w - -");
    return (!strcmp(get_fen(position), "r5r1/n1q1pP1k/3pPppp/P1pP4/2P4N/R1B5/2Q3PP/7K w - -"));
}
示例#8
0
bool CompBinary<T>::search(T pat) 
{
	pattern = pat;

	int fd = open(filename.c_str(), O_RDONLY);
	if (fd == -1) 
	{
		perror("open");
		exit(EXIT_FAILURE);
	}

	struct stat stats;
	if (fstat(fd, &stats) == -1) 
	{
		perror ("fstat");
		exit(EXIT_FAILURE);
	}

	if (close(fd) == -1) 
	{
		perror("close");
		exit(EXIT_FAILURE);
	}

	long count = stats.st_size / recordSize;
	int sec = -1;

	FileSpan sections[NUM_THREADS];
	CompBinaryThreadParams threadParams[NUM_THREADS];
	pthread_t threads[NUM_THREADS];

	if (!integrity(0, count))
		return false;
    
	compartmentalize(sections, 0, count);

	for (int i = 0; i < NUM_THREADS; ++i) 
	{
		sections[i].filename = filename;
		threadParams[i].search = this;
		threadParams[i].fileSpan = &sections[i];
		pthread_create(&threads[i], NULL, CompBinary<T>::collapseThread, &threadParams[i]);
	}

	for (int j = 0; j < NUM_THREADS; ++j) 
		pthread_join(threads[j], NULL);

	for (int k = 0; k < NUM_THREADS; ++k) 
	{
		if (sections[k].inMe == true) 
		{
			sec = k;
			sections[k].inMe = false;
		}
	}

	if (NUM_THREADS > 1) 
	{
		while ((sections[sec].count % NUM_THREADS) == 0) 
		{
			compartmentalize(sections, sections[sec].offset, sections[sec].count);

			for (int x = 0; x < NUM_THREADS; ++x) 
			{
				threadParams[x].fileSpan = &sections[x];
				pthread_create(&threads[x], NULL, CompBinary<T>::collapseThread, &threadParams[x]);
			}

			for (int y = 0; y < NUM_THREADS; ++y) 
				pthread_join(threads[y], NULL);

			for (int z = 0; z < NUM_THREADS; ++z) 
			{
				if (sections[z].inMe == true) 
				{
					sec = z;
					sections[z].inMe = false;
				}
			}
		}
	}

	return evaluate(&sections[sec]);
}