Exemplo n.º 1
0
        public void SaveCoordinates()
        {
            var firstRook    = new Rook(this, new Position("a1"));
            var firstKnight  = new Knight(this, new Position("b1"));
            var firstBishop  = new Bishop(this, new Position("c1"));
            var queen        = new Queen(this, new Position("d1"));
            var king         = new King(this, new Position("e1"));
            var secondBishop = new Bishop(this, new Position("f1"));
            var secondKnight = new Knight(this, new Position("g1"));
            var secondRook   = new Rook(this, new Position("h1"));

            this.Figures.Add(firstRook);
            this.Figures.Add(firstKnight);
            this.Figures.Add(firstBishop);
            this.Figures.Add(queen);
            this.Figures.Add(king);
            this.Figures.Add(secondBishop);
            this.Figures.Add(secondKnight);
            this.Figures.Add(secondRook);

            for (int i = 0; i < 8; i++)
            {
                var currentWidth = 'a' + i;
                var pawn         = new Pawn(this, new Position($"{(char)currentWidth}2"));
                pawn.HasInitialState = true;
                this.Figures.Add(pawn);
            }

            AddColorOfFigures();
        }
Exemplo n.º 2
0
 public override void attackTile(ref ChessBoard chess)
 {
     if (IsWhite)
     {
         Rook whiteRook = new Rook();
         whiteRook.IsWhite  = true;
         whiteRook.Position = Position;
         whiteRook.attackTile(ref chess);
         Bishop whiteBishop = new Bishop();
         whiteBishop.IsWhite  = true;
         whiteBishop.Position = Position;
         whiteBishop.attackTile(ref chess);
     }
     else
     {
         Rook whiteRook = new Rook();
         whiteRook.IsWhite  = false;
         whiteRook.Position = Position;
         whiteRook.attackTile(ref chess);
         Bishop whiteBishop = new Bishop();
         whiteBishop.IsWhite  = false;
         whiteBishop.Position = Position;
         whiteBishop.attackTile(ref chess);
     }
 }
Exemplo n.º 3
0
        public Board()
        {
            board = new Piece[boardSize, boardSize];

            board[0, 0] = new Rook(Player.Black);
            board[0, 1] = new Knight(Player.Black);
            board[0, 2] = new Bishop(Player.Black);
            board[0, 3] = new Queen(Player.Black);
            board[0, 4] = new King(Player.Black);
            board[0, 5] = new Bishop(Player.Black);
            board[0, 6] = new Knight(Player.Black);
            board[0, 7] = new Rook(Player.Black);
            for (int i = 0; i < boardSize; i++)
            {
                board[1, i] = new Pawn(Player.Black);
            }

            board[7, 0] = new Rook(Player.White);
            board[7, 1] = new Knight(Player.White);
            board[7, 2] = new Bishop(Player.White);
            board[7, 3] = new Queen(Player.White);
            board[7, 4] = new King(Player.White);
            board[7, 5] = new Bishop(Player.White);
            board[7, 6] = new Knight(Player.White);
            board[7, 7] = new Rook(Player.White);
            for (int i = 0; i < boardSize; i++)
            {
                board[6, i] = new Pawn(Player.White);
            }
        }
Exemplo n.º 4
0
        internal void SetupBackRowPieces(int row, bool white)
        {
            if (gameBoard == null)
            {
                return;
            }
            var queen   = new Queen(white);
            var king    = new King(white);
            var rook1   = new Rook(white);
            var rook2   = new Rook(white);
            var bishop1 = new Bishop(white);
            var bishop2 = new Bishop(white);
            var knight1 = new Knight(white);
            var knight2 = new Knight(white);

            gameBoard.PlacePiece(king, 4, row);
            gameBoard.PlacePiece(queen, 3, row);

            gameBoard.PlacePiece(rook1, 0, row);
            gameBoard.PlacePiece(rook2, 7, row);
            gameBoard.PlacePiece(bishop1, 2, row);
            gameBoard.PlacePiece(bishop2, 5, row);
            gameBoard.PlacePiece(knight1, 1, row);
            gameBoard.PlacePiece(knight2, 6, row);
        }
