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

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

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

            BoardLogic.ColumnCoordinates col1 = GetColumnFromChar(cc1.Column);

            BoardLogic.ColumnCoordinates col2 = GetColumnFromChar(cc2.Column);

            if (Program.board[cc1.Row - 1, col1.GetHashCode()].Piece != null)
            {
                if (Program.board[cc1.Row - 1, col1.GetHashCode()].Piece.ValidMovement(cc1, cc2))
                {
                    Program.board[cc2.Row - 1, col2.GetHashCode()].Piece = Program.board[cc1.Row - 1, col1.GetHashCode()].Piece;
                    Program.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 void InitialPlacement(string piece, string color, BoardLogic.ChessCoordinates coordinates)
        {
            BoardLogic.ColumnCoordinates column = GetColumnFromChar(coordinates.Column);
            switch (piece)
            {
            case "Q":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.Queen();
                break;

            case "K":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.King();
                break;

            case "B":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.Bishop();
                break;

            case "N":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.Knight();
                break;

            case "R":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.Rook();
                break;

            case "P":
                Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Models.Pawn();
                break;
            }
            Program.board[(coordinates.Row - 1), (column.GetHashCode())].Piece.IsLight = (color == "White") ? true : false;
        }
示例#3
0
        static void CastleMovement(BoardLogic.ChessCoordinates Piece1MoveFrom, BoardLogic.ChessCoordinates Piece1MoveTo, BoardLogic.ChessCoordinates Piece2MoveFrom, BoardLogic.ChessCoordinates Piece2MoveTo)
        {
            Program.board[Piece1MoveTo.Row - 1, GetColumnFromChar(Piece1MoveTo.Column).GetHashCode()].Piece     = Program.board[Piece1MoveFrom.Row - 1, GetColumnFromChar(Piece1MoveFrom.Column).GetHashCode()].Piece;
            Program.board[Piece1MoveFrom.Row - 1, GetColumnFromChar(Piece1MoveFrom.Column).GetHashCode()].Piece = null;

            Program.board[Piece2MoveTo.Row - 1, GetColumnFromChar(Piece2MoveTo.Column).GetHashCode()].Piece     = Program.board[Piece2MoveFrom.Row - 1, GetColumnFromChar(Piece2MoveFrom.Column).GetHashCode()].Piece;
            Program.board[Piece2MoveFrom.Row - 1, GetColumnFromChar(Piece2MoveFrom.Column).GetHashCode()].Piece = null;
        }
示例#4
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;
            }
            BoardLogic.ChessCoordinates cc = BoardLogic.Coordinates(message.Substring(2));
            InitialPlacement(piece, color, cc);
            return(output += cc.ToString());
        }
示例#5
0
        static string ParseCastling(string move)
        {
            string output = "";

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

            BoardLogic.ChessCoordinates cc1 = BoardLogic.Coordinates(moves[0]);
            BoardLogic.ChessCoordinates cc2 = BoardLogic.Coordinates(moves[1]);
            BoardLogic.ChessCoordinates cc3 = BoardLogic.Coordinates(moves[2]);
            BoardLogic.ChessCoordinates cc4 = BoardLogic.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);
        }