示例#1
0
void initialize()
{
    move_sp = move_stack;
    chessclock[0]=chessclock[1]=10*60*1000;
    clockinc = 0;

    branch_info.average = 0.0;
    branch_info.count = 0;

    if (book_mode)
    {
	change_gamemode(OPENING, 0);
	loadbook(bookfile);
    }
    else
    {
    	change_gamemode(MIDGAME, 1);
    }
    
    setupboard();

    ponder_mode = 0;
    
    init_learning();
    
    ply = 0;
    searchdepth = midgamedepth;

    computer[WHITE]=0;
    computer[BLACK]=searchdepth;
    
    loadrc();
}
示例#2
0
文件: learn.c 项目: cwbowron/BCE
/*
  returns the gradient with respect to weight w in board *b
  using the formulat (f(x+h)-f(x)) / h
*/
double gradient(int w, chessboard *b, int index)
{
    int v1, v2;
    chessboard *temp_board = board;

    board = b;

    if (gamemode != actualmode())
	change_gamemode(actualmode(), 0);
    
    countmaterial();
    v1 = eval_for_white();
    
    base_weights[w] += EPSILON;
    countmaterial();
    v2 = eval_for_white();

    base_weights[w] -= EPSILON;	/* restore weight */
    board = temp_board;		/* restore board */
    
    return (double)(v2-v1)/(double)EPSILON;
}
示例#3
0
void cmd_fen(char *s)
{
    char pos[80];
    char color;
    char castling[4];
    char enpassante[2];
    int halfmove, fullmove;
    int f, r, i;

    FILE *in = fopen(s+1, "r");

    if (!in)
    {
	printf("cmd_fen(): error opening %s\n", s+1);
	return;
    }

    change_gamemode(MIDGAME, 1);
    
    fscanf(in, "%s %c %s %s %d %d", pos, &color, castling, enpassante, &halfmove, &fullmove);

    printf("pos: %s\ncolor: %c\ncastling: %s\nenpassante: %s\n",
	   pos, color, castling, enpassante);

    for (i=0;i<64;i++) setpiece__(i,empty);

    f = 0;
    r = 7;
    for (i=0;i<strlen(pos);i++)
    {
	chesspiece p;

	if (pos[i]=='/')
	{
	    r--;
	    f=0;
	    printf("new rank: %d\n", r);
	}
	else if ((pos[i]>='1')&&(pos[i]<='9'))
	{
	    f += pos[i]-'0';
	}
	else if ((p=lookup(pos[i])))
	{
	    setpiece(f,r,p);
	    printf("%c @ %c%d\n", rep(p), f+'a',r);
	    f++;
	}
	else
	{
	    printf("unknown character in fen position string: %s[%d]\n", pos, i);
	    exit(EXIT_FAILURE);
	}
    }
    
    countmaterial();
    board->flags = 0;
    ply = 0;
    
    if (!strcmp(enpassante, "-"))
    {
	gamestack[ply]=dummymove;
    }
    else
    {
	int file = enpassante[0]-'a';
	int rank = enpassante[1]-'1';

	board->flags |= enp;
	
	if (rank == 4)
	    gamestack[ply] = MV(SQ(file,6), SQ(file,4));
	else if (rank==3)
	    gamestack[ply] = MV(SQ(file,1), SQ(file,3));
	else
	    printf("cmd_fen(): error parsing enpassante square\n");
    }
    ply++;
    
    if (strchr(castling, 'Q'))
	board->flags |= wqc;
    if (strchr(castling, 'K'))
	board->flags |= wkc;
    if (strchr(castling, 'q'))
	board->flags |= bqc;
    if (strchr(castling, 'k'))
	board->flags |= bkc;
    
    if (color=='w')
	board->flags &= ~turn_flag;

    else if (color=='b')
	board->flags |= turn_flag;
    else
	printf("cmd_fen(): error parsing color\n");
}