Exemplo n.º 5
0
        public Set(Color color)
        {
            int rank;
            this.color = color;
            pieces = new Piece[16];

            rank = (color == Color.Black) ? 8 : 1;
            pieces[0] = rookA = new Rook(color, new Position(rank, 'a'));
            pieces[1] = knightA = new Knight(color, new Position(rank, 'b'));
            pieces[2] = bishopA = new Bishop(color, new Position(rank, 'c'));
            pieces[3] = king = new King(color, new Position(rank, 'd'));
            pieces[4] = queen = new Queen(color, new Position(rank, 'e'));
            pieces[5] = bishopB = new Bishop(color, new Position(rank, 'f'));
            pieces[6] = knightB = new Knight(color, new Position(rank, 'g'));
            pieces[7] = rookB = new Rook(color, new Position(rank, 'h'));

            rank = (color == Color.Black) ? 7 : 2;
            pieces[8] = pawnA = new Pawn(color, new Position(rank, 'a'));
            pieces[9] = pawnB = new Pawn(color, new Position(rank, 'b'));
            pieces[10] = pawnC = new Pawn(color, new Position(rank, 'c'));
            pieces[11] = pawnD = new Pawn(color, new Position(rank, 'd'));
            pieces[12] = pawnE = new Pawn(color, new Position(rank, 'e'));
            pieces[13] = pawnF = new Pawn(color, new Position(rank, 'f'));
            pieces[14] = pawnG = new Pawn(color, new Position(rank, 'g'));
            pieces[15] = pawnH = new Pawn(color, new Position(rank, 'h'));
        }
Exemplo n.º 6
0
        //Used for creating a duplicate object
        public override ChessPiece Clone()
        {
            Bishop returnPiece = new Bishop(PositionX, PositionY);

            returnPiece.Colour = Colour;
            return(returnPiece);
        }
Exemplo n.º 7
0
        private void SetInitPositions()
        {
            // pijun
            for (int j = 0; j < 8; j++)
            {
                figureTable[1, j] = new Pawn(1, j, PlayerType.BLACK, FigureType.PAWN, this);
                figureTable[6, j] = new Pawn(6, j, PlayerType.WHITE, FigureType.PAWN, this);
            }

            // Add Rooks
            figureTable[0, 0] = new Rook(0, 0, PlayerType.BLACK, FigureType.ROOK, this);
            figureTable[0, 7] = new Rook(0, 7, PlayerType.BLACK, FigureType.ROOK, this);
            figureTable[7, 0] = new Rook(7, 0, PlayerType.WHITE, FigureType.ROOK, this);
            figureTable[7, 7] = new Rook(7, 7, PlayerType.WHITE, FigureType.ROOK, this);

            // Add Knights
            figureTable[0, 1] = new Knight(0, 1, PlayerType.BLACK, FigureType.KNIGHT, this);
            figureTable[0, 6] = new Knight(0, 6, PlayerType.BLACK, FigureType.KNIGHT, this);
            figureTable[7, 1] = new Knight(7, 1, PlayerType.WHITE, FigureType.KNIGHT, this);
            figureTable[7, 6] = new Knight(7, 6, PlayerType.WHITE, FigureType.KNIGHT, this);

            // Add Bishops
            figureTable[0, 2] = new Bishop(0, 2, PlayerType.BLACK, FigureType.BISHOP, this);
            figureTable[0, 5] = new Bishop(0, 5, PlayerType.BLACK, FigureType.BISHOP, this);
            figureTable[7, 2] = new Bishop(7, 2, PlayerType.WHITE, FigureType.BISHOP, this);
            figureTable[7, 5] = new Bishop(7, 5, PlayerType.WHITE, FigureType.BISHOP, this);

            // Add Kings and Queens
            figureTable[0, 3] = new Queen(0, 3, PlayerType.BLACK, FigureType.QUEEN, this);
            figureTable[7, 3] = new Queen(7, 3, PlayerType.WHITE, FigureType.QUEEN, this);
            figureTable[0, 4] = new King(0, 4, PlayerType.BLACK, FigureType.KING, this);
            figureTable[7, 4] = new King(7, 4, PlayerType.WHITE, FigureType.KING, this);
        }
Exemplo n.º 8
0
        public override DynamicArray <Coordinate> Moves()
        {
            Bishop bishop = this;
            DynamicArray <Coordinate> moves = new DynamicArray <Coordinate>();
            int startVertical = bishop.Coordinate.Vertical, startHorizontal = bishop.Coordinate.Horizontal;
            int vertical = startVertical, horizontal = startHorizontal;

            while (vertical < 8 && horizontal < 8)
            {
                vertical++; horizontal++;
                moves.Add(new Coordinate(vertical, horizontal));
            }
            vertical = startVertical; horizontal = startHorizontal;
            while (vertical < 8 && horizontal > 1)
            {
                vertical++; horizontal--;
                moves.Add(new Coordinate(vertical, horizontal));
            }
            vertical = startVertical; horizontal = startHorizontal;
            while (horizontal < 8 && vertical > 1)
            {
                vertical--; horizontal++;
                moves.Add(new Coordinate(vertical, horizontal));
            }
            vertical = startVertical; horizontal = startHorizontal;
            while (vertical > 1 && horizontal > 1)
            {
                vertical--; horizontal--;
                moves.Add(new Coordinate(vertical, horizontal));
            }
            return(moves);
        }
