src/arasanx.cpp
// handle editing the chessboard (Winboard mode)
handle editing the chessboard (Winboard mode)
handle editing the chessboard ( Winboard mode )
static void edit_board(istream &fin, Board &board)
{
    for (int i = 0; i < 64; i++)
        board.setContents(EmptyPiece,i);
    static char buf[80];
    static const char pieces[]="PNBRQKpnbrqk";
    ColorType side = White;
    while (fin.getline(buf,80)) {
        if (strcmp(buf,"white") == 0)
            side = White;
        else if (strcmp(buf,"black")==0)
            side = Black;
        else if (*buf == '#') {
            for (int i = 0; i < 64; i++)
                board.setContents(EmptyPiece,i);
        }
        else if (strcmp(buf,"c")==0)
            side = OppositeColor(side);
        else if (strcmp(buf,".")==0)
            break;
        else {
            if (strchr(pieces,buf[0])) {
                char c = tolower(buf[0]);
               Piece p = EmptyPiece;
               switch (c) {
               case 'p':
                   p = MakePiece(Pawn,side);
                   break;
               case 'n':
                   p = MakePiece(Knight,side);
                   break;
               case 'b':
                   p = MakePiece(Bishop,side);
                   break;
               case 'r':
                   p = MakePiece(Rook,side);
                   break;
               case 'q':
                   p = MakePiece(Queen,side);
                   break;
               case 'k':
                   p = MakePiece(King,side);
                   break;
               default:
                   break;
                }
                if (p != EmptyPiece) {
                    Square sq = SquareValue(buf+1);
                    if (!IsInvalid(sq))
                        board.setContents(p,sq);
                }
            }
        }
    }
    board.setSecondaryVars();
    if (board.kingSquare(White) == chess::E1) {
       if (board[chess::A1] == WhiteRook &&
           board[chess::H1] == WhiteRook)
            board.setCastleStatus(CanCastleEitherSide,White);
       else if (board[chess::A1] == WhiteRook)
            board.setCastleStatus(CanCastleQSide,White);
       else if (board[chess::H1] == WhiteRook)
            board.setCastleStatus(CanCastleKSide,White);
    }
    else
        board.setCastleStatus(CantCastleEitherSide,White);
    if (board.kingSquare(Black) == chess::E8) {
       if (board[chess::A8] == BlackRook &&
           board[chess::H8] == BlackRook)
            board.setCastleStatus(CanCastleEitherSide,Black);
       else if (board[chess::A8] == BlackRook)
            board.setCastleStatus(CanCastleQSide,Black);
       else if (board[chess::H8] == BlackRook)
            board.setCastleStatus(CanCastleKSide,Black);
    }
    else
        board.setCastleStatus(CantCastleEitherSide,Black);
}
static void edit_board ( istream & fin , Board & board ) { for ( int i = 0 ; i < 64 ; i ++ ) board . setContents ( EmptyPiece , i ) ; static char buf [ 80 ] ; static const char pieces [ ] = " " ; ColorType side = White ; while ( fin . getline ( buf , 80 ) ) { if ( strcmp ( buf , " " ) == 0 ) side = White ; else if ( strcmp ( buf , " " ) == 0 ) side = Black ; else if ( * buf == ' ' ) { for ( int i = 0 ; i < 64 ; i ++ ) board . setContents ( EmptyPiece , i ) ; } else if ( strcmp ( buf , " " ) == 0 ) side = OppositeColor ( side ) ; else if ( strcmp ( buf , " " ) == 0 ) break ; else { if ( strchr ( pieces , buf [ 0 ] ) ) { char c = tolower ( buf [ 0 ] ) ; Piece p = EmptyPiece ; switch ( c ) { case ' ' : p = MakePiece ( Pawn , side ) ; break ; case ' ' : p = MakePiece ( Knight , side ) ; break ; case ' ' : p = MakePiece ( Bishop , side ) ; break ; case ' ' : p = MakePiece ( Rook , side ) ; break ; case ' ' : p = MakePiece ( Queen , side ) ; break ; case ' ' : p = MakePiece ( King , side ) ; break ; default : break ; } if ( p != EmptyPiece ) { Square sq = SquareValue ( buf + 1 ) ; if ( ! IsInvalid ( sq ) ) board . setContents ( p , sq ) ; } } } } board . setSecondaryVars ( ) ; if ( board . kingSquare ( White ) == chess :: E1 ) { if ( board [ chess :: A1 ] == WhiteRook && board [ chess :: H1 ] == WhiteRook ) board . setCastleStatus ( CanCastleEitherSide , White ) ; else if ( board [ chess :: A1 ] == WhiteRook ) board . setCastleStatus ( CanCastleQSide , White ) ; else if ( board [ chess :: H1 ] == WhiteRook ) board . setCastleStatus ( CanCastleKSide , White ) ; } else board . setCastleStatus ( CantCastleEitherSide , White ) ; if ( board . kingSquare ( Black ) == chess :: E8 ) { if ( board [ chess :: A8 ] == BlackRook && board [ chess :: H8 ] == BlackRook ) board . setCastleStatus ( CanCastleEitherSide , Black ) ; else if ( board [ chess :: A8 ] == BlackRook ) board . setCastleStatus ( CanCastleQSide , Black ) ; else if ( board [ chess :: H8 ] == BlackRook ) board . setCastleStatus ( CanCastleKSide , Black ) ; } else board . setCastleStatus ( CantCastleEitherSide , Black ) ; }
handle editing the chessboard (Winboard mode)
handle editing the chessboard ( Winboard mode )
// edit doesn't set the castle status, so try to deduce it // from the piece positions