Exemplo n.º 1
0
void UCI()
{
    char str[8192];
    char *p;
    
    printf("id name chess\n");
    printf("id author komendart\n");
    printf("uciok\n");
    fflush(stdout);
    
    while(1)
    {
        gets(str);
        p = strtok(str, " ");
        if(!p)
        {
            continue;
        }
        else if(!strcmp(p, "quit"))
        {
            return;
        }
        else if(!strcmp(p, "isready"))
        {
            printf("readyok\n");
            fflush(stdout);
        }
        else if(!strcmp(p, "position"))
        {
            p = strtok(0, " ");
            if(!strcmp(p, "fen"))
			{
				p = strtok(0, "m");
				setup_position(p);
			}
            else
            {
                setup_position(start_fen);
            }
            if (p = strtok(0, " "))
			{
				while(p = strtok(0, " "))
				{
					Move m = str_to_move(p);
					make_move(m);
				}
			}
        }
        else if(!strcmp(p, "go"))
        {
            int depth_limit = 8;
            while (p = strtok(0, " "))
			{
                if(!strcmp(p, "depth"))
				{
					p = strtok(0, " ");
					depth_limit = atoi(p);
				}
            }
            Move move = search(depth_limit);
            char tmp[6];
            move_to_str(move, tmp);
            sprintf(str, "bestmove %s\n", tmp);
            printf(str);
            fflush(stdout);
        }
    }
}
Exemplo n.º 2
0
void console()
{
    char str[100];
    Move movelist[256];
    int n;
    int depth_limit = 8;
    setup_position(start_fen);
    
    printf("white or black?\n");
    while(1)
    {
        gets(str);
        if(!strcmp(str, "white") || ! strcmp(str, "black"))
        {
            break;
        }
    }
    int is_reversed;
    if(!strcmp(str, "black"))
    {
        is_reversed = 1;
        print_position(is_reversed);
        Move bestmove = search(depth_limit);
        make_move(bestmove);
    }
    else
    {
        is_reversed = 0;
    }
    
    while(1)
    {
        print_position(is_reversed);
        n = generate_moves(movelist);
        if(n == 0)
        {
            while(1);
        }
        int flag = 1;
        while(flag)
        {
            gets(str);
            Move move = str_to_move(str);
            for(int i = 0; i < n; i += 1)
            {
                Move i_move = movelist[i]; 
                if(move == i_move)
                {
                    make_move(move);
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                printf("Incorrect\n");
            }
        }
        
        print_position(is_reversed);
        Move bestmove = search(depth_limit);
        if(bestmove == 0)
        {
            while(1);
        }
        make_move(bestmove);
    }
}
Exemplo n.º 3
0
void create() {
   ::create();
   setup_position("lie", "down", LYING);
} /* create() */