Exemplo n.º 9
0
        internal static Piece PieceFromString(Color color, string pieceTypeChar)
        {
            Piece piece = null;

            if (pieceTypeChar == "K")
            {
                piece = new King(color);
            }
            else if (pieceTypeChar == "Q")
            {
                piece = new Queen(color);
            }
            else if (pieceTypeChar == "R")
            {
                piece = new Rook(color);
            }
            else if (pieceTypeChar == "N")
            {
                piece = new Knight(color);
            }
            else if (pieceTypeChar == "B")
            {
                piece = new Bishop(color);
            }
            else if (pieceTypeChar == "P")
            {
                piece = new Pawn(color);
            }
            if (piece == null)
            {
                throw new ApplicationException("Invalid format of add piece string");
            }
            return(piece);
        }
Exemplo n.º 10
0
        public void initialize()
        {
            string[,] boardSetup = new string[8, 8]
            {
                { "Rook", "Knight", "Bishop", "King", "Queen", "Bishop", "Knight", "Rook" },
                { "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn" },
                { "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty" },
                { "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty" },
                { "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty" },
                { "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty", "Empty" },
                { "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn", "Pawn" },
                { "Rook", "Knight", "Bishop", "Queen", "King", "Bishop", "Knight", "Rook" },
            };

            Color  color;
            string type;

            int[] position;

            for (int i = 0; i < 8; i++)     // ROW
            {
                for (int j = 0; j < 8; j++) // COLUMN
                {
                    type  = boardSetup[i, j];
                    color = (i < 3) ? Color.Black : Color.White;

                    switch (type)
                    {
                    case "Rook":
                        board[i, j] = new Rook(color, type, i, j);
                        break;

                    case "Knight":
                        board[i, j] = new Knight(color, type, i, j);
                        break;

                    case "Bishop":
                        board[i, j] = new Bishop(color, type, i, j);
                        break;

                    case "King":
                        board[i, j] = new King(color, type, i, j);
                        break;

                    case "Queen":
                        board[i, j] = new Queen(color, type, i, j);
                        break;

                    case "Pawn":
                        board[i, j] = new Pawn(color, type, i, j);
                        break;

                    default:
                        board[i, j] = null;
                        break;
                    }
                }
            }
        }
Exemplo n.º 11
0
        public override Piece Copy(Square[] squares)
        {
            var p = new Bishop(Color)
            {
                MoveCount = MoveCount
            };

            return(CopySquare(squares, p));
        }
Exemplo n.º 12
0
        public static GamePiece StartingPiece(Point cell)
        {
            Color color = Color.Red;

            GamePiece temp = null;

            //Top 2 Rows
            //BLACK PIECES
            if (cell.Y < 2)
            {
                color = Color.Black;
            }
            //Bottom 2 Rows
            //WHITE PIECES
            else if (cell.Y > 5)
            {
                color = Color.White;
            }
            else
            {
                return(null);
            }

            //Pawn
            if (cell.Y == 1 || cell.Y == 6)
            {
                temp = new Pawn(color, cell);
            }
            //Rook
            else if (cell.X == 0 || cell.X == 7)
            {
                temp = new Rook(color, cell);
            }
            //Knight
            else if (cell.X == 1 || cell.X == 6)
            {
                temp = new Knight(color, cell);
            }
            //Bishop
            else if (cell.X == 2 || cell.X == 5)
            {
                temp = new Bishop(color, cell);
            }
            //Queen
            else if (cell.X == 3)
            {
                temp = new Queen(color, cell);
            }
            //King
            else if (cell.X == 4)
            {
                temp = new King(color, cell);
            }

            return(temp);
        }
