示例#1
0
        static string ParsePieceMovement(string movement)
        {
            string output = "";

            ChessCoordinates cc1 = Coordinates(movement.Substring(0, 2));

            ChessCoordinates cc2 = Coordinates(movement.Substring(3));

            ColumnCoordinates col1 = GetColumnFromChar(cc1.Column);

            ColumnCoordinates col2 = GetColumnFromChar(cc2.Column);

            if (board[cc1.Row - 1, col1.GetHashCode()].Piece != null)
            {
                if (board[cc1.Row - 1, col1.GetHashCode()].Piece.ValidMovement(cc1, cc2))
                {
                    board[cc2.Row - 1, col2.GetHashCode()].Piece = board[cc1.Row - 1, col1.GetHashCode()].Piece;
                    board[cc1.Row - 1, col1.GetHashCode()].Piece = null;
                    output = $"The piece at {cc1.ToString()} has moved to {cc2.ToString()}.";
                }
                else
                {
                    output = "F**k you it didn't work";
                }
            }
            else
            {
                output = $"I'm not seeing a piece at {cc1.ToString()}";
            }


            return(output);
        }
示例#2
0
        static string ParsePiecePlacement(string message)
        {
            string output = "";
            string color  = "";
            string piece  = "";

            if (string.Equals(message[1].ToString(), "l", StringComparison.CurrentCultureIgnoreCase))
            {
                color = "White";
            }
            else if (string.Equals(message[1].ToString(), "d", StringComparison.CurrentCultureIgnoreCase))
            {
                color = "Black";
            }
            switch (message[0])
            {
            case 'Q':
                piece   = "Q";
                output += $"Place the {color} Queen at ";
                break;

            case 'K':
                piece   = "K";
                output += $"Place the {color} King at ";
                break;

            case 'B':
                piece   = "B";
                output += $"Place the {color} Bishop at ";
                break;

            case 'N':
                piece   = "N";
                output += $"Place the {color} Knight at ";
                break;

            case 'R':
                piece   = "R";
                output += $"Place the {color} Rook at ";
                break;

            case 'P':
                piece   = "P";
                output += $"Place the {color} Pawn at ";
                break;
            }
            ChessCoordinates cc = Coordinates(message.Substring(2));

            InitialPlacement(piece, color, cc);
            return(output += cc.ToString());
        }
示例#3
0
        static string ParseCastling(string move)
        {
            string output = "";

            string[] moves = move.Split(' ');

            ChessCoordinates cc1 = Coordinates(moves[0]);
            ChessCoordinates cc2 = Coordinates(moves[1]);
            ChessCoordinates cc3 = Coordinates(moves[2]);
            ChessCoordinates cc4 = Coordinates(moves[3]);

            CastleMovement(cc1, cc2, cc3, cc4);

            output = $"The piece at {cc1.ToString()} moved to {cc2.ToString()} and the piece at {cc3.ToString()} moved to {cc4.ToString()}.";

            return(output);
        }