Example #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);
        }
Example #2
0
        static ChessCoordinates Coordinates(string movement)
        {
            int.TryParse(movement[1].ToString(), out int number);
            ChessCoordinates coordinates = new ChessCoordinates(movement[0], number, null);

            return(coordinates);
        }
Example #3
0
        static void InitialPlacement(string piece, string color, ChessCoordinates coordinates)
        {
            ColumnCoordinates column = GetColumnFromChar(coordinates.Column);

            switch (piece)
            {
            case "Q":
                board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Queen();
                break;

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

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

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

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

            case "P":
                board[(coordinates.Row - 1), (column.GetHashCode())].Piece = new Pawn();
                break;
            }
            board[(coordinates.Row - 1), (column.GetHashCode())].Piece.IsLight = (color == "White") ? true : false;
            Console.WriteLine("Yeet" + board[(coordinates.Row - 1), (column.GetHashCode())]);
        }
Example #4
0
        static void CastleMovement(ChessCoordinates Piece1MoveFrom, ChessCoordinates Piece1MoveTo, ChessCoordinates Piece2MoveFrom, ChessCoordinates Piece2MoveTo)
        {
            board[Piece1MoveTo.Row - 1, GetColumnFromChar(Piece1MoveTo.Column).GetHashCode()].Piece     = board[Piece1MoveFrom.Row - 1, GetColumnFromChar(Piece1MoveFrom.Column).GetHashCode()].Piece;
            board[Piece1MoveFrom.Row - 1, GetColumnFromChar(Piece1MoveFrom.Column).GetHashCode()].Piece = null;

            board[Piece2MoveTo.Row - 1, GetColumnFromChar(Piece2MoveTo.Column).GetHashCode()].Piece     = board[Piece2MoveFrom.Row - 1, GetColumnFromChar(Piece2MoveFrom.Column).GetHashCode()].Piece;
            board[Piece2MoveFrom.Row - 1, GetColumnFromChar(Piece2MoveFrom.Column).GetHashCode()].Piece = null;
        }
Example #5
0
 static void InitializeBoard()
 {
     char[] columnLetters = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             board[i, j] = new ChessCoordinates(columnLetters[i], j, null);
         }
     }
 }
Example #6
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());
        }
Example #7
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);
        }
Example #8
0
 static void PlaceOnBoard(ChessCoordinates currentPlace, ChessCoordinates placeToGo)
 {
     //need a board to do this part but I'm gonna remove the piece from its space on the board and put it at the new space
     //actually wtf
 }