Exemplo n.º 13
0
        private void buttonAccept_Click(object sender, System.EventArgs e)
        {
            //Button "Accept" clicked, carry out the promotion

            if (comboBoxFigures.SelectedItem == null)
            {
                MessageBox.Show(this, "You must select a figure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                promotionRealized = true;

                //Delete the pawn

                Board.getInstance().killPiece(pawn.getPosition(), true);

                //Create the new figure

                string   fig   = comboBoxFigures.SelectedItem.ToString();
                Position pos   = pawn.getPosition();
                Color    color = pawn.getColor();
                Piece    piece = null;

                if (fig == "Bishop")
                {
                    piece = new Bishop(pos, color);
                }
                else if (fig == "Knight")
                {
                    piece = new Knight(pos, color);
                }
                else if (fig == "Queen")
                {
                    piece = new Queen(pos, color);
                }
                else if (fig == "Rook")
                {
                    piece = new Rook(pos, color);
                }

                if (color == Color.White)
                {
                    Board.getInstance().getWhitePieces().insert(piece);
                }
                else
                {
                    Board.getInstance().getBlackPieces().insert(piece);
                }

                Board.getInstance().deletePiece(pawn);
                Board.getInstance().drawPiece(piece);

                this.Close();
            }
        }
Exemplo n.º 14
0
        //Creates and returns a chessboard with all the pieces in the starting locations
        public static ChessPiece[,] CreateChessBoard()
        {
            ChessPiece[,] chessBoard = new ChessPiece[8, 8];

            //sets up blank spaces
            for (int i = 0; i < 8; i++)
            {
                for (int j = 2; j <= 6; j++)
                {
                    chessBoard[i, j] = new ChessPiece(i, j);
                }
            }

            //sets up pawns
            for (int i = 0; i < 8; i++)
            {
                chessBoard[i, 1] = new Pawn(i, 1);
                chessBoard[i, 6] = new Pawn(i, 6);
            }

            for (int i = 0; i < 8; i = i + 7)
            {
                //kings and queens
                chessBoard[4, i] = new King(4, i);
                chessBoard[3, i] = new Queen(3, i);

                //Rooks
                chessBoard[0, i] = new Rook(0, i);
                chessBoard[7, i] = new Rook(7, i);

                //Knights
                chessBoard[1, i] = new Knight(1, i);
                chessBoard[6, i] = new Knight(6, i);

                //Bishops
                chessBoard[2, i] = new Bishop(2, i);
                chessBoard[5, i] = new Bishop(5, i);
            }

            //record the colour of all chess piece objects, set up all kings
            for (int i = 0; i <= MAX_CHESS_VALUE; i++)
            {
                chessBoard[i, 0].Colour = chessColour.WHITE;
                chessBoard[i, 1].Colour = chessColour.WHITE;
                chessBoard[i, 0]._king  = (King)chessBoard[4, 0];
                chessBoard[i, 1]._king  = (King)chessBoard[4, 0];

                chessBoard[i, 6].Colour = chessColour.BLACK;
                chessBoard[i, 7].Colour = chessColour.BLACK;
                chessBoard[i, 6]._king  = (King)chessBoard[4, 7];
                chessBoard[i, 7]._king  = (King)chessBoard[4, 7];
            }

            return(chessBoard);
        }
        static void Main(string[] args)
        {
            Bishop chessBishop = new Bishop("Chess", 50, "wood", 100);

            chessBishop.Move();
            King chessKing = new King("Chess", 3, "iron", 10);

            chessKing.Move();
            Knight chessKnight = new Knight("Chess", 2, "keramick", 1);

            chessKnight.Move();
        }
Exemplo n.º 16
0
        private void SetupBoard()
        {
            for (int i = 0; i < 8; i++)
            {
                Pawn p1 = new Pawn(i, 1, true);
                chessPieces.Add(p1);
                Pawn p2 = new Pawn(i, 6, false);
                chessPieces.Add(p2);
            }
            Bishop b_b1 = new Bishop(2, 0, true);

            chessPieces.Add(b_b1);
            Bishop b_b2 = new Bishop(5, 0, true);

            chessPieces.Add(b_b2);
            Bishop w_b1 = new Bishop(2, 7, false);

            chessPieces.Add(w_b1);
            Bishop w_b2 = new Bishop(5, 7, false);

            chessPieces.Add(w_b2);
            King b_king = new King(4, 0, true);

            chessPieces.Add(b_king);
            King w_king = new King(4, 7, false);

            chessPieces.Add(w_king);
            Rook b_r1 = new Rook(0, 0, true);
            Rook b_r2 = new Rook(7, 0, true);

            chessPieces.Add(b_r1);
            chessPieces.Add(b_r2);
            Rook w_r1 = new Rook(0, 7, false);
            Rook w_r2 = new Rook(7, 7, false);

            chessPieces.Add(w_r1);
            chessPieces.Add(w_r2);
            Knight b_k1 = new Knight(1, 0, true);
            Knight b_k2 = new Knight(6, 0, true);

            chessPieces.Add(b_k1);
            chessPieces.Add(b_k2);
            Knight w_k1 = new Knight(1, 7, false);
            Knight w_k2 = new Knight(6, 7, false);

            chessPieces.Add(w_k1);
            chessPieces.Add(w_k2);
            Queen b_q = new Queen(3, 0, true);
            Queen w_q = new Queen(3, 7, false);

            chessPieces.Add(b_q);
            chessPieces.Add(w_q);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Override method that returns a list of positions that the queen can make
        /// </summary>
        /// <param name="pieces">All pieces, white and black, to see if moves are obstructed</param>
        /// <returns>list of positions that the queen can make</returns>
        public override List <Position> GetMoves(List <Chesspiece> pieces)
        {
            // The queen uses the same moves as a bishop AND a rook, so you can simply use their moves
            Bishop tempBishop = new Bishop(Pos, IsWhite);       // Create a temporary bishop on the same position
            Rook   tempRook   = new Rook(Pos, IsWhite);         // Create a temporary rook on the same position

            // Create the moves list to later return filled with moves
            List <Position> moves = tempBishop.GetMoves(pieces).ToList(); // Give it the bishops moves

            moves.AddRange(tempRook.GetMoves(pieces));                    // Add the rooks moves to the list of moves

            return(moves);                                                // Return the list of the queens moves (bishop and rooks moves)
        }
Exemplo n.º 18
0
        public override bool canMove(int CurrentX, int CurrentY, int NewX, int NewY, bool white)// bishop canmove only calls upon the diagonal
        {
            Bishop bishop = new Bishop();

            if (bishop.diagonalMove(CurrentX, CurrentY, NewX, NewY, white))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 19
0
        public override bool Move(Coordinate oldCoordinate, Coordinate newCoordinate)
        {
            bool checkMove = false;

            //QUEEN = ROOK + BISHOP...
            checkMove = Rook.VerifyVerticalAndHorizontal(oldCoordinate, newCoordinate, checkMove);

            if (!checkMove)
            {
                checkMove = Bishop.VerifyDiagonals(oldCoordinate, newCoordinate, checkMove);
            }

            return(checkMove);
        }
Exemplo n.º 20
0
 public Queen(char color, Point loc) : base(color + "  ", 'q', loc)
 {
     //creates new instances of Bishops/Rooks for getting this piece's moveset
     tempRook = new Rook(this.color + "  ", this.loc);
     tempBish = new Bishop(this.color + "  ", this.loc);
     if (this.color == 'w')
     {
         this.num = (char)(Piece.whiteQueen + '0');
         Piece.whiteQueen++;
     }
     else
     {
         this.num = (char)(Piece.blackQueen + '0');
         Piece.blackQueen++;
     }
 }
Exemplo n.º 21
0
        private void GenerateBlackSide()
        {
            Board[0, 0] = new Rook(Color.Black);
            Board[0, 1] = new Knight(Color.Black);
            Board[0, 2] = new Bishop(Color.Black);
            Board[0, 3] = new Queen(Color.Black);
            Board[0, 4] = new King(Color.Black);
            Board[0, 5] = new Bishop(Color.Black);
            Board[0, 6] = new Knight(Color.Black);
            Board[0, 7] = new Rook(Color.Black);

            for (int i = 0; i < BoardSize; i++)
            {
                Board[1, i] = new Pawn(Color.Black);
            }
        }
Exemplo n.º 22
0
        private void GenerateWhiteSide()
        {
            Board[7, 0] = new Rook(Color.White);
            Board[7, 1] = new Knight(Color.White);
            Board[7, 2] = new Bishop(Color.White);
            Board[7, 3] = new Queen(Color.White);
            Board[7, 4] = new King(Color.White);
            Board[7, 5] = new Bishop(Color.White);
            Board[7, 6] = new Knight(Color.White);
            Board[7, 7] = new Rook(Color.White);

            for (int i = 0; i < BoardSize; i++)
            {
                Board[6, i] = new Pawn(Color.White);
            }
        }
Exemplo n.º 23
0
        public List<Tuple<int, int>> getValidMoves(Piece currentPiece, Gameboard gameboard, bool doRecurse = true)
        {
            this.copyOfCurrentPiece = new Piece(currentPiece);
            this.gameboard = new Gameboard(gameboard);

            switch (currentPiece.type)
            {
                case (int)type.rock: // tower
                    Rock rock = new Rock();
                    this.validDestinations = rock.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
                case (int)type.knight: // horsie
                    Knight knight = new Knight();
                    this.validDestinations = knight.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
                case (int)type.bishop: // springare
                    Bishop bishop = new Bishop();
                    this.validDestinations = bishop.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
                case (int)type.queen: //los quuenos
                    Queen queen = new Queen();
                    this.validDestinations = queen.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
                case (int)type.king: // los kingos
                    King king = new King();
                    this.validDestinations = king.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
                case (int)type.pawn: // los farmeros
                    Pawn pawn = new Pawn();
                    this.validDestinations = pawn.Rules(currentPiece, gameboard);
                    if (doRecurse)
                        cleanUp();
                    return validDestinations;
            }
            return new List<Tuple<int,int>>();
        }
Exemplo n.º 24
0
        public override DynamicArray <Coordinate> Path(Coordinate endCoordinate)
        {
            Queen queen = this;
            DynamicArray <Coordinate> queenPath;

            if (Math.Abs(queen.Coordinate.Vertical - endCoordinate.Vertical) != 0 && Math.Abs(queen.Coordinate.Horizontal - endCoordinate.Horizontal) != 0)
            {
                Bishop bishop = new Bishop(queen.Coordinate, queen.Color);
                queenPath = bishop.Path(endCoordinate);
            }
            else
            {
                Rock rock = new Rock(queen.Coordinate, queen.Color);
                queenPath = rock.Path(endCoordinate);
            }
            return(queenPath);
        }
Exemplo n.º 25
0
        public override DynamicArray <Coordinate> Moves()
        {
            Queen  queen = this;
            Bishop bishop = new Bishop(queen.Coordinate, queen.Color); Rock rock = new Rock(queen.Coordinate, queen.Color);
            DynamicArray <Coordinate> Bishop = bishop.Moves(), Rock = rock.Moves();
            DynamicArray <Coordinate> queenMoves = new DynamicArray <Coordinate>(); // rock always have maximum 14 moves, they do not depend on the piece color

            for (int i = 0; i < Bishop.Count(); i++)
            {
                queenMoves.Add(Bishop[i]);
            }
            for (int i = 0; i < Rock.Count(); i++)
            {
                queenMoves.Add(Rock[i]);
            }
            return(queenMoves);
        }
Exemplo n.º 26
0
 private void CopyTable() //kopiranje glavne table u privremenu
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (figureTable[i, j] == null)
             {
                 tempTable[i, j] = null;
             }
             else
             {
                 if (figureTable[i, j] is King)
                 {
                     tempTable[i, j] = new King(i, j, figureTable[i, j].player, figureTable[i, j].type, this,
                                                ((King)figureTable[i, j]).IsMoved);
                 }
                 else if (figureTable[i, j] is Rook)
                 {
                     tempTable[i, j] = new Rook(i, j, figureTable[i, j].player, figureTable[i, j].type, this,
                                                ((Rook)figureTable[i, j]).IsMoved);
                 }
                 else if (figureTable[i, j] is Queen)
                 {
                     tempTable[i, j] = new Queen(i, j, figureTable[i, j].player, figureTable[i, j].type, this);
                 }
                 else if (figureTable[i, j] is Knight)
                 {
                     tempTable[i, j] = new Knight(i, j, figureTable[i, j].player, figureTable[i, j].type, this);
                 }
                 else if (figureTable[i, j] is Bishop)
                 {
                     tempTable[i, j] = new Bishop(i, j, figureTable[i, j].player, figureTable[i, j].type, this);
                 }
                 else if (figureTable[i, j] is Pawn)
                 {
                     tempTable[i, j] = new Pawn(i, j, figureTable[i, j].player, figureTable[i, j].type, this);
                 }
             }
         }
     }
 }
