コード例 #1
0
        private static ChessBoard PerformBlackPawnCapture(ChessBoard board, string notation, ChessBoard tempboard)
        {
            char  pawnfile  = notation[0];
            char  enemyfile = notation[1];
            sbyte enemyrank = (sbyte)Char.GetNumericValue(notation[2]);
            sbyte pawnrank  = (sbyte)(enemyrank + 1);

            if (board[pawnfile, pawnrank] != -1)
            {
                throw new ArgumentException("wrong notation");
            }
            tempboard[pawnfile, pawnrank] = 0;
            if (DefaultInfo.WhiteEnPassantEndangered && enemyfile == DefaultInfo.EnPassantPossibleCapture.file && enemyrank == DefaultInfo.EnPassantPossibleCapture.rank)
            {
                tempboard[enemyfile, enemyrank + 1] = 0;
            }
            if (notation.Length == 3)
            {
                tempboard[enemyfile, enemyrank] = (sbyte)DefaultPieces.BlackPawn;
            }
            else
            {
                tempboard[enemyfile, enemyrank] = GetSbyteFromBlackPieceLetter(notation[3]);
            }
            if (BlackPawn.GetPossiblePositions(board, pawnfile, pawnrank).Contains(tempboard))
            {
                return(tempboard);
            }
            else
            {
                throw new ArgumentException("Wrong move");
            }
        }
コード例 #2
0
        private static ChessBoard PerformBlackPawnMove(ChessBoard board, string notation, ChessBoard tempboard)
        {
            //simple move (not 5 rank) and promotion
            if (notation[1] != '5')
            {
                sbyte pawnrank = (sbyte)(Char.GetNumericValue(notation[1]) + 1);
                char  pawnfile = notation[0];
                if (board[pawnfile, pawnrank] != (sbyte)DefaultPieces.BlackPawn)
                {
                    throw new ArgumentException("wrong move");
                }
                tempboard[pawnfile, pawnrank] = 0;
                if (notation.Length == 2)
                {
                    tempboard[pawnfile, pawnrank - 1] = (sbyte)DefaultPieces.BlackPawn;
                }
                else
                {
                    tempboard[pawnfile, pawnrank - 1] = GetSbyteFromBlackPieceLetter(notation[2]);
                }

                if (BlackPawn.GetPossiblePositions(board, pawnfile, pawnrank).Contains(tempboard))
                {
                    return(tempboard);
                }
                else
                {
                    throw new ArgumentException("Wrong move");
                }
            }
            //simple move (5 rank)
            else
            {
                char  pawnfile = notation[0];
                sbyte pawnrank;
                if (board[pawnfile, (sbyte)(Char.GetNumericValue(notation[1]) + 1)] == (sbyte)DefaultPieces.BlackPawn)
                {
                    pawnrank = (sbyte)(Char.GetNumericValue(notation[1]) + 1);
                }
                else if (board[pawnfile, (sbyte)(Char.GetNumericValue(notation[1]) + 2)] == (sbyte)DefaultPieces.BlackPawn && board[pawnfile, (sbyte)(Char.GetNumericValue(notation[1]) + 1)] == 0)
                {
                    pawnrank = (sbyte)(Char.GetNumericValue(notation[1]) + 2);
                }
                else
                {
                    throw new ArgumentException("Wrong move");
                }
                tempboard[pawnfile, pawnrank] = 0;
                tempboard[pawnfile, (sbyte)Char.GetNumericValue(notation[1])] = (sbyte)DefaultPieces.BlackPawn;

                if (BlackPawn.GetPossiblePositions(board, pawnfile, pawnrank).Contains(tempboard))
                {
                    //en passant
                    if (pawnrank == (sbyte)(Char.GetNumericValue(notation[1]) + 2))
                    {
                        DefaultInfo.EnPassantPossibleCapture = new Square(notation[0], (sbyte)(Char.GetNumericValue(notation[1]) + 1));
                        DefaultInfo.BlackEnPassantEndangered = true;
                    }
                    return(tempboard);
                }
                else
                {
                    throw new ArgumentException("Wrong move");
                }
            }
        }