Esempio n. 1
0
        internal string GeneratePGNString(Board board)
        {
            if (!string.IsNullOrEmpty(this.PgnMove))
            {
                return(this.PgnMove);
            }
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            byte num1  = (byte)((uint)this.MovingPiecePrimary.SrcPosition % 8U);
            byte num2  = (byte)(8 - (int)this.MovingPiecePrimary.SrcPosition / 8);
            byte num3  = (byte)((uint)this.MovingPiecePrimary.DstPosition % 8U);
            byte num4  = (byte)(8 - (int)this.MovingPiecePrimary.DstPosition / 8);

            this.PgnMove = "";
            for (byte index = 0; (int)index < 64; ++index)
            {
                if ((int)index != (int)this.MovingPiecePrimary.DstPosition)
                {
                    Square square = board.Squares[(int)index];
                    if (square.Piece != null && square.Piece.PieceType == this.MovingPiecePrimary.PieceType && square.Piece.PieceColor == this.MovingPiecePrimary.PieceColor)
                    {
                        foreach (int validMove in square.Piece.ValidMoves)
                        {
                            if (validMove == (int)this.MovingPiecePrimary.DstPosition)
                            {
                                flag3 = true;
                                int  num5 = (int)(byte)((uint)index % 8U);
                                byte num6 = (byte)(8 - (int)index / 8);
                                int  num7 = (int)num1;
                                if (num5 == num7)
                                {
                                    flag1 = true;
                                }
                                if ((int)num6 == (int)num2)
                                {
                                    flag2 = true;
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (this.MovingPieceSecondary.PieceType == ChessPieceType.Rook)
            {
                if (this.MovingPieceSecondary.PieceColor == ChessPieceColor.Black)
                {
                    if ((int)this.MovingPieceSecondary.SrcPosition == 7)
                    {
                        this.PgnMove = this.PgnMove + "O-O";
                    }
                    else if ((int)this.MovingPieceSecondary.SrcPosition == 0)
                    {
                        this.PgnMove = this.PgnMove + "O-O-O";
                    }
                }
                else if (this.MovingPieceSecondary.PieceColor == ChessPieceColor.White)
                {
                    if ((int)this.MovingPieceSecondary.SrcPosition == 63)
                    {
                        this.PgnMove = this.PgnMove + "O-O";
                    }
                    else if ((int)this.MovingPieceSecondary.SrcPosition == 56)
                    {
                        this.PgnMove = this.PgnMove + "O-O-O";
                    }
                }
            }
            else
            {
                this.PgnMove = this.PgnMove + MoveContent.GetPgnMove(this.MovingPiecePrimary.PieceType);
                switch (this.MovingPiecePrimary.PieceType)
                {
                case ChessPieceType.Queen:
                    if (flag3)
                    {
                        if (!flag1)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                            break;
                        }
                        if (flag2)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        }
                        this.PgnMove = this.PgnMove + (object)num2;
                        break;
                    }
                    break;

                case ChessPieceType.Rook:
                    if (flag3)
                    {
                        if (!flag1)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                            break;
                        }
                        if (flag2)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        }
                        this.PgnMove = this.PgnMove + (object)num2;
                        break;
                    }
                    break;

                case ChessPieceType.Bishop:
                    if (flag3)
                    {
                        if (!flag1)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                            break;
                        }
                        if (flag2)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        }
                        this.PgnMove = this.PgnMove + (object)num2;
                        break;
                    }
                    break;

                case ChessPieceType.Knight:
                    if (flag3)
                    {
                        if (!flag1)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                            break;
                        }
                        if (flag2)
                        {
                            this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        }
                        this.PgnMove = this.PgnMove + (object)num2;
                        break;
                    }
                    break;

                case ChessPieceType.Pawn:
                    if (flag3 && (int)num1 != (int)num3)
                    {
                        this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        break;
                    }
                    if (this.TakenPiece.PieceType != ChessPieceType.None)
                    {
                        this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        break;
                    }
                    break;
                }
                if (this.TakenPiece.PieceType != ChessPieceType.None)
                {
                    this.PgnMove = this.PgnMove + "x";
                }
                this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num3);
                this.PgnMove = this.PgnMove + (object)num4;
                if (this.PawnPromotedTo == ChessPieceType.Queen)
                {
                    this.PgnMove = this.PgnMove + "=Q";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Rook)
                {
                    this.PgnMove = this.PgnMove + "=R";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Bishop)
                {
                    this.PgnMove = this.PgnMove + "=B";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Knight)
                {
                    this.PgnMove = this.PgnMove + "=N";
                }
            }
            return(this.PgnMove);
        }
Esempio n. 2
0
        public new string ToString()
        {
            if (!string.IsNullOrEmpty(this.PgnMove))
            {
                return(this.PgnMove);
            }
            byte num1 = (byte)((uint)this.MovingPiecePrimary.SrcPosition % 8U);
            byte num2 = (byte)(8 - (int)this.MovingPiecePrimary.SrcPosition / 8);
            byte num3 = (byte)((uint)this.MovingPiecePrimary.DstPosition % 8U);
            byte num4 = (byte)(8 - (int)this.MovingPiecePrimary.DstPosition / 8);

            if (this.MovingPieceSecondary.PieceType == ChessPieceType.Rook)
            {
                if (this.MovingPieceSecondary.PieceColor == ChessPieceColor.Black)
                {
                    if ((int)this.MovingPieceSecondary.SrcPosition == 7)
                    {
                        this.PgnMove = this.PgnMove + "O-O";
                    }
                    else if ((int)this.MovingPieceSecondary.SrcPosition == 0)
                    {
                        this.PgnMove = this.PgnMove + "O-O-O";
                    }
                }
                else if (this.MovingPieceSecondary.PieceColor == ChessPieceColor.White)
                {
                    if ((int)this.MovingPieceSecondary.SrcPosition == 63)
                    {
                        this.PgnMove = this.PgnMove + "O-O";
                    }
                    else if ((int)this.MovingPieceSecondary.SrcPosition == 56)
                    {
                        this.PgnMove = this.PgnMove + "O-O-O";
                    }
                }
            }
            else
            {
                this.PgnMove = this.PgnMove + MoveContent.GetPgnMove(this.MovingPiecePrimary.PieceType);
                switch (this.MovingPiecePrimary.PieceType)
                {
                case ChessPieceType.Rook:
                    this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                    this.PgnMove = this.PgnMove + (object)num2;
                    break;

                case ChessPieceType.Knight:
                    this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                    this.PgnMove = this.PgnMove + (object)num2;
                    break;

                case ChessPieceType.Pawn:
                    if ((int)num1 != (int)num3)
                    {
                        this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num1);
                        break;
                    }
                    break;
                }
                if (this.TakenPiece.PieceType != ChessPieceType.None)
                {
                    this.PgnMove = this.PgnMove + "x";
                }
                this.PgnMove = this.PgnMove + MoveContent.GetColumnFromInt((int)num3);
                this.PgnMove = this.PgnMove + (object)num4;
                if (this.PawnPromotedTo == ChessPieceType.Queen)
                {
                    this.PgnMove = this.PgnMove + "=Q";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Rook)
                {
                    this.PgnMove = this.PgnMove + "=R";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Bishop)
                {
                    this.PgnMove = this.PgnMove + "=B";
                }
                else if (this.PawnPromotedTo == ChessPieceType.Knight)
                {
                    this.PgnMove = this.PgnMove + "=N";
                }
            }
            return(this.PgnMove);
        }