Exemplo n.º 27
0
        // Method that connect lower char with white figures and letters RNBQKP with relative figures
        private Figure figureLookup(char c)
        {
            Figure result;
            string color = "white";

            if (Char.IsLower(c))
            {
                c     = Char.ToUpper(c);
                color = "black";
            }
            switch (c)
            {
            case 'R':
                result = new Rock(color);
                break;

            case 'N':
                result = new Knight(color);
                break;

            case 'B':
                result = new Bishop(color);
                break;

            case 'Q':
                result = new Queen(color);
                break;

            case 'K':
                result = new King(color);
                break;

            case 'P':
                result = new Pawn(color);
                break;

            default:
                result = new Empty();
                break;
            }
            return(result);
        }
Exemplo n.º 28
0
        public override DynamicArray <Coordinate> Path(Coordinate endCoordinate)
        {
            Bishop bishop = this;
            DynamicArray <Coordinate> moves = new DynamicArray <Coordinate>();
            int vertical = bishop.Coordinate.Vertical, horizontal = bishop.Coordinate.Horizontal;
            int endVertical = endCoordinate.Vertical, endHorizontal = endCoordinate.Horizontal;

            if (endVertical - vertical > 0 && endHorizontal - horizontal > 0)
            {
                while (vertical < endVertical && horizontal < endHorizontal)
                {
                    vertical++; horizontal++;
                    moves.Add(new Coordinate(vertical, horizontal));
                }
            }
            else if (endVertical - vertical < 0 && endHorizontal - horizontal < 0)
            {
                while (vertical > endVertical && horizontal > endHorizontal)
                {
                    vertical--; horizontal--;
                    moves.Add(new Coordinate(vertical, horizontal));
                }
            }
            else if (endVertical - vertical < 0 && endHorizontal - horizontal > 0)
            {
                while (vertical > endVertical && horizontal < endHorizontal)
                {
                    vertical--; horizontal++;
                    moves.Add(new Coordinate(vertical, horizontal));
                }
            }
            else if (endVertical - vertical > 0 && endHorizontal - horizontal < 0)
            {
                while (vertical < endVertical && horizontal > endHorizontal)
                {
                    vertical++; horizontal--;
                    moves.Add(new Coordinate(vertical, horizontal));
                }
            }
            return(moves);
        }
