Esempio n. 1
0
        /** This Function sets the squares this piece is able to move to.
         * The queen is able to move in any direction like a bishop and
         * a rook combined.
         * @param a_board - The chessboard the queen is on
         * @author Thomas Hooper
         * @date February 2019
         */
        public override void SetValidSquares(Board a_board)
        {
            List <BoardSquare> squares = new List <BoardSquare>();
            Rook   r = new Rook(this.Row, this.Column, 0, this.Color, "a");
            Bishop b = new Bishop(this.Row, this.Column, 0, this.Color, "a");

            r.SetValidSquares(a_board);
            b.SetValidSquares(a_board);
            squares = r.ValidSquares;
            squares.AddRange(b.ValidSquares);
            ValidSquares     = squares;
            AttackingSquares = squares;
        }
Esempio n. 2
0
        public void AddPieceToBoard(string pieceName, int pieceRow, int pieceCol, bool isWhite, bool isFirstMove)
        {
            switch (pieceName)
            {
            case "Pawn":
                _ = new Pawn(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;

            case "Knight":
                _ = new Knight(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;

            case "King":
                _ = new King(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;

            case "Rook":
                _ = new Rook(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;

            case "Bishop":
                _ = new Bishop(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;

            case "Queen":
                _ = new Queen(isWhite, Board[pieceRow, pieceCol])
                {
                    IsFirstMove = isFirstMove
                };
                break;
            }
        }
Esempio n. 3
0
        public void NewGame()
        {
            ClearBoard();

            _ = new Pawn(true, Board[6, 0]);
            _ = new Pawn(true, Board[6, 1]);
            _ = new Pawn(true, Board[6, 2]);
            _ = new Pawn(true, Board[6, 3]);
            _ = new Pawn(true, Board[6, 4]);
            _ = new Pawn(true, Board[6, 5]);
            _ = new Pawn(true, Board[6, 6]);
            _ = new Pawn(true, Board[6, 7]);

            _ = new Rook(true, Board[7, 0]);
            _ = new Knight(true, Board[7, 1]);
            _ = new Bishop(true, Board[7, 2]);
            _ = new Queen(true, Board[7, 3]);
            _ = new King(true, Board[7, 4]);
            _ = new Bishop(true, Board[7, 5]);
            _ = new Knight(true, Board[7, 6]);
            _ = new Rook(true, Board[7, 7]);

            _ = new Pawn(false, Board[1, 0]);
            _ = new Pawn(false, Board[1, 1]);
            _ = new Pawn(false, Board[1, 2]);
            _ = new Pawn(false, Board[1, 3]);
            _ = new Pawn(false, Board[1, 4]);
            _ = new Pawn(false, Board[1, 5]);
            _ = new Pawn(false, Board[1, 6]);
            _ = new Pawn(false, Board[1, 7]);

            _ = new Rook(false, Board[0, 0]);
            _ = new Knight(false, Board[0, 1]);
            _ = new Bishop(false, Board[0, 2]);
            _ = new Queen(false, Board[0, 3]);
            _ = new King(false, Board[0, 4]);
            _ = new Bishop(false, Board[0, 5]);
            _ = new Knight(false, Board[0, 6]);
            _ = new Rook(false, Board[0, 7]);
        }
Esempio n. 4
0
        public void NewGame()
        {
            Pawn whitePawn1 = new Pawn(true, Board[6, 0]);
            Pawn whitePawn2 = new Pawn(true, Board[6, 1]);
            Pawn whitePawn3 = new Pawn(true, Board[6, 2]);
            Pawn whitePawn4 = new Pawn(true, Board[6, 3]);
            Pawn whitePawn5 = new Pawn(true, Board[6, 4]);
            Pawn whitePawn6 = new Pawn(true, Board[6, 5]);
            Pawn whitePawn7 = new Pawn(true, Board[6, 6]);
            Pawn whitePawn8 = new Pawn(true, Board[6, 7]);

            Rook   whiteRook1   = new Rook(true, Board[7, 0]);
            Knight whiteKnight1 = new Knight(true, Board[7, 1]);
            Bishop whiteBishop1 = new Bishop(true, Board[7, 2]);
            Queen  whiteQueen   = new Queen(true, Board[7, 3]);
            King   whiteKing    = new King(true, Board[7, 4]);
            Bishop whiteBishop2 = new Bishop(true, Board[7, 5]);
            Knight whiteKnight2 = new Knight(true, Board[7, 6]);
            Rook   whiteRook2   = new Rook(true, Board[7, 7]);

            Pawn blackPawn1 = new Pawn(false, Board[1, 0]);
            Pawn blackPawn2 = new Pawn(false, Board[1, 1]);
            Pawn blackPawn3 = new Pawn(false, Board[1, 2]);
            Pawn blackPawn4 = new Pawn(false, Board[1, 3]);
            Pawn blackPawn5 = new Pawn(false, Board[1, 4]);
            Pawn blackPawn6 = new Pawn(false, Board[1, 5]);
            Pawn blackPawn7 = new Pawn(false, Board[1, 6]);
            Pawn blackPawn8 = new Pawn(false, Board[1, 7]);

            Rook   blackRook1   = new Rook(false, Board[0, 0]);
            Knight blackKnight1 = new Knight(false, Board[0, 1]);
            Bishop blackBishop1 = new Bishop(false, Board[0, 2]);
            Queen  blackQueen   = new Queen(false, Board[0, 3]);
            King   blackKing    = new King(false, Board[0, 4]);
            Bishop blackBishop2 = new Bishop(false, Board[0, 5]);
            Knight blackKnight2 = new Knight(false, Board[0, 6]);
            Rook   blackRook2   = new Rook(false, Board[0, 7]);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Chessboard chessboard = new Chessboard();

            // IPiece interface? Wanna be able to get it all in a list.
            Pawn   whitePawn   = new Pawn(true, chessboard.Board[4, 3]);
            Pawn   blackPawn   = new Pawn(false, chessboard.Board[6, 0]);
            Knight blackKnight = new Knight(false, chessboard.Board[2, 2]);
            King   whiteKing   = new King(false, chessboard.Board[7, 3]);
            Rook   whiteRook   = new Rook(true, chessboard.Board[3, 6]);
            Bishop blackBishop = new Bishop(false, chessboard.Board[2, 4]);
            Queen  whiteQueen  = new Queen(true, chessboard.Board[1, 5]);

            List <Pieces> pieces = new List <Pieces>
            {
                whitePawn,
                blackPawn,
                blackKnight,
                whiteKing,
                whiteRook,
                blackBishop,
                whiteQueen
            };

            Console.WriteLine("The Pieces");
            chessboard.ClearMarkedLegalMoves();
            PrintBoardOccupiedAndLegal(chessboard);

            foreach (Pieces piece in pieces)
            {
                Console.WriteLine("=====================================================");
                Console.WriteLine(piece.Name);
                chessboard.ClearMarkedLegalMoves();
                chessboard.FindLegalMoves(piece);
                PrintBoardOccupiedAndLegal(chessboard);
            }

            Console.WriteLine("=====================================================");

            Console.WriteLine("Before Move");
            chessboard.MovePiece(whiteQueen, chessboard.Board[2, 4]);
            chessboard.ClearMarkedLegalMoves();
            PrintBoardOccupiedAndLegal(chessboard);

            Console.WriteLine("=====================================================");

            Console.WriteLine("Clear Board");
            chessboard.ClearBoard();
            PrintBoardOccupiedAndLegal(chessboard);

            Console.WriteLine("=====================================================");

            Console.WriteLine("New Game");
            chessboard.NewGame();
            PrintBoardOccupiedAndLegal(chessboard);

            Console.WriteLine("=====================================================");

            Console.WriteLine("Queen Moves");
            chessboard.ClearBoard();
            Queen queen = new Queen(true, chessboard.Board[4, 4]);
            Pawn  pawn  = new Pawn(false, chessboard.Board[2, 4]);

            PrintBoardOccupiedAndLegal(chessboard);

            Console.WriteLine("=====================================================");

            Console.WriteLine("Find Queen Obstruction");
        }