Ejemplo n.º 1
0
/* ----------------------------------------------------------------------- */
void do_a_file(FILE *f)
{
   char *start;

   if ( (start =  findstart(f)) != (char *)ERRVAL) /* find the starting point */
     printfrom(start, f);               /* print from there to end */

}
Ejemplo n.º 2
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;
}