Exemplo n.º 29
0
        /*
         * This constructor is used in the clone method
         */
        public List(ArrayList l)
        {
            list = new ArrayList();

            foreach (Piece p in l)
            {
                Position pos = new Position(p.getPosition().getRow(), p.getPosition().getColumn());
                Color color = p.getColor();
                Image image = p.getImage();
                Piece piece = null;

                if (p is Bishop)
                {
                    piece = new Bishop(pos, color);
                }
                else if (p is Knight)
                {
                    piece = new Knight(pos, color);
                }
                else if (p is Pawn)
                {
                    piece = new Pawn(pos, color);
                }
                else if (p is Queen)
                {
                    piece = new Queen(pos, color);
                }
                else if (p is Rook)
                {
                    piece = new Rook(pos, color);
                }
                else if (p is King)
                {
                    piece = new King(pos, color);
                }

                list.Add(piece);
            }

        }
Exemplo n.º 30
0
        /// <summary>
        /// string format. E.g. e1bR (black Rook)
        /// </summary>
        /// <param name="game"></param>
        /// <param name="pieceString"></param>
        public static Game AddPiece(this Game game, string pieceString)
        {
            var   file          = (File)Enum.Parse(typeof(File), pieceString.Substring(0, 1).ToUpper());
            var   rank          = (Rank)Enum.Parse(typeof(Rank), "_" + pieceString.Substring(1, 1));
            var   colorChar     = pieceString.Substring(2, 1);
            var   color         = colorChar == "w" ? Color.White : Color.Black;
            var   pieceTypeChar = pieceString.Substring(3, 1);
            Piece piece         = null;

            if (pieceTypeChar == "K")
            {
                piece = new King(color);
            }
            else if (pieceTypeChar == "Q")
            {
                piece = new Queen(color);
            }
            else if (pieceTypeChar == "R")
            {
                piece = new Rook(color);
            }
            else if (pieceTypeChar == "N")
            {
                piece = new Knight(color);
            }
            else if (pieceTypeChar == "B")
            {
                piece = new Bishop(color);
            }
            else if (pieceTypeChar == "P")
            {
                piece = new Pawn(color);
            }
            if (piece == null)
            {
                throw new ApplicationException("Invalid format of add piece string" + pieceString);
            }
            game.AddPiece(file, rank, piece);
            return(game);
        }
