コード例 #1
0
ファイル: chessstate_tests.c プロジェクト: fishysplash/chess
CHESS_STATE test_search(char *test,
                        char *piece_placement,
                        char *en_passant_square,
                        char *castling_availability,
                        int expected_move_count,
                        char *active_color,
                        char *expected_moves)
{
    CHESS_STATE_STR css = {0};
    strcpy(css.piece_placement, piece_placement);
    strcpy(css.active_color,active_color);
    strcpy(css.enpassant_square,en_passant_square);
    strcpy(css.castling_availability,castling_availability);
    CHESS_STATE cs = get_chess_state(css);

    int id_count;
    ITERATIVE_DEEPENING_INFO id_info[MAX_ITERATIVE_DEEPENING_DEPTH] = {0};

    iterative_deepening(&cs, 0, &id_count, id_info, 0);

    if (id_info[1].legal_move_count!=expected_move_count)
        printf("Test: %s\nExpected moves: %d, Actual moves: %d",test, expected_move_count,id_info[1].legal_move_count);

    assert(id_info[1].legal_move_count==expected_move_count);

    if (strlen(expected_moves)>0)
        check_contains_moves(&cs, expected_moves);
}
コード例 #2
0
ファイル: search.cpp プロジェクト: hof/qm2
/**
 * Starts the searching
 */
void search_t::go() {
    assert(stack->best_move.piece == 0 && ponder_move.piece == 0);
    if (book_lookup()) { //book hit
        uci::send_pv(0, 1, 1, 1, game->tm.elapsed(),
                stack->best_move.to_string().c_str(), score::EXACT);
    } else if (init_root_moves() > 0) { //do id search
        iterative_deepening();
    }
    uci::send_bestmove(stack->best_move, ponder_move);
}
コード例 #3
0
int main(int argc, char *argv[]) {

	/* hi */
	double secs;
	clock_t ticks;
	unsigned long int *vertex_addresses; 
	int start, target, file_size, file_pos, level, sum, found = 0;
	char *file_buffer, file[] = "Graphs/graph4.txt";
	Graph *graph;
	Result *result, *rhead; 

	/* yeah, dangerous, since never re-allocated - f**k that and save time :~D */
	vertex_addresses = (unsigned long int *)malloc(2500000 * sizeof(unsigned long int));

	result = new_result();
	rhead = result;

	/* run clock */
	ticks = clock();

		/* input */
		switch(argc) {
			case 2:
				file_buffer = load_file(argv[1], &file_size);
				break;
			case 1:
				file_buffer = load_file(file, &file_size);
				break;
			default:
				printf("\nFehlerhafte Eingabe\n\n");
				exit(1);
		}

		/* organize */
		start = get_start(file_buffer);
		target = get_target(file_buffer);
		graph = build_graph(file_buffer, file_size, vertex_addresses);

		/* search */
		for(level = SEARCH_INIT_LEVEL, found = 0; found != 1 && level < 1000; level++)
			found = iterative_deepening(graph->vertices->next_vertex, target, level, &result, 0);

		/* format + output */
		for(sum = 0; rhead->next; rhead = rhead->next)
			sum += rhead->next->cost;

		if(sum) {
			printf("\n%d\n", sum);

			while(result->prev && result->prev->state) {
				if(result->prev->state != result->state)
				printf("Z%d ", result->state);
				result = result->prev;
			}
			printf("Z%d\n\n", result->state);
		} else
			printf("\nZiel nicht erreichbar\n\n");
	
	/* stop clock */
	ticks = clock() - ticks;
	secs = ((double)ticks) / CLOCKS_PER_SEC;
	printf("\n\n(Duration %.3lf seconds)\n", secs);

	/* bye */
	free(vertex_addresses); 
	free(file_buffer); 
	return(0); 
}