Exemplo n.º 1
0
void cmd_inspect(char *s)
{
    int i;
  
    output("\tPawns : ");
    output("W : "); 
    for (i=1;i<9;i++) output("%d",board->pawns[0][i]);
    output(" B : ");
    for (i=1;i<9;i++) output("%d",board->pawns[1][i]);
    output("\n");

    output("\tFlags : %s\n", formatflags());

    if (ply)
    {
	undo u = undostack[ply-1];
	int v = board->flags;
      
	board->flags = u.flags;
	output("\tprevious move : %c took %c = %s : %s\n",
	       rep(u.moved), rep(u.captured), movestring(u.m), formatflags());
	board->flags = v;
    }
  
    if (fullincheckp(tomove()))
    {
	output("\tYou are currently in check : %d\n", fullincheckp(tomove()));
    }
}
Exemplo n.º 2
0
void genmoves_nocastles()
{
    int f,r;

    int col = tomove();
    for (f=0;f<8;f++)
    {
	for (r=0;r<8;r++)
	{
	    chesspiece p = getpiece(f,r);
	    if (p && (chesspiececolor(p) == col))
	    {
		int v = chesspiecevalue(p);
		if (v==king)
		{
		    getmovesk_nocastles(f,r,col);
		}
		else
		{
		    generators[v](f,r,col);
		}
	    }
	}
    }
}
Exemplo n.º 3
0
void cmd_new(char *s)
{
    if (gameoverp(tomove()) == IN_PROGRESS)
    {
	if (weight_mode)
	    update_weights(-2);
    }
    
    initialize();
}
Exemplo n.º 4
0
/*
ex. cd (cxd)
*/
move decode_pawn_cap(char *s)
{
    static char *c_index = "abcdefgh";
    int r, sf, ef;

    sf = strchr(c_index, s[0]) - c_index;
    ef = strchr(c_index, s[1]) - c_index;

    for (r=0;r<7;r++)
    {
	chesspiece p = getpiece(sf,r);
	if ((COLOR(p) == tomove()) &&
	    (VALUE(p) == pawn))
	{
	    chesspiece a = getpiece(ef, r+dir(COLOR(p)));
	    if (COLOR(a) != tomove())
		return MV(SQ(sf,r),SQ(ef,r+dir(COLOR(p))));
	}
    }

    return dummymove;
}
Exemplo n.º 5
0
Arquivo: hash.c Projeto: cwbowron/BCE
void compute_hash()
{
  int x;
  board->hash = 0;
  for (x=0;x<64;x++)
  {
      chesspiece p;
      if ((p=getpiece__(x)))
      {
	  board->hash ^= randoms[p][x];
      }
  }  
  board->hash ^= tomove();
}
Exemplo n.º 6
0
void printboard_and_time()
{
    int full, part;
    
    printboard();
    
    printf("W %s\t", formattime(chessclock[WHITE]));
    printf("B %s\n", formattime(chessclock[BLACK]));

    full = fullincheckp(tomove());
    part = ply ? incheckp(tomove()) : 0;
    
    if (full)
	printf("In Check : %d\n", full);

    if ((part &&  !full)||(full && !part))
    {
	printf("partial checktest (%d) and full checktest (%d) do no agree\n",
	       part, full);
    }
    
    printf("%c To Move\n", (tomove()==WHITE) ? 'W' : 'B');
}
Exemplo n.º 7
0
QString Note::setCategory(QString cat) const
{
    QString new_cat_path = appendPath(notesFolder().absolutePath(), cat);
    QString new_file_path = appendPath(new_cat_path,
                                       QFileInfo(m_path).fileName());

    QDir new_cat_dir(new_cat_path);
    if (!new_cat_dir.exists())
        new_cat_dir.mkpath(new_cat_path);

    QFile tomove(m_path);
    tomove.rename(new_file_path);

    return new_file_path;
}
Exemplo n.º 8
0
void genmoves()
{
    int f,r;

    int col = tomove();
    for (f=0; f<8; f++)
        for (r=0; r<8; r++)
        {
            chesspiece p = getpiece(f,r);
            if (p && (chesspiececolor(p) == col))
            {
                int v = chesspiecevalue(p);
                generators[v](f,r,col);
            }
        }
}
Exemplo n.º 9
0
void genattacks()
{
    int f,r;

    int col = tomove();
    for (f=0; f<8; f++)
        for (r=0; r<8; r++)
        {
            chesspiece p = getpiece(f,r);

            if (p && (chesspiececolor(p)==col))
            {
                int v;
                v = chesspiecevalue(p);
                attackgens[v](f,r,col);
            }
        }
}
Exemplo n.º 10
0
char *formatflags()
{
    static char fmt[20];
    
    fmt[0] = flag_test(wqcastlep(), 'Q');
    fmt[1] = flag_test(wkcastlep(), 'K');
    fmt[2] = flag_test(bqcastlep(), 'q');
    fmt[3] = flag_test(bkcastlep(), 'k');
    fmt[4] = flag_test(castledp(), 'C');
    fmt[5] = flag_test(enpassantedp(), 'E');
    fmt[6] = flag_test(doublepushp(), 'P');
    fmt[7] = flag_test(wkcastledp(), 'K');
    fmt[8] = flag_test(wqcastledp(), 'Q');
    fmt[9] = flag_test(bkcastledp(), 'k');
    fmt[10] = flag_test(bqcastledp(), 'q');
    fmt[11] = tomove() == WHITE ? 'W' : 'B';
    fmt[12] = 0;

    return fmt;
}
Exemplo n.º 11
0
void cmd_otim(char *s){int v;sscanf(s, "%d", &v);chessclock[tomove()] = v*10;}
Exemplo n.º 12
0
void cmd_time(char *s){int v;sscanf(s, "%d", &v);chessclock[opp(tomove())] = v*10;}
Exemplo n.º 13
0
Arquivo: learn.c Projeto: cwbowron/BCE
void save_leaf(move *pv, int n, int value, int hashed)
{
#ifndef LEARNING
    return;
#else
    int s_ply = ply;
    int searched_value = -1;
    int stored_board_value = -1;

    
    if (tomove() != WHITE)
	value = -value;

    stored.search_results[stored.index] = value;

    /* first check our stored position */
    if (stored.boards[stored.index]->piececount[0]>0)
    {
	chessboard *temp_board = board;

	board = stored.boards[stored.index];
	countmaterial();
	
	stored_board_value = eval_for_white();

	board = temp_board;
	countmaterial();

	if (((stored_board_value > (value - EVAL_INTERVAL)) &&
	    (stored_board_value < (value + EVAL_INTERVAL))) ||
	    (value > WIN - 50) ||
	    (value < LOSE + 50))
	{
	    stored.usable[stored.index] = 1;
	    stored.actual[stored.index] = stored_board_value;
	    printf("STORING: qsearch board = %d\n", stored_board_value);
	}
    }

    /* then check to see if our value is the same as our last search */
    if (!stored.usable[stored.index])
    {
	if ((stored.search_results[stored.index] ==
	     stored.search_results[stored.index-1]))
	{
	    memcpy(stored.boards[stored.index], stored.boards[stored.index-1],
		   sizeof(chessboard));
	    stored.usable[stored.index] = 1;
	    stored.actual[stored.index] = stored.actual[stored.index]-1;
	    printf("STORING: previous board = %d\n",
		   stored.search_results[stored.index-1]);
	}
    }

    /* lastly check to see if our pv leads to a correct board eval */
    if (!stored.usable[stored.index])
    {
	int i;
	
	printf("pv: ");
	for (i=0;i<n;i++)
	{
	    if (pv[i] == dummymove)
		break;

	    domove(pv[i]);
	    printf("%s ", movestring(pv[i]));
	}
	printf("\n");
    
	searched_value = eval_for_white();
	
	if ((searched_value > value - EVAL_INTERVAL)&&
	    (searched_value < value + EVAL_INTERVAL))
	{
	    memcpy(stored.boards[stored.index], board, sizeof(chessboard));
	    stored.usable[stored.index] = 1;
	    stored.actual[stored.index] = searched_value;
	    printf("STORING: pv board = %d\n", searched_value);
	}
	else
	{
	    printf("!usable: stored_position %d, "
		   "searched %d, previous %d, stored %d\n",
		   stored_board_value, searched_value,
		   stored.search_results[stored.index-1], value);
	}
	
	while (ply>s_ply)
	    undomove();
    }
    
#endif
    
}
Exemplo n.º 14
0
move easydecode(char *str)
{
    if (!strcmp(str,"o")||!strcmp(str,"o-o")||
	!strcmp(str,"0-0")||!strcmp("O-O",str))
    {
	return (tomove() == WHITE) ? WKC : BKC;
    }

    if (!strcmp(str,"o-")||!strcmp(str,"o-o-o")||
	!strcmp(str,"0-0-0")||!strcmp("O-O-O",str))
    {
	return (tomove() == WHITE) ? WQC : BQC;
    }

    strip(str);

    if (strlen(str)==5)
    {
	/* assume this is the form a7a8q */
	/* get promo and remove from string */
	chesspiece p = lookup(str[4]);
	promopiece = chesspiecevalue(p);

	if ((promopiece<=0)||(promopiece>king))
	    return dummymove;
	
	str[4]=0;
    }
    
    /* e4 */
    if (strlen(str)==2)
    {
	int ef, er;
	square s1, s2;

	ef = str[0]-'a';
	er = str[1]-'1';

	if (strchr("abcdefgh", str[0]) &&
	    strchr("abcdefgh", str[1]))
	{
	    return decode_pawn_cap(str);
	}
	
	if (offboardp(ef, er))
	    return dummymove;
	
	s2 = SQ(ef,er);
	s1 = findstart(makepiece(tomove(), pawn), ef, er, 8, 8);
	return MV(s1,s2);
    }

    /* Pe4 ab4 */
    if (strlen(str)==3)
    {
	int sf, ef, er;
	square s1 = dummymove, s2;

	ef = str[1]-'a';
	er = str[2]-'1';

	if (offboardp(ef, er))
	    return dummymove;

	s2 = SQ(ef,er);
	if (str[0]=='b')
	{
	    /* if its a valid pawn move it,
	       else look for valid Bishop move
	    */
	    int v = chesspiecevalue(lookup(str[0]));
	    sf = str[0] - 'a';
	    s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8);
	    if (s1!=dummysq)
	    {
		return MV(s1,s2);
	    }
	    else if (v)
	    {
		s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8);
		return MV(s1,s2);
	    }
	    else
		return dummysq;
	}
	else if (lookup(str[0]))
	{
	    int v = chesspiecevalue(lookup(str[0]));
	    s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8);
	}
	else
	{
	    sf = str[0] - 'a';
	    s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8);
	}
	return (MV(s1,s2));
    }
    
    /* e2e4 Nbd7 N8d7*/
    else if (strlen(str)==4)
    {
	int sf, sr, ef, er, v;
	square s1, s2;
	
	sf = str[0]-'a';
	sr = str[1]-'1';
	ef = str[2]-'a';
	er = str[3]-'1';

	if (offboardp(ef, er))
	    return dummymove;

	if (!offboardp(sf, sr))
	    return MV(SQ(sf,sr),SQ(ef,er));
	
	s2 = SQ(ef, er);
	s1 = SQ(sf, sr);
	
	switch (str[0])
	{
	    case 'P': case 'p':
	    case 'N': case 'n':
	    case 'B': case 'b':
	    case 'R': case 'r':
	    case 'Q': case 'q':
	    case 'K': case 'k':
		sf = str[1]-'a';
		sr = str[1]-'1';
		v = chesspiecevalue(lookup(str[0]));
		if ((sf>=0)&&(sf<=7))
		{
		    s1 = findstart(makepiece(tomove(), v), ef, er, sf, 8);
		    return MV(s1, s2);
		}
		else
		{
		    s1 = findstart(makepiece(tomove(), v), ef, er, 8, sr);
		    return MV(s1, s2);
		}
		
	    default:
		return dummymove;
	}
    }
    else
	return dummymove;
}
Exemplo n.º 15
0
/* returns -1 for stalemate or winner's color */
int playchess()
{
    int use_pondering = 0;
    
    printboard_and_time();
     
    for (;;)
    {
	long starttime, endtime;
	move m;
	int g;

	g = gameoverp(tomove());

	if (g)
	{
	    switch (g)
	    {
		case END_CHECKMATE:
		    if (tomove() == BLACK)
		    {
			return end(WHITE, "white mates");
		    }
		    else
		    {
			return end(BLACK, "black mates");
		    }
		case END_STALEMATE:
		    return end(-1, "stalemate");
		case NON_MATERIAL:
		    return end(-1, "insufficient material");
		case REP_DRAW:
		    if (!robo_mode)
		    {
			printf("drawable position\n");
		    }
		    if (computer[WHITE]||computer[BLACK])
		    {
			if (robo_mode)
			    tellics("draw\n");
			return end(-1, "draw by repetition of moves");
		    }
		    break;
	    }
	}
    
	starttime = get_ms();
	
	if (computer[tomove()])
	{
	    m = bce();

	    if ((m!=dummymove)&&(validmove(m)==1))
	    {
		printf("move %s\n", movestring(m));
	    }
	    else
	    {
		if (robo_mode)
		{
		    tellics("mailmoves\n");
		    tellics(
			"message madhacker valid? = %d, move = %s, wouldbeincheckp() = %d, wouldbeinfullcheckp() = %d, pv = %s\n",
			validmove(m),
			movestring(m),
			wouldbeincheckp(m),
			wouldbeincheckfullp(m),
			thoughts);
		    tellics("abort\n");
		}
		else
		{
		    printf("BCE returned invalid move: %s\n", movestring(m));
		    printf("valid? = %d\n", validmove(m));

		    fprintf(stdout, "random seed = %ld\n", seed);
		    fprintf(stdout, "hash = %lld\n", board->hash);
		    fprintf(stdout, "draw? = %d g = %d\n",
			    draw_by_rep(), g);
		    computer[1] = computer[0] = 0;
		}
	    }
	    use_pondering = 1;
	}
	else 
	{
	    if ((ponder_mode && computer[opp(tomove())])&&
		use_pondering)
	    {
		ponder();
		use_pondering = 0;
	    }
	    
	    m = usermove();
	    use_pondering = 0;
	}
    
	endtime = get_ms();
	chessclock[tomove()] -= (endtime-starttime);
	chessclock[tomove()] += clockinc;
    
	if (m)
	{
	    domove(m);
	    update_state(m);
	    printboard_and_time();
	}
    }
}
Exemplo n.º 16
0
Arquivo: learn.c Projeto: cwbowron/BCE
int eval_for_white()
{
    return (tomove() == WHITE) ? evaluate() : -evaluate();
}
Exemplo n.º 17
0
void cmd_go(char *s)
{
    computer[opp(tomove())]=0;
    computer[tomove()]=searchdepth;
}
Exemplo n.º 18
0
void cmd_moves(char *s){printmoves(tomove());}
Exemplo n.º 19
0
void cmd_go(char *s)
{
    computer[opp(tomove())]=0;
    computer[tomove()]=1;
}