Exemplo n.º 31
0
        /*
         * This constructor is used in the clone method
         */
        public List(ArrayList l)
        {
            list = new ArrayList();

            foreach (Piece p in l)
            {
                Position pos   = new Position(p.getPosition().getRow(), p.getPosition().getColumn());
                Color    color = p.getColor();
                Image    image = p.getImage();
                Piece    piece = null;

                if (p is Bishop)
                {
                    piece = new Bishop(pos, color);
                }
                else if (p is Knight)
                {
                    piece = new Knight(pos, color);
                }
                else if (p is Pawn)
                {
                    piece = new Pawn(pos, color);
                }
                else if (p is Queen)
                {
                    piece = new Queen(pos, color);
                }
                else if (p is Rook)
                {
                    piece = new Rook(pos, color);
                }
                else if (p is King)
                {
                    piece = new King(pos, color);
                }

                list.Add(piece);
            }
        }
Exemplo n.º 32
0
        public void NewGame(bool firstIsHuman, bool secondIsHuman)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    field[i, j] = null;
                }
            }
            Player player1 = new Player(true, firstIsHuman);
            Player player2 = new Player(false, secondIsHuman);

            for (int i = 0; i <= 7; i++)
            {
                field[i, 1] = new Pawn(i, 1, false, player2);
                field[i, 6] = new Pawn(i, 6, true, player1);
            }
            for (int i = 0; i <= 7; i += 7)
            {
                field[i, 0] = new Rook(i, 0, player2);
                field[i, 7] = new Rook(i, 7, player1);
            }
            for (int i = 1; i <= 7; i += 5)
            {
                field[i, 0] = new Knight(i, 0, player2);
                field[i, 7] = new Knight(i, 7, player1);
            }
            for (int i = 2; i <= 6; i += 3)
            {
                field[i, 0] = new Bishop(i, 0, player2);
                field[i, 7] = new Bishop(i, 7, player1);
            }
            field[3, 0] = new Queen(3, 0, player2);
            field[3, 7] = new Queen(3, 7, player1);
            field[4, 0] = new King(4, 0, player2);
            field[4, 7] = new King(4, 7, player1);
            Game.king2  = (King)field[4, 0];
            Game.king1  = (King)field[4, 7];
        }
Exemplo n.º 33
0
        /// <summary>
        /// Adds all of the pieces to the board
        /// </summary>
        public void AddPieces()
        {
            Piece[] pieces = new Piece[32];
            //White pieces
            pieces[0] = new King(squares["E1"], true, 0);
            pieces[1] = new Queen(squares["D1"], true, 0);
            pieces[2] = new Bishop(squares["C1"], true, 1);
            pieces[3] = new Bishop(squares["F1"], true, 2);
            pieces[4] = new Knight(squares["B1"], true, 1);
            pieces[5] = new Knight(squares["G1"], true, 2);
            pieces[6] = new Rook(squares["A1"], true, 1);
            pieces[7] = new Rook(squares["H1"], true, 2);
            //Black pieces
            pieces[8]  = new King(squares["E8"], false, 0);
            pieces[9]  = new Queen(squares["D8"], false, 0);
            pieces[10] = new Bishop(squares["C8"], false, 1);
            pieces[11] = new Bishop(squares["F8"], false, 2);
            pieces[12] = new Knight(squares["B8"], false, 1);
            pieces[13] = new Knight(squares["G8"], false, 2);
            pieces[14] = new Rook(squares["A8"], false, 1);
            pieces[15] = new Rook(squares["H8"], false, 2);
            //White pawns
            for (int i = 1; i <= 8; i++)
            {
                pieces[15 + i] = new Pawn(squares[colLabels[i - 1] + 2.ToString()], true, i);
            }
            //Black pawns
            for (int i = 1; i <= 8; i++)
            {
                pieces[23 + i] = new Pawn(squares[colLabels[i - 1] + 7.ToString()], false, i);
            }

            foreach (Piece p in pieces)
            {
                Program.display.AddPiece(p);
            }
        }
Exemplo n.º 34
0
        private void buttonAccept_Click(object sender, System.EventArgs e)
        {
            //Button "Accept" clicked, carry out the promotion

            if (comboBoxFigures.SelectedItem == null)
            {
                MessageBox.Show(this, "You must select a figure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else {

                promotionRealized = true;

                //Delete the pawn

                Board.getInstance().killPiece(pawn.getPosition(), true);

                //Create the new figure

                string fig = comboBoxFigures.SelectedItem.ToString();
                Position pos = pawn.getPosition();
                Color color = pawn.getColor();
                Piece piece = null;

                if (fig == "Bishop")
                {
                    piece = new Bishop(pos, color);
                }
                else if (fig == "Knight")
                {
                    piece = new Knight(pos, color);
                }
                else if (fig == "Queen")
                {
                    piece = new Queen(pos, color);
                }
                else if (fig == "Rook")
                {
                    piece = new Rook(pos, color);
                }

                if (color == Color.White)
                {
                    Board.getInstance().getWhitePieces().insert(piece);
                }
                else {
                    Board.getInstance().getBlackPieces().insert(piece);
                }

                Board.getInstance().deletePiece(pawn);
                Board.getInstance().drawPiece(piece);

                this.Close();
            }
        }
Exemplo n.º 35
0
 public void BeforeEachTest()
 {
     Target = new Bishop();
 }