Example #1
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'));
        }
Example #2
0
File: Rook.cs Project: feco93/Chess
 public Rook[] GetRooks(bool isWhitePlayer)
 {
     Rook[] rooks = new Rook[2];
     if (isWhitePlayer)
     {
         rooks[0] = new Rook(1, 1);
         rooks[1] = new Rook(1, 8);
     }
     else
     {
         rooks[0] = new Rook(8, 1);
         rooks[1] = new Rook(8, 8);
     }
     return rooks;
 }
Example #3
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);
            }

        }
Example #4
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);
        }
Example #5
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];
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }
Example #8
0
        private GamePiece PawnPromotion(GamePiece piece)
        {
            Console.WriteLine("Select a type to promote Pawn to.");
            Console.WriteLine("[0] - Bishop, [1] - Knight, [2] - Queen, [3] - Rook");

            string input;

            input = Console.ReadLine();
            bool success = Int32.TryParse(input, out int result);

            while (success == false || result < 0 || result > 3)
            {
                Console.WriteLine("Try again, Incorrect input.");
                input   = Console.ReadLine();
                success = Int32.TryParse(input, out result);
            }
            GamePiece newPiece = new GamePiece(piece.Place, piece.Color);

            if (result == 0)
            {
                newPiece = new Bishop(piece.Place, piece.Color);
            }
            else if (result == 1)
            {
                newPiece = new Knight(piece.Place, piece.Color);
            }
            else if (result == 2)
            {
                newPiece = new Queen(piece.Place, piece.Color);
            }
            else if (result == 3)
            {
                newPiece = new Rook(piece.Place, piece.Color);
            }

            return(newPiece);
        }
Example #9
0
        // Prüft, ob die große Rochade möglich ist
        public bool CanPerformCastlingQueensSide(Square dest)
        {
            Square source     = this.game.board.GetSquare(this.Current_position);
            int    source_col = GetColumnCoordinate(source);
            int    source_row = GetRowCoordinate(source);
            int    dest_col   = GetColumnCoordinate(dest);
            int    dest_row   = GetRowCoordinate(dest);

            // Bewegung bei der großen Rochade
            if (source_col - dest_col == 2 && source_row == dest_row)
            {
                Rook rook = this.game.board.GetRook("A" + this.Orig_position.Substring(1, 1));
                if (rook != null && !rook.IsMoved && !this.isMoved && !this.HasPerformedCastling)
                {
                    Square orig_rook_pos = this.game.board.GetSquare(rook.Orig_position);
                    if (CanMoveHorizontal(source, orig_rook_pos))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #10
0
        static void Main()
        {
            string FigPos = Console.ReadLine();
            Horse  horse  = new Horse();
            Rook   rook   = new Rook();

            string text = "";

            using (StreamReader fs = new StreamReader(@"chess.txt"))
            {
                while (true)
                {
                    // Читаем строку из файла во временную переменную.
                    string temp = fs.ReadLine();

                    // Если достигнут конец файла, прерываем считывание.
                    if (temp == null)
                    {
                        break;
                    }

                    // Пишем считанную строку в итоговую переменную.
                    text += temp + " ";
                }
            }

            List <IFigure> lst = new List <IFigure>()
            {
            };

            string[] text2 = text.Split(' ');

            for (int i = 0; i < text2.Length; i += 2)
            {
                if (text2[i] == "R")
                {
                    rook.Pos  = text2[i + 1];
                    rook.Name = text2[i];

                    lst.Add(rook);
                    if (!rook.CheckPos(FigPos))
                    {
                        Console.WriteLine(false);
                        Console.ReadLine();
                        return;
                    }
                }

                if (text2[i] == "H")
                {
                    horse.Pos  = text2[i + 1];
                    horse.Name = text2[i];

                    lst.Add(horse);
                    if (horse.CheckPos(FigPos) == false)
                    {
                        Console.WriteLine(false);
                        Console.ReadLine();
                        return;
                    }
                }
            }

            Console.WriteLine(true);
            Console.ReadLine();
        }
        public void MakeMove(Position origin, Position destiny)
        {
            Piece takenPiece = ChessMove(origin, destiny);

            if (IsInCheck(CurrentPlayer))
            {
                UndoChessMove(origin, destiny, takenPiece);
                throw new BoardExceptions("You can not put your self in check");
            }

            Piece movedPiece = Board.GetPiece(destiny);

            //Special move: Pawn Promotion
            if (movedPiece is Pawn)
            {
                if ((movedPiece.Color == Color.White && destiny.Line == 0) || (movedPiece.Color == Color.Black && destiny.Line == 7))
                {
                    Board.RemovePiece(destiny);
                    GamePieces.Remove(movedPiece);
                    Console.WriteLine("Type the kind of piece you want to promote your pawn to");
                    Console.Write("(QUEEN / ROOK / KNIGHT / BISHOP): ");
                    string playerChoice = Console.ReadLine();
                    if (!ScreenController.CheckPlayerChoice(playerChoice))
                    {
                        throw new BoardExceptions("Not valid option");
                    }
                    playerChoice = playerChoice.ToLower();
                    switch (playerChoice)
                    {
                    case "queen":
                    {
                        Piece newPiece = new Queen(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "rook":
                    {
                        Piece newPiece = new Rook(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "knight":
                    {
                        Piece newPiece = new Knight(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "bishop":
                    {
                        Piece newPiece = new Bishop(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }
                    }
                }
            }
            //EndGame Pawn Promotion

            if (IsInCheck(EnemyIs(CurrentPlayer)))
            {
                PlayerInCheck = true;
            }
            else
            {
                PlayerInCheck = false;
            }

            if (IsInCheckMate(EnemyIs(CurrentPlayer)))
            {
                EndGame = true;
            }
            else
            {
                Turn++;
                MudaJogador();
            }

            //Special move: en passant
            if (movedPiece is Pawn && (destiny.Line == origin.Line + 2 || destiny.Line == origin.Line - 2))
            {
                VulnerableToEnPassant = movedPiece;
            }
            else
            {
                VulnerableToEnPassant = null;
            }
        }
Example #12
0
        /**
         * StartGame()
         *
         * Remplit le plateau et lance le premier tour
         *
         * @author Axel Floquet-Trillot
         * */
        public void StartGame()
        {
            //Remplissage du plateau
            for (int i = 0; i < GameBoard.GetLength(0); i++)
            {
                switch (i)
                {
                case 0:
                    for (int j = 0; j < GameBoard.GetLength(1); j++)
                    {
                        switch (j)
                        {
                        case 0:
                        case 7: GameBoard[i, j] = new Rook(Piece.Color.Black);
                            break;

                        case 1:
                        case 6:  GameBoard[i, j] = new Knight(Piece.Color.Black);
                            break;

                        case 2:
                        case 5: GameBoard[i, j] = new Bishop(Piece.Color.Black);
                            break;

                        case 3: GameBoard[i, j] = new Queen(Piece.Color.Black);
                            break;

                        case 4: GameBoard[i, j] = new King(Piece.Color.Black);
                            break;
                        }
                    }
                    break;

                case 1:
                    for (int j = 0; j < GameBoard.GetLength(1); j++)
                    {
                        GameBoard[i, j] = new Pawn(Piece.Color.Black);
                    }
                    break;

                case 2:
                case 3:
                case 4:
                case 5:
                    for (int j = 0; j < GameBoard.GetLength(1); j++)
                    {
                        GameBoard[i, j] = null;
                    }
                    break;

                case 6:
                    for (int j = 0; j < GameBoard.GetLength(1); j++)
                    {
                        GameBoard[i, j] = new Pawn(Piece.Color.White);
                    }
                    break;

                case 7:
                    for (int j = 0; j < GameBoard.GetLength(1); j++)
                    {
                        switch (j)
                        {
                        case 0:
                        case 7: GameBoard[i, j] = new Rook(Piece.Color.White);
                            break;

                        case 1:
                        case 6: GameBoard[i, j] = new Knight(Piece.Color.White);
                            break;

                        case 2:
                        case 5: GameBoard[i, j] = new Bishop(Piece.Color.White);
                            break;

                        case 3: GameBoard[i, j] = new Queen(Piece.Color.White);
                            break;

                        case 4: GameBoard[i, j] = new King(Piece.Color.White);
                            break;
                        }
                    }
                    break;
                }
            }

            PlayTurn();
        }
Example #13
0
        /// <summary>
        /// Clear the board and place each piece on the board
        /// </summary>
        /// <param name="board"></param>
        public void placePieces(Board board)
        {
            board.clearBoard(board);
            //Instancing each piece
            Rook   newBlackRook1   = new Rook("black", 0, 0);
            Knight newBlackKnight1 = new Knight("black", 0, 1);
            Bishop newBlackBishop1 = new Bishop("black", 0, 2);
            Queen  newBlackQueen   = new Queen("black", 0, 3);
            King   newBlackKing    = new King("black", 0, 4);
            Bishop newBlackBishop2 = new Bishop("black", 0, 5);
            Knight newBlackKnight2 = new Knight("black", 0, 6);
            Rook   newBlackRook2   = new Rook("black", 0, 7);

            Pawn newBlackPawn1 = new Pawn("black", 1, 0);
            Pawn newBlackPawn2 = new Pawn("black", 1, 1);
            Pawn newBlackPawn3 = new Pawn("black", 1, 2);
            Pawn newBlackPawn4 = new Pawn("black", 1, 3);
            Pawn newBlackPawn5 = new Pawn("black", 1, 4);
            Pawn newBlackPawn6 = new Pawn("black", 1, 5);
            Pawn newBlackPawn7 = new Pawn("black", 1, 6);
            Pawn newBlackPawn8 = new Pawn("black", 1, 7);


            Rook   newWhiteRook1   = new Rook("white", 7, 0);
            Knight newWhiteKnight1 = new Knight("white", 7, 1);
            Bishop newWhiteBishop1 = new Bishop("white", 7, 2);
            Queen  newWhiteQueen   = new Queen("white", 7, 3);
            King   newWhiteKing    = new King("white", 7, 4);
            Bishop newWhiteBishop2 = new Bishop("white", 7, 5);
            Knight newWhiteKnight2 = new Knight("white", 7, 6);
            Rook   newWhiteRook2   = new Rook("white", 7, 7);

            Pawn newWhitePawn1 = new Pawn("white", 6, 0);
            Pawn newWhitePawn2 = new Pawn("white", 6, 1);
            Pawn newWhitePawn3 = new Pawn("white", 6, 2);
            Pawn newWhitePawn4 = new Pawn("white", 6, 3);
            Pawn newWhitePawn5 = new Pawn("white", 6, 4);
            Pawn newWhitePawn6 = new Pawn("white", 6, 5);
            Pawn newWhitePawn7 = new Pawn("white", 6, 6);
            Pawn newWhitePawn8 = new Pawn("white", 6, 7);

            //Placing each piece on the board
            board.Grid[0, 0, 0].WhoIsOnIt = newBlackRook1;
            board.Grid[0, 1, 0].WhoIsOnIt = newBlackKnight1;
            board.Grid[0, 2, 0].WhoIsOnIt = newBlackBishop1;
            board.Grid[0, 3, 0].WhoIsOnIt = newBlackQueen;
            board.Grid[0, 4, 0].WhoIsOnIt = newBlackKing;
            board.Grid[0, 5, 0].WhoIsOnIt = newBlackBishop2;
            board.Grid[0, 6, 0].WhoIsOnIt = newBlackKnight2;
            board.Grid[0, 7, 0].WhoIsOnIt = newBlackRook2;

            board.Grid[1, 0, 0].WhoIsOnIt = newBlackPawn1;
            board.Grid[1, 1, 0].WhoIsOnIt = newBlackPawn2;
            board.Grid[1, 2, 0].WhoIsOnIt = newBlackPawn3;
            board.Grid[1, 3, 0].WhoIsOnIt = newBlackPawn4;
            board.Grid[1, 4, 0].WhoIsOnIt = newBlackPawn5;
            board.Grid[1, 5, 0].WhoIsOnIt = newBlackPawn6;
            board.Grid[1, 6, 0].WhoIsOnIt = newBlackPawn7;
            board.Grid[1, 7, 0].WhoIsOnIt = newBlackPawn8;

            board.Grid[7, 0, 0].WhoIsOnIt = newWhiteRook1;
            board.Grid[7, 1, 0].WhoIsOnIt = newWhiteKnight1;
            board.Grid[7, 2, 0].WhoIsOnIt = newWhiteBishop1;
            board.Grid[7, 3, 0].WhoIsOnIt = newWhiteQueen;
            board.Grid[7, 4, 0].WhoIsOnIt = newWhiteKing;
            board.Grid[7, 5, 0].WhoIsOnIt = newWhiteBishop2;
            board.Grid[7, 6, 0].WhoIsOnIt = newWhiteKnight2;
            board.Grid[7, 7, 0].WhoIsOnIt = newWhiteRook2;

            board.Grid[6, 0, 0].WhoIsOnIt = newWhitePawn1;
            board.Grid[6, 1, 0].WhoIsOnIt = newWhitePawn2;
            board.Grid[6, 2, 0].WhoIsOnIt = newWhitePawn3;
            board.Grid[6, 3, 0].WhoIsOnIt = newWhitePawn4;
            board.Grid[6, 4, 0].WhoIsOnIt = newWhitePawn5;
            board.Grid[6, 5, 0].WhoIsOnIt = newWhitePawn6;
            board.Grid[6, 6, 0].WhoIsOnIt = newWhitePawn7;
            board.Grid[6, 7, 0].WhoIsOnIt = newWhitePawn8;
        }
Example #14
0
        public void MakePlay(Position origin, Position destination)
        {
            Piece capturedPiece = ExecuteMoviment(origin, destination);

            if (IsInCheck(ActualPlayer))
            {
                RemakePlay(origin, destination, capturedPiece);
                throw new BoardException("You can't put yourself in check");
            }

            Piece p = Board.Piece(destination);

            //#Promotion

            if (p is Pawn)
            {
                if (p.Color == Colors.White && destination.Line == 0 || p.Color == Colors.Black && destination.Line == 7)
                {
                    p = Board.RemovePiece(destination);
                    _pieces.Remove(p);

                    Console.Write("Promotion: ('Q'|'K'|'B'|'R')");
                    char promotion = char.Parse(Console.ReadLine());

                    switch (promotion)
                    {
                    case 'q':
                        p = new Queen(p.Color, Board);
                        break;

                    case 'k':
                        p = new Knight(p.Color, Board);
                        break;

                    case 'b':
                        p = new Bishop(ActualPlayer, Board);
                        break;

                    case 'r':
                        p = new Rook(ActualPlayer, Board);
                        break;

                    default:
                        p = new Queen(ActualPlayer, Board);
                        break;
                    }

                    Board.PutPiece(p, destination);
                    _pieces.Add(p);
                }
            }

            if (IsInCheck(Adversary(ActualPlayer)))
            {
                Check = true;
            }
            else
            {
                Check = false;
            }
            if (CheckMate(Adversary(ActualPlayer)))
            {
                Ended = true;
            }
            else
            {
                Turn++;
                SwitchPlayer();
            }

            //#EnPassant
            if (p is Pawn && (destination.Line == origin.Line + 2) || (destination.Line == origin.Line - 2))
            {
                VulnerableEnPassant = p;
            }
            else
            {
                VulnerableEnPassant = null;
            }
        }
        public void RookShouldBeCorrectMove()
        {
            Rook figure = new Rook("E2");

            Assert.AreEqual(true, figure.Move("C2"));
        }
Example #16
0
 public override bool Attacks(Square square, Board board)
 {
     return(Rook.Attacks(this, square, board) || Bishop.Attacks(this, square, board));
 }
Example #17
0
        public static void AddPiece(this Game game, Square square, PieceType type)
        {
            Piece piece = null;

            switch (type)
            {
            case PieceType.NoPiece:
                break;

            case PieceType.WhiteKing:
                piece = new King(Color.White);
                break;

            case PieceType.WhiteQueen:
                piece = new Queen(Color.White);
                break;

            case PieceType.WhiteRook:
                piece = new Rook(Color.White);
                break;

            case PieceType.WhiteBishop:
                piece = new Bishop(Color.White);
                break;

            case PieceType.WhiteNight:
                piece = new Knight(Color.White);
                break;

            case PieceType.WhitePawn:
                piece = new Pawn(Color.White);
                break;

            case PieceType.BlackKing:
                piece = new King(Color.Black);
                break;

            case PieceType.BlackQueen:
                piece = new Queen(Color.Black);
                break;

            case PieceType.BlackRook:
                piece = new Rook(Color.Black);
                break;

            case PieceType.BlackBishop:
                piece = new Bishop(Color.Black);
                break;

            case PieceType.BlackKnight:
                piece = new Knight(Color.Black);
                break;

            case PieceType.BlackPawn:
                piece = new Pawn(Color.Black);
                break;

            default:
                throw new NotImplementedException();
            }
            game.AddPiece(square.File, square.Rank, piece);
        }
Example #18
0
        public void Initialize()
        {
            //Initialize all squares
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Square square = new Square();
                    square.File = (File)(i);
                    square.Rank = j;
                    BoardCoordinates.Add(square);
                }
            }

            //Initialize all pieces

            int whiteMajorPieceRank = 1;
            int whitePawnRank       = 2;
            int blackPawnRank       = 7;
            int blackMajorPieceRank = 8;

            File queenRookFile   = File.A;
            File queenKnightFile = File.B;
            File queenBishopFile = File.C;
            File queenFile       = File.D;
            File kingFile        = File.E;
            File kingBishopFile  = File.F;
            File kingKnightFile  = File.G;
            File kingRookFile    = File.H;

            #region Pawns
            for (int i = 0; i < 16; i++)
            {
                Pawn pawn = new Pawn();
                pawn.PieceColor       = i < 8 ? PieceColor.White : PieceColor.Black;
                pawn.Coordinates.Rank = i < 8 ? whitePawnRank : blackPawnRank;
                pawn.Coordinates.File = (File)(i % 8);
                pawn.IsOnBoard        = true;
                Pieces.Add(pawn);
            }
            #endregion

            #region Rooks
            Rook whiteKingRook = new Rook();
            whiteKingRook.Coordinates.Rank = whiteMajorPieceRank;
            whiteKingRook.Coordinates.File = kingRookFile;
            whiteKingRook.IsOnBoard        = true;
            whiteKingRook.PieceColor       = PieceColor.White;
            Pieces.Add(whiteKingRook);

            Rook whiteQueenRook = new Rook();
            whiteQueenRook.Coordinates.Rank = whiteMajorPieceRank;
            whiteQueenRook.Coordinates.File = queenRookFile;
            whiteQueenRook.IsOnBoard        = true;
            whiteQueenRook.PieceColor       = PieceColor.White;
            Pieces.Add(whiteQueenRook);

            Rook blackKingRook = new Rook();
            blackKingRook.Coordinates.Rank = blackMajorPieceRank;
            blackKingRook.Coordinates.File = kingRookFile;
            blackKingRook.IsOnBoard        = true;
            blackKingRook.PieceColor       = PieceColor.Black;
            Pieces.Add(blackKingRook);

            Rook blackQueenRook = new Rook();
            blackQueenRook.Coordinates.File = queenRookFile;
            blackQueenRook.Coordinates.Rank = blackMajorPieceRank;
            blackQueenRook.IsOnBoard        = true;
            blackQueenRook.PieceColor       = PieceColor.Black;
            Pieces.Add(blackQueenRook);

            #endregion

            #region Knights
            Knight whiteQueenKnight = new Knight();
            whiteQueenKnight.Coordinates.File = queenKnightFile;
            whiteQueenKnight.Coordinates.Rank = whiteMajorPieceRank;
            whiteQueenKnight.IsOnBoard        = true;
            whiteQueenKnight.PieceColor       = PieceColor.White;
            Pieces.Add(whiteQueenKnight);

            Knight whiteKingKnight = new Knight();
            whiteKingKnight.Coordinates.File = kingKnightFile;
            whiteKingKnight.Coordinates.Rank = whiteMajorPieceRank;
            whiteKingKnight.IsOnBoard        = true;
            whiteKingKnight.PieceColor       = PieceColor.White;
            Pieces.Add(whiteKingKnight);

            Knight blackQueenKnight = new Knight();
            blackQueenKnight.Coordinates.File = queenKnightFile;
            blackQueenKnight.Coordinates.Rank = blackMajorPieceRank;
            blackQueenKnight.IsOnBoard        = true;
            blackQueenKnight.PieceColor       = PieceColor.Black;
            Pieces.Add(blackQueenKnight);

            Knight blackKingKnight = new Knight();
            blackKingKnight.Coordinates.File = kingKnightFile;
            blackKingKnight.Coordinates.Rank = blackMajorPieceRank;
            blackQueenKnight.IsOnBoard       = true;
            blackQueenKnight.PieceColor      = PieceColor.Black;
            Pieces.Add(blackKingKnight);
            #endregion

            #region Bishop
            Bishop whiteKingBishop = new Bishop();
            whiteKingBishop.Coordinates.Rank = whiteMajorPieceRank;
            whiteKingBishop.Coordinates.File = kingBishopFile;
            whiteKingBishop.IsOnBoard        = true;
            whiteKingBishop.PieceColor       = PieceColor.White;
            Pieces.Add(whiteKingBishop);

            Bishop whiteQueenBishop = new Bishop();
            whiteQueenBishop.Coordinates.Rank = whiteMajorPieceRank;
            whiteQueenBishop.Coordinates.File = queenBishopFile;
            whiteQueenBishop.IsOnBoard        = true;
            whiteQueenBishop.PieceColor       = PieceColor.White;
            Pieces.Add(whiteQueenBishop);

            Bishop blackKingBishop = new Bishop();
            blackKingBishop.Coordinates.Rank = blackMajorPieceRank;
            blackKingBishop.Coordinates.File = kingBishopFile;
            blackKingBishop.IsOnBoard        = true;
            blackKingBishop.PieceColor       = PieceColor.Black;
            Pieces.Add(blackKingBishop);

            Bishop blackQueenBishop = new Bishop();
            blackQueenBishop.Coordinates.Rank = blackMajorPieceRank;
            blackQueenBishop.Coordinates.File = queenBishopFile;
            blackQueenBishop.IsOnBoard        = true;
            blackQueenBishop.PieceColor       = PieceColor.Black;
            Pieces.Add(blackQueenBishop);

            #endregion

            #region Queens
            Queen whiteQueen = new Queen();
            whiteQueen.Coordinates.Rank = whiteMajorPieceRank;
            whiteQueen.Coordinates.File = queenFile;
            whiteQueen.IsOnBoard        = true;
            whiteQueen.PieceColor       = PieceColor.White;
            Pieces.Add(whiteQueen);

            Queen blackQueen = new Queen();
            blackQueen.Coordinates.Rank = blackMajorPieceRank;
            blackQueen.Coordinates.File = queenFile;
            blackQueen.IsOnBoard        = true;
            blackQueen.PieceColor       = PieceColor.Black;
            Pieces.Add(blackQueen);

            #endregion

            #region Kings
            King whiteKing = new King();
            whiteKing.Coordinates.Rank = whiteMajorPieceRank;
            whiteKing.Coordinates.File = kingFile;
            whiteKing.IsOnBoard        = true;
            whiteKing.PieceColor       = PieceColor.White;
            Pieces.Add(whiteKing);

            King blackKing = new King();
            blackKing.Coordinates.File = kingFile;
            blackKing.Coordinates.Rank = blackMajorPieceRank;
            blackKing.IsOnBoard        = true;
            blackKing.PieceColor       = PieceColor.Black;
            Pieces.Add(blackKing);
            #endregion
        }
Example #19
0
        public static void SetupBoard()
        {
            Pawn   p1W = new Pawn(0, 6, "WHITE");
            Pawn   p2W = new Pawn(1, 6, "WHITE");
            Pawn   p3W = new Pawn(2, 6, "WHITE");
            Pawn   p4W = new Pawn(3, 6, "WHITE");
            Pawn   p5W = new Pawn(4, 6, "WHITE");
            Pawn   p6W = new Pawn(5, 6, "WHITE");
            Pawn   p7W = new Pawn(6, 6, "WHITE");
            Pawn   p8W = new Pawn(7, 6, "WHITE");
            Rook   r1W = new Rook(0, 7, "WHITE");
            Knight n1W = new Knight(1, 7, "WHITE");
            Bishop b1W = new Bishop(2, 7, "WHITE");
            Queen  q1W = new Queen(3, 7, "WHITE");
            King   k1W = new King(4, 7, "WHITE");
            Bishop b2W = new Bishop(5, 7, "WHITE");
            Knight n2W = new Knight(6, 7, "WHITE");
            Rook   r2W = new Rook(7, 7, "WHITE");

            Pawn   p1B = new Pawn(0, 1, "BLACK");
            Pawn   p2B = new Pawn(1, 1, "BLACK");
            Pawn   p3B = new Pawn(2, 1, "BLACK");
            Pawn   p4B = new Pawn(3, 1, "BLACK");
            Pawn   p5B = new Pawn(4, 1, "BLACK");
            Pawn   p6B = new Pawn(5, 1, "BLACK");
            Pawn   p7B = new Pawn(6, 1, "BLACK");
            Pawn   p8B = new Pawn(7, 1, "BLACK");
            Rook   r1B = new Rook(0, 0, "BLACK");
            Knight n1B = new Knight(1, 0, "BLACK");
            Bishop b1B = new Bishop(2, 0, "BLACK");
            Queen  q1B = new Queen(3, 0, "BLACK");
            King   k1B = new King(4, 0, "BLACK");
            Bishop b2B = new Bishop(5, 0, "BLACK");
            Knight n2B = new Knight(6, 0, "BLACK");
            Rook   r2B = new Rook(7, 0, "BLACK");


            board[p1W.Y, p1W.X] = p1W;
            board[p2W.Y, p2W.X] = p2W;
            board[p3W.Y, p3W.X] = p3W;
            board[p4W.Y, p4W.X] = p4W;
            board[p5W.Y, p5W.X] = p5W;
            board[p6W.Y, p6W.X] = p6W;
            board[p7W.Y, p7W.X] = p7W;
            board[p8W.Y, p8W.X] = p8W;
            board[r1W.Y, r1W.X] = r1W;
            board[n1W.Y, n1W.X] = n1W;
            board[b1W.Y, b1W.X] = b1W;
            board[q1W.Y, q1W.X] = q1W;
            board[k1W.Y, k1W.X] = k1W;
            board[b2W.Y, b2W.X] = b2W;
            board[n2W.Y, n2W.X] = n2W;
            board[r2W.Y, r2W.X] = r2W;

            board[p1B.Y, p1B.X] = p1B;
            board[p2B.Y, p2B.X] = p2B;
            board[p3B.Y, p3B.X] = p3B;
            board[p4B.Y, p4B.X] = p4B;
            board[p5B.Y, p5B.X] = p5B;
            board[p6B.Y, p6B.X] = p6B;
            board[p7B.Y, p7B.X] = p7B;
            board[p8B.Y, p8B.X] = p8B;
            board[r1B.Y, r1B.X] = r1B;
            board[n1B.Y, n1B.X] = n1B;
            board[b1B.Y, b1B.X] = b1B;
            board[q1B.Y, q1B.X] = q1B;
            board[k1B.Y, k1B.X] = k1B;
            board[b2B.Y, b2B.X] = b2B;
            board[n2B.Y, n2B.X] = n2B;
            board[r2B.Y, r2B.X] = r2B;
        }
Example #20
0
        static void Main(string[] args)
        {
            Position pawn1StartingPosition = new Position(0, 1);
            Pawn     pawn1 = new Pawn(pawn1StartingPosition);

            Position[] pawn1MovementOptions = pawn1.MovementOptions();
            Console.WriteLine("A posição inicial do Peão 1 é:");
            pawn1.Pos.Print();
            Console.WriteLine("A posição válida para movimento dele é:");
            pawn1MovementOptions[0].Print();
            Console.WriteLine();

            Position rook1StartingPosition = new Position(0, 0);
            Rook     rook1 = new Rook(rook1StartingPosition);

            Position[] rook1MovementOptions = rook1.MovementOptions();
            Console.WriteLine("A posição inicial da Torre 1 é:");
            rook1.Pos.Print();
            Console.WriteLine("As posições válidas para movimento dele são:");
            for (int i = 0; i < rook1.MovementOptions().Length; i++)
            {
                rook1MovementOptions[i].Print();
            }

            Position bishop1StartingPosition = new Position(2, 0);
            Bishop   bishop1 = new Bishop(bishop1StartingPosition);

            Position[] bishop1MovementOptions = bishop1.MovementOptions();
            Console.WriteLine("A posição inicial do Bispo 1 é:");
            bishop1.Pos.Print();
            Console.WriteLine("As posições válidas para movimento dele são:");
            for (int i = 0; i < bishop1.MovementOptions().Length; i++)
            {
                bishop1MovementOptions[i].Print();
            }

            Position knight1StartingPosition = new Position(1, 0);
            Knight   knight1 = new Knight(knight1StartingPosition);

            Position[] knight1MovementOptions = knight1.MovementOptions();
            Console.WriteLine("A posição inicial do Cavaleiro 1 é:");
            knight1.Pos.Print();
            Console.WriteLine("As posições válidas para movimento dele são:");
            for (int i = 0; i < knight1.MovementOptions().Length; i++)
            {
                knight1MovementOptions[i].Print();
            }

            Position queen1StartingPosition = new Position(4, 0);
            Queen    queen1 = new Queen(queen1StartingPosition);

            Position[] queen1MovementOptions = queen1.MovementOptions();
            Console.WriteLine("A posição inicial da Rainha 1 é:");
            queen1.Pos.Print();
            Console.WriteLine("As posições válidas para movimento dela são:");
            for (int i = 0; i < queen1.MovementOptions().Length; i++)
            {
                queen1MovementOptions[i].Print();
            }

            Position king1StartingPosition = new Position(3, 0);
            King     king1 = new King(king1StartingPosition);

            Position[] king1MovementOptions = king1.MovementOptions();
            Console.WriteLine("A posição inicial do Rei 1 é:");
            king1.Pos.Print();
            Console.WriteLine("As posições válidas para movimento dele são:");
            for (int i = 0; i < king1.MovementOptions().Length; i++)
            {
                king1MovementOptions[i].Print();
            }
            Console.ReadKey();
        }
Example #21
0
        public void initBoard()
        {
            Console.WriteLine("INIT Board");

            /* Queens */
            chessPiece QueenW = new Queen(false, 7, 3);

            chessBoard[QueenW.getX(), QueenW.getY()] = QueenW;
            chessPiece QueenB = new Queen(true, 0, 3);

            chessBoard[QueenB.getX(), QueenB.getY()] = QueenB;

            // /* Kings */
            chessPiece KingW = new King(false, 7, 4);

            chessBoard[KingW.getX(), KingW.getY()] = KingW;
            setKingLocation(false, 7, 4);
            chessPiece KingB = new King(true, 0, 4);

            chessBoard[KingB.getX(), KingB.getY()] = KingB;
            setKingLocation(true, 0, 4);

            // /* Bishops */
            chessPiece BishW1 = new Bishop(false, 7, 2);

            chessBoard[BishW1.getX(), BishW1.getY()] = BishW1;
            chessPiece BishW2 = new Bishop(false, 7, 5);

            chessBoard[BishW2.getX(), BishW2.getY()] = BishW2;
            // Blacks
            chessPiece BishB1 = new Bishop(true, 0, 2);

            chessBoard[BishB1.getX(), BishB1.getY()] = BishB1;
            chessPiece BishB2 = new Bishop(true, 0, 5);

            chessBoard[BishB2.getX(), BishB2.getY()] = BishB2;

            // /* Knights */
            chessPiece KnW1 = new Knight(false, 7, 1);

            chessBoard[KnW1.getX(), KnW1.getY()] = KnW1;
            chessPiece KnW2 = new Knight(false, 7, 6);

            chessBoard[KnW2.getX(), KnW2.getY()] = KnW2;
            // Blacks
            chessPiece KnB1 = new Knight(true, 0, 1);

            chessBoard[KnB1.getX(), KnB1.getY()] = KnB1;
            chessPiece KnB2 = new Knight(true, 0, 6);

            chessBoard[KnB2.getX(), KnB2.getY()] = KnB2;

            /* Rooks */
            chessPiece RookW1 = new Rook(false, 7, 0);

            chessBoard[RookW1.getX(), RookW1.getY()] = RookW1;
            chessPiece RookW2 = new Rook(false, 7, 7);

            chessBoard[RookW2.getX(), RookW2.getY()] = RookW2;
            // Blacks
            chessPiece RookB1 = new Rook(true, 0, 0);

            chessBoard[RookB1.getX(), RookB1.getY()] = RookB1;
            chessPiece RookB2 = new Rook(true, 0, 7);

            chessBoard[RookB2.getX(), RookB2.getY()] = RookB2;

            /* Pawns */
            // chessPiece PawnW1 = new Pawn(false, 4, 4);
            // chessBoard[PawnW1.getX(), PawnW1.getY()] = PawnW1;
            // chessPiece PawnW2 = new Pawn(false, 6, 1);
            // chessBoard[PawnW2.getX(), PawnW2.getY()] = PawnW2;
            // chessPiece PawnW3 = new Pawn(false, 6, 2);
            // chessBoard[PawnW3.getX(), PawnW3.getY()] = PawnW3;
            // chessPiece PawnW4 = new Pawn(false, 6, 3);
            // chessBoard[PawnW4.getX(), PawnW4.getY()] = PawnW4;
            // chessPiece PawnW5 = new Pawn(false, 6, 4);
            // chessBoard[PawnW5.getX(), PawnW5.getY()] = PawnW5;
            // chessPiece PawnW6 = new Pawn(false, 6, 5);
            // chessBoard[PawnW6.getX(), PawnW6.getY()] = PawnW6;
            // chessPiece PawnW7 = new Pawn(false, 6, 6);
            // chessBoard[PawnW7.getX(), PawnW7.getY()] = PawnW7;
            // chessPiece PawnW8 = new Pawn(false, 6, 7);
            // chessBoard[PawnW8.getX(), PawnW8.getY()] = PawnW8;
            //  // Blacks
            // chessPiece PawnB1 = new Pawn(true, 1, 0);
            // chessBoard[PawnB1.getX(), PawnB1.getY()] = PawnB1;
            // chessPiece PawnB2 = new Pawn(true, 1, 1);
            // chessBoard[PawnB2.getX(), PawnB2.getY()] = PawnB2;
            // chessPiece PawnB3 = new Pawn(true, 1, 2);
            // chessBoard[PawnB3.getX(), PawnB3.getY()] = PawnB3;
            // chessPiece PawnB4 = new Pawn(true, 1, 3);
            // chessBoard[PawnB4.getX(), PawnB4.getY()] = PawnB4;
            // chessPiece PawnB5 = new Pawn(true, 1, 4);
            // chessBoard[PawnB5.getX(), PawnB5.getY()] = PawnB5;
            // chessPiece PawnB6 = new Pawn(true, 1, 5);
            // chessBoard[PawnB6.getX(), PawnB6.getY()] = PawnB6;
            // chessPiece PawnB7 = new Pawn(true, 1, 6);
            // chessBoard[PawnB7.getX(), PawnB7.getY()] = PawnB7;
            // chessPiece PawnB8 = new Pawn(true, 1, 7);
            // chessBoard[PawnB8.getX(), PawnB8.getY()] = PawnB8;
        }
Example #22
0
        public void SetupBoard(string setup)
        {
            switch (setup)
            {
            case "new_game_setup":

                // WEISSE SPIELFIGUREN
                PawnWhite pawn_w_1   = factory.GetPawnWhite("A2");
                PawnWhite pawn_w_2   = factory.GetPawnWhite("B2");
                PawnWhite pawn_w_3   = factory.GetPawnWhite("C2");
                PawnWhite pawn_w_4   = factory.GetPawnWhite("D2");
                PawnWhite pawn_w_5   = factory.GetPawnWhite("E2");
                PawnWhite pawn_w_6   = factory.GetPawnWhite("F2");
                PawnWhite pawn_w_7   = factory.GetPawnWhite("G2");
                PawnWhite pawn_w_8   = factory.GetPawnWhite("H2");
                Rook      rook_w_1   = factory.GetRook("white", "A1");
                Knight    knight_w_1 = factory.GetKnight("white", "B1");
                Bishop    bishop_w_1 = factory.GetBishop("white", "C1");
                Queen     queen_w    = factory.GetQueen("white", "D1");
                King      king_w     = factory.GetKing("white", "E1");
                Bishop    bishop_w_2 = factory.GetBishop("white", "F1");
                Knight    knight_w_2 = factory.GetKnight("white", "G1");
                Rook      rook_w_2   = factory.GetRook("white", "H1");

                // SCHWARZE SPIELFIGUREN
                PawnBlack pawn_b_1   = factory.GetPawnBlack("A7");
                PawnBlack pawn_b_2   = factory.GetPawnBlack("B7");
                PawnBlack pawn_b_3   = factory.GetPawnBlack("C7");
                PawnBlack pawn_b_4   = factory.GetPawnBlack("D7");
                PawnBlack pawn_b_5   = factory.GetPawnBlack("E7");
                PawnBlack pawn_b_6   = factory.GetPawnBlack("F7");
                PawnBlack pawn_b_7   = factory.GetPawnBlack("G7");
                PawnBlack pawn_b_8   = factory.GetPawnBlack("H7");
                Rook      rook_b_1   = factory.GetRook("black", "A8");
                Knight    knight_b_1 = factory.GetKnight("black", "B8");
                Bishop    bishop_b_1 = factory.GetBishop("black", "C8");
                Queen     queen_b    = factory.GetQueen("black", "D8");
                King      king_b     = factory.GetKing("black", "E8");
                Bishop    bishop_b_2 = factory.GetBishop("black", "F8");
                Knight    knight_b_2 = factory.GetKnight("black", "G8");
                Rook      rook_b_2   = factory.GetRook("black", "H8");

                // WEISSE SPIELFIGUREN
                board.chessman.Add(pawn_w_1);
                board.chessman.Add(pawn_w_2);
                board.chessman.Add(pawn_w_3);
                board.chessman.Add(pawn_w_4);
                board.chessman.Add(pawn_w_5);
                board.chessman.Add(pawn_w_6);
                board.chessman.Add(pawn_w_7);
                board.chessman.Add(pawn_w_8);
                board.chessman.Add(rook_w_1);
                board.chessman.Add(rook_w_2);
                board.chessman.Add(bishop_w_1);
                board.chessman.Add(bishop_w_2);
                board.chessman.Add(knight_w_1);
                board.chessman.Add(knight_w_2);
                board.chessman.Add(queen_w);
                board.chessman.Add(king_w);

                // SCHWARZE SPIELFIGUREN
                board.chessman.Add(pawn_b_1);
                board.chessman.Add(pawn_b_2);
                board.chessman.Add(pawn_b_3);
                board.chessman.Add(pawn_b_4);
                board.chessman.Add(pawn_b_5);
                board.chessman.Add(pawn_b_6);
                board.chessman.Add(pawn_b_7);
                board.chessman.Add(pawn_b_8);
                board.chessman.Add(rook_b_1);
                board.chessman.Add(rook_b_2);
                board.chessman.Add(bishop_b_1);
                board.chessman.Add(bishop_b_2);
                board.chessman.Add(knight_b_1);
                board.chessman.Add(knight_b_2);
                board.chessman.Add(queen_b);
                board.chessman.Add(king_b);

                break;

            case "promotion_setup":
                // WEISSE SPIELFIGUREN
                PawnWhite promotion_pawn_w_1   = factory.GetPawnWhite("A7");
                PawnWhite promotion_pawn_w_2   = factory.GetPawnWhite("B7");
                King      promotion_king_w     = factory.GetKing("white", "E1");
                Bishop    promotion_bishop_w_2 = factory.GetBishop("white", "F1");
                Knight    promotion_knight_w_2 = factory.GetKnight("white", "G1");
                Rook      promotion_rook_w_2   = factory.GetRook("white", "H1");

                // SCHWARZE SPIELFIGUREN
                PawnBlack promotion_pawn_b_1   = factory.GetPawnBlack("A2");
                PawnBlack promotion_pawn_b_2   = factory.GetPawnBlack("B2");
                King      promotion_king_b     = factory.GetKing("black", "E8");
                Bishop    promotion_bishop_b_2 = factory.GetBishop("black", "F8");
                Knight    promotion_knight_b_2 = factory.GetKnight("black", "G8");
                Rook      promotion_rook_b_2   = factory.GetRook("black", "H8");

                // WEISSE SPIELFIGUREN
                board.chessman.Add(promotion_pawn_w_1);
                board.chessman.Add(promotion_pawn_w_2);
                board.chessman.Add(promotion_king_w);
                board.chessman.Add(promotion_knight_w_2);
                board.chessman.Add(promotion_bishop_w_2);
                board.chessman.Add(promotion_rook_w_2);

                // SCHWARZE SPIELFIGUREN
                board.chessman.Add(promotion_pawn_b_1);
                board.chessman.Add(promotion_pawn_b_2);
                board.chessman.Add(promotion_king_b);
                board.chessman.Add(promotion_knight_b_2);
                board.chessman.Add(promotion_bishop_b_2);
                board.chessman.Add(promotion_rook_b_2);

                break;

            case "en_passant_setup":

                // WEISSE SPIELFIGUREN
                PawnWhite en_passant_pawn_w_1   = factory.GetPawnWhite("A2");
                PawnWhite en_passant_pawn_w_2   = factory.GetPawnWhite("B2");
                PawnWhite en_passant_pawn_w_3   = factory.GetPawnWhite("C4");
                PawnWhite en_passant_pawn_w_4   = factory.GetPawnWhite("D2");
                PawnWhite en_passant_pawn_w_5   = factory.GetPawnWhite("E2");
                PawnWhite en_passant_pawn_w_6   = factory.GetPawnWhite("F2");
                PawnWhite en_passant_pawn_w_7   = factory.GetPawnWhite("G2");
                PawnWhite en_passant_pawn_w_8   = factory.GetPawnWhite("H2");
                Rook      en_passant_rook_w_1   = factory.GetRook("white", "A1");
                Knight    en_passant_knight_w_1 = factory.GetKnight("white", "B1");
                Bishop    en_passant_bishop_w_1 = factory.GetBishop("white", "C1");
                Queen     en_passant_queen_w    = factory.GetQueen("white", "D1");
                King      en_passant_king_w     = factory.GetKing("white", "E1");
                Bishop    en_passant_bishop_w_2 = factory.GetBishop("white", "F1");
                Knight    en_passant_knight_w_2 = factory.GetKnight("white", "G1");
                Rook      en_passant_rook_w_2   = factory.GetRook("white", "H1");

                // SCHWARZE SPIELFIGUREN
                PawnBlack en_passant_pawn_b_1   = factory.GetPawnBlack("A7");
                PawnBlack en_passant_pawn_b_2   = factory.GetPawnBlack("B7");
                PawnBlack en_passant_pawn_b_3   = factory.GetPawnBlack("C7");
                PawnBlack en_passant_pawn_b_4   = factory.GetPawnBlack("D7");
                PawnBlack en_passant_pawn_b_5   = factory.GetPawnBlack("E7");
                PawnBlack en_passant_pawn_b_6   = factory.GetPawnBlack("F5");
                PawnBlack en_passant_pawn_b_7   = factory.GetPawnBlack("G7");
                PawnBlack en_passant_pawn_b_8   = factory.GetPawnBlack("H7");
                Rook      en_passant_rook_b_1   = factory.GetRook("black", "A8");
                Knight    en_passant_knight_b_1 = factory.GetKnight("black", "B8");
                Bishop    en_passant_bishop_b_1 = factory.GetBishop("black", "C8");
                Queen     en_passant_queen_b    = factory.GetQueen("black", "D8");
                King      en_passant_king_b     = factory.GetKing("black", "E8");
                Bishop    en_passant_bishop_b_2 = factory.GetBishop("black", "F8");
                Knight    en_passant_knight_b_2 = factory.GetKnight("black", "G8");
                Rook      en_passant_rook_b_2   = factory.GetRook("black", "H8");

                // WEISSE SPIELFIGUREN
                board.chessman.Add(en_passant_pawn_w_1);
                board.chessman.Add(en_passant_pawn_w_2);
                board.chessman.Add(en_passant_pawn_w_3);
                board.chessman.Add(en_passant_pawn_w_4);
                board.chessman.Add(en_passant_pawn_w_5);
                board.chessman.Add(en_passant_pawn_w_6);
                board.chessman.Add(en_passant_pawn_w_7);
                board.chessman.Add(en_passant_pawn_w_8);
                board.chessman.Add(en_passant_rook_w_1);
                board.chessman.Add(en_passant_rook_w_2);
                board.chessman.Add(en_passant_bishop_w_1);
                board.chessman.Add(en_passant_bishop_w_2);
                board.chessman.Add(en_passant_knight_w_1);
                board.chessman.Add(en_passant_knight_w_2);
                board.chessman.Add(en_passant_queen_w);
                board.chessman.Add(en_passant_king_w);

                // SCHWARZE SPIELFIGUREN
                board.chessman.Add(en_passant_pawn_b_1);
                board.chessman.Add(en_passant_pawn_b_2);
                board.chessman.Add(en_passant_pawn_b_3);
                board.chessman.Add(en_passant_pawn_b_4);
                board.chessman.Add(en_passant_pawn_b_5);
                board.chessman.Add(en_passant_pawn_b_6);
                board.chessman.Add(en_passant_pawn_b_7);
                board.chessman.Add(en_passant_pawn_b_8);
                board.chessman.Add(en_passant_rook_b_1);
                board.chessman.Add(en_passant_rook_b_2);
                board.chessman.Add(en_passant_bishop_b_1);
                board.chessman.Add(en_passant_bishop_b_2);
                board.chessman.Add(en_passant_knight_b_1);
                board.chessman.Add(en_passant_knight_b_2);
                board.chessman.Add(en_passant_queen_b);
                board.chessman.Add(en_passant_king_b);

                break;

            case "castling_setup":

                // WEISSE SPIELFIGUREN

                Rook castling_rook_w_1 = factory.GetRook("white", "A1");
                King castling_king_w   = factory.GetKing("white", "E1");
                Rook castling_rook_w_2 = factory.GetRook("white", "H1");

                // SCHWARZE SPIELFIGUREN
                Rook castling_rook_b_1 = factory.GetRook("black", "A8");
                King castling_king_b   = factory.GetKing("black", "E8");
                Rook castling_rook_b_2 = factory.GetRook("black", "H8");

                // WEISSE SPIELFIGUREN
                board.chessman.Add(castling_rook_w_1);
                board.chessman.Add(castling_rook_w_2);
                board.chessman.Add(castling_king_w);

                // SCHWARZE SPIELFIGUREN
                board.chessman.Add(castling_rook_b_1);
                board.chessman.Add(castling_rook_b_2);
                board.chessman.Add(castling_king_b);

                break;
            }
        }
        private void InitializePlayersPieces()
        {
            foreach (var player in Players)
            {
                if (player.Pieces != null)
                {
                    player.Pieces = null;
                }

                if (player.PlayerColor == Color.Black)
                {
                    ChessPiece one   = new Rook("R1", "R", player.PlayerColor, GetLocation("A1"), null, false) as ChessPiece;
                    ChessPiece two   = new Knight("Kn1", "Kn", player.PlayerColor, GetLocation("B1"), null, true) as ChessPiece;
                    ChessPiece three = new Bishop("B1", "B", player.PlayerColor, GetLocation("C1"), null, false) as ChessPiece;
                    //ChessPiece four = new ChessPiece("Q", "Q", player.PlayerColor, GetLocation("D1"), null);
                    //ChessPiece five = new ChessPiece("K", "K", player.PlayerColor, GetLocation("E1"), null);
                    ChessPiece six      = new Bishop("B2", "B", player.PlayerColor, GetLocation("F1"), null, false) as ChessPiece;
                    ChessPiece seven    = new Knight("Kn2", "Kn", player.PlayerColor, GetLocation("G1"), null, true) as ChessPiece;
                    ChessPiece eight    = new Rook("R2", "R", player.PlayerColor, GetLocation("H1"), null, false) as ChessPiece;
                    ChessPiece nine     = new Pawn("P1", "P", player.PlayerColor, GetLocation("A2"), null, false) as ChessPiece;
                    ChessPiece ten      = new Pawn("P1", "P", player.PlayerColor, GetLocation("B2"), null, false) as ChessPiece;
                    ChessPiece eleven   = new Pawn("P1", "P", player.PlayerColor, GetLocation("C2"), null, false) as ChessPiece;
                    ChessPiece twelve   = new Pawn("P2", "P", player.PlayerColor, GetLocation("D2"), null, false) as ChessPiece;
                    ChessPiece thirteen = new Pawn("P3", "P", player.PlayerColor, GetLocation("E2"), null, false) as ChessPiece;
                    ChessPiece fourteen = new Pawn("P4", "P", player.PlayerColor, GetLocation("F2"), null, false) as ChessPiece;
                    ChessPiece fifteen  = new Pawn("P5", "P", player.PlayerColor, GetLocation("G2"), null, false) as ChessPiece;
                    ChessPiece sixteen  = new Pawn("P6", "P", player.PlayerColor, GetLocation("H2"), null, false) as ChessPiece;

                    player.Pieces = new List <ChessPiece>();
                    player.Pieces.Add(one);
                    player.Pieces.Add(two);
                    player.Pieces.Add(three);
                    //player.Pieces.Add(four);
                    //player.Pieces.Add(five);
                    player.Pieces.Add(six);
                    player.Pieces.Add(seven);
                    player.Pieces.Add(eight);
                    player.Pieces.Add(nine);
                    player.Pieces.Add(ten);
                    player.Pieces.Add(eleven);
                    player.Pieces.Add(twelve);
                    player.Pieces.Add(thirteen);
                    player.Pieces.Add(fourteen);
                    player.Pieces.Add(fifteen);
                    player.Pieces.Add(sixteen);
                }
                else
                {
                    ChessPiece one   = new Rook("R3", "R", player.PlayerColor, GetLocation("A8"), null, false) as ChessPiece;
                    ChessPiece two   = new Knight("Kn3", "Kn", player.PlayerColor, GetLocation("B8"), null, true) as ChessPiece;
                    ChessPiece three = new Bishop("B3", "B", player.PlayerColor, GetLocation("C8"), null, false) as ChessPiece;
                    //ChessPiece four = new ChessPiece("Q", "Q", player.PlayerColor, GetLocation("D8"), null);
                    //ChessPiece five = new ChessPiece("K", "K", player.PlayerColor, GetLocation("E8"), null);
                    ChessPiece six      = new Bishop("B4", "B", player.PlayerColor, GetLocation("F8"), null, false) as ChessPiece;
                    ChessPiece seven    = new Knight("Kn4", "Kn", player.PlayerColor, GetLocation("G8"), null, true) as ChessPiece;
                    ChessPiece eight    = new Rook("R4", "R", player.PlayerColor, GetLocation("H8"), null, false) as ChessPiece;
                    ChessPiece nine     = new Pawn("P7", "P", player.PlayerColor, GetLocation("A7"), null, false) as ChessPiece;
                    ChessPiece ten      = new Pawn("P8", "P", player.PlayerColor, GetLocation("B7"), null, false) as ChessPiece;
                    ChessPiece eleven   = new Pawn("P9", "P", player.PlayerColor, GetLocation("C7"), null, false) as ChessPiece;
                    ChessPiece twelve   = new Pawn("P10", "P", player.PlayerColor, GetLocation("D7"), null, false) as ChessPiece;
                    ChessPiece thirteen = new Pawn("P11", "P", player.PlayerColor, GetLocation("E7"), null, false) as ChessPiece;
                    ChessPiece fourteen = new Pawn("P12", "P", player.PlayerColor, GetLocation("F7"), null, false) as ChessPiece;
                    ChessPiece fifteen  = new Pawn("P13", "P", player.PlayerColor, GetLocation("G7"), null, false) as ChessPiece;
                    ChessPiece sixteen  = new Pawn("P14", "P", player.PlayerColor, GetLocation("H7"), null, false) as ChessPiece;

                    player.Pieces = new List <ChessPiece>();
                    player.Pieces.Add(one);
                    player.Pieces.Add(two);
                    player.Pieces.Add(three);
                    //player.Pieces.Add(four);
                    //player.Pieces.Add(five);
                    player.Pieces.Add(six);
                    player.Pieces.Add(seven);
                    player.Pieces.Add(eight);
                    player.Pieces.Add(nine);
                    player.Pieces.Add(ten);
                    player.Pieces.Add(eleven);
                    player.Pieces.Add(twelve);
                    player.Pieces.Add(thirteen);
                    player.Pieces.Add(fourteen);
                    player.Pieces.Add(fifteen);
                    player.Pieces.Add(sixteen);
                }
            }
        }
Example #24
0
        internal static Piece[,] GetFairyDefault()
        {
            Piece[,] b = new Piece[BOARDSIZE, BOARDSIZE];

            // Set Antelope
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 1));

                b[posX, (team * (BOARDSIZE - 1))] = new Antelope(team);
            }

            // Set Camel
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 3) + 1);

                b[posX, (team * (BOARDSIZE - 1))] = new Camel(team);
            }

            // Set Bow
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 5) + 2);

                b[posX, (team * (BOARDSIZE - 1))] = new Bow(team);
            }

            // Set Bull
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 7) + 3);

                b[posX, (team * (BOARDSIZE - 1))] = new Bull(team);
            }

            // Set Cannon
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 9) + 4);

                b[posX, (team * (BOARDSIZE - 1))] = new Cannon(team);
            }

            // Set Buffalo
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[5, (team * (BOARDSIZE - 1))] = new Buffalo(team);
            }

            // Set Rhinoceros
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[6, (team * (BOARDSIZE - 1))] = new Rhinoceros(team);
            }

            // Set Star
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[7, (team * (BOARDSIZE - 1))] = new Star(team);
            }

            // Set Unicorn
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[8, (team * (BOARDSIZE - 1))] = new Unicorn(team);
            }

            // Set DragonWoman
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[9, (team * (BOARDSIZE - 1))] = new DragonWoman(team);
            }

            // Set Diablo
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[10, (team * (BOARDSIZE - 1))] = new Diablo(team);
            }

            // Set Centurion
            for (int seed = 0; seed < 28; seed++)
            {
                byte team = (byte)((seed / 14) % 2);
                byte posX = (byte)(((9 + seed) + (team * 2)) % BOARDSIZE);
                b[posX, ((team * (BOARDSIZE - 3)) + 1)] = new Centurion(team);
            }

            // Set Lion
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[7, ((team * (BOARDSIZE - 3)) + 1)] = new Lion(team);
            }

            // Set Gryphon
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[8, ((team * (BOARDSIZE - 3)) + 1)] = new Gryphon(team);
            }

            // Set Elephant
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)((seed % 2) * (BOARDSIZE - 1));

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Elephant(team);
            }

            // Set Machine
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 3)) + 1);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Machine(team);
            }

            // Set Rook
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 5)) + 2);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Rook(team);
            }

            // Set Knight
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 7)) + 3);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Knight(team);
            }

            // Set Bishop
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 9)) + 4);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Bishop(team);
            }

            // Set Ship
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 11)) + 5);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Ship(team);
            }

            // Set Buffoon
            for (int seed = 0; seed < 4; seed++)
            {
                byte team = (byte)(seed / 2);
                byte posX = (byte)(((seed % 2) * (BOARDSIZE - 13)) + 6);

                b[posX, (team * (BOARDSIZE - 5)) + 2] = new Buffoon(team);
            }

            // Set Queen
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[7, ((team * (BOARDSIZE - 5)) + 2)] = new Queen(team);
            }

            // Set King
            for (int seed = 0; seed < 2; seed++)
            {
                byte team = (byte)(seed % 2);
                b[8, ((team * (BOARDSIZE - 5)) + 2)] = new King(team);
            }

            // Set FairyPawn
            for (int seed = 0; seed < 32; seed++)
            {
                byte team = (byte)(seed / 16);
                b[(seed % 16), (byte)((team * (BOARDSIZE - 7)) + 3)] = new FairyPawn(team);
            }

            return(b);
        }
Example #25
0
        // Investigates if a move is Legal
        private Condition MovePossibility(GamePiece piece, Cell fromCell, Cell toCell, Condition condition)
        {
            Condition result = Condition.Default;

            if (fromCell == toCell)
            {
                return(Condition.Active); // Already there
            }
            if (toCell.Piece is null)     // cell is Empty
            {
                // Legal Neutral
                if (condition == Condition.Default || condition == Condition.Neutral)
                {
                    result = Condition.Neutral;
                }
                // Legal Pawn Enpassant Move
                else if (piece is Pawn && condition == Condition.Attack && !(toCell.enPassantPawn is null))
                {
                    result = Condition.enPassant;
                }
            }
            else if (toCell.Piece != null && toCell.Piece.TeamColor != piece.TeamColor) // cell is Enemy
            {
                // Legal Attack
                if (condition == Condition.Default || condition == Condition.Attack)
                {
                    result = Condition.Attack;
                }
            }

            if (condition == Condition.Castling)
            {
                Player player = piece.TeamColor == PlayerOne.TeamColor ? PlayerOne : PlayerTwo;
                // get Rook
                int   xDirection   = fromCell.ID.X > toCell.ID.X ? -1 : 1;
                Point rookLocation = xDirection == 1 ? new Point(7, fromCell.ID.Y) : new Point(0, fromCell.ID.Y);
                Rook  rook         = (Rook)player.MyPieces.Find(gp => gp.ID == rookLocation && gp.moveCount == 0 && gp.isAlive);

                if (rook is null)
                {
                    result = Condition.Illegal; // Rook is missing
                }
                else
                {
                    if (piece.moveCount != 0 && rook.moveCount != 0)
                    {
                        result = Condition.Illegal; // Cannot Castle when King & Rook are not in original locations
                    }
                    else
                    {
                        Cell focus = Cells.NextCell(fromCell, new Point(xDirection, 0));
                        while (focus.Piece is null) // find next gamepiece in the movement direction
                        {
                            focus = Cells.NextCell(focus, new Point(xDirection, 0));
                        }

                        if (!ReferenceEquals(rook, focus.Piece))
                        {
                            result = Condition.Illegal; // Other Pieces in the way
                        }
                        else
                        {
                            if (player.isChecked == true)
                            {
                                result = Condition.Illegal; // Cannot Castle when in Check
                            }
                            else
                            {
                                Point passThrough = new Point(fromCell.ID.X + xDirection, fromCell.ID.Y);
                                if (!IsSafe(passThrough, WhosTurn))
                                {
                                    result = Condition.Illegal; // Cannot Castle through Check
                                }
                                else
                                {
                                    result = Condition.Castling; // Castling Permitted! (Well still one more test in PossibleMoves())
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
        public void RookShouldBeIncorrectMove()
        {
            ChessFigure figure = new Rook("E2");

            Assert.AreEqual(false, figure.Move("C5"));
        }
Example #27
0
 public void BeforeEachTest()
 {
     Target = new Rook();
     MovesFrom11 = Target.GetMovesFrom(new BoardCoordinate(1, 1));
 }
Example #28
0
        static void StartPlacement(Cell[,] Field)
        {
            King WhiteKing = new King(1, '♚', 7, 4);

            WhiteKing.SetToCell(Field, 7, 4);
            WhiteKing.SetFigureColor(Field, 7, 4);
            King BlackKing = new King(0, '♚', 0, 4);

            BlackKing.SetToCell(Field, 0, 4);
            BlackKing.SetFigureColor(Field, 0, 4);
            Quinn WhiteQuinn = new Quinn(1, '♛', 7, 3);

            WhiteQuinn.SetToCell(Field, 7, 3);
            WhiteQuinn.SetFigureColor(Field, 7, 3);
            Quinn BlackQuinn = new Quinn(0, '♛', 0, 3);

            BlackQuinn.SetToCell(Field, 0, 3);
            BlackQuinn.SetFigureColor(Field, 0, 3);
            Bishop WhiteBishop1 = new Bishop(1, '♝', 7, 2);

            WhiteBishop1.SetToCell(Field, 7, 2);
            WhiteBishop1.SetFigureColor(Field, 7, 2);
            Bishop WhiteBishop2 = new Bishop(1, '♝', 7, 5);

            WhiteBishop2.SetToCell(Field, 7, 5);
            WhiteBishop2.SetFigureColor(Field, 7, 5);
            Bishop BlackBishop1 = new Bishop(0, '♝', 0, 2);

            BlackBishop1.SetToCell(Field, 0, 2);
            BlackBishop1.SetFigureColor(Field, 0, 2);
            Bishop BlackBishop2 = new Bishop(0, '♝', 0, 5);

            BlackBishop2.SetToCell(Field, 0, 5);
            BlackBishop2.SetFigureColor(Field, 0, 5);
            Knight WhiteKnight1 = new Knight(1, '♞', 7, 1);

            WhiteKnight1.SetToCell(Field, 7, 1);
            WhiteKnight1.SetFigureColor(Field, 7, 1);
            Knight WhiteKnight2 = new Knight(1, '♞', 7, 6);

            WhiteKnight2.SetToCell(Field, 7, 6);
            WhiteKnight2.SetFigureColor(Field, 7, 6);
            Knight BlackKnight1 = new Knight(0, '♞', 0, 1);

            BlackKnight1.SetToCell(Field, 0, 1);
            BlackKnight1.SetFigureColor(Field, 0, 1);
            Knight BlackKnight2 = new Knight(0, '♞', 0, 6);

            BlackKnight2.SetToCell(Field, 0, 6);
            BlackKnight2.SetFigureColor(Field, 0, 6);
            Rook WhiteRook1 = new Rook(1, '♜', 7, 0);

            WhiteRook1.SetToCell(Field, 7, 0);
            WhiteRook1.SetFigureColor(Field, 7, 0);
            Rook WhiteRook2 = new Rook(1, '♜', 7, 7);

            WhiteRook2.SetToCell(Field, 7, 7);
            WhiteRook2.SetFigureColor(Field, 7, 7);
            Rook BlackRook1 = new Rook(0, '♜', 0, 0);

            BlackRook1.SetToCell(Field, 0, 0);
            BlackRook1.SetFigureColor(Field, 0, 0);
            Rook BlackRook2 = new Rook(0, '♜', 0, 7);

            BlackRook2.SetToCell(Field, 0, 7);
            BlackRook2.SetFigureColor(Field, 0, 7);
            Pawn WhitePawn1 = new Pawn(1, '♟', 6, 0);

            WhitePawn1.SetToCell(Field, 6, 0);
            WhitePawn1.SetFigureColor(Field, 6, 0);
            Pawn WhitePawn2 = new Pawn(1, '♟', 6, 1);

            WhitePawn2.SetToCell(Field, 6, 1);
            WhitePawn2.SetFigureColor(Field, 6, 1);
            Pawn WhitePawn3 = new Pawn(1, '♟', 6, 2);

            WhitePawn3.SetToCell(Field, 6, 2);
            WhitePawn3.SetFigureColor(Field, 6, 2);
            Pawn WhitePawn4 = new Pawn(1, '♟', 6, 3);

            WhitePawn4.SetToCell(Field, 6, 3);
            WhitePawn4.SetFigureColor(Field, 6, 3);
            Pawn WhitePawn5 = new Pawn(1, '♟', 6, 4);

            WhitePawn5.SetToCell(Field, 6, 4);
            WhitePawn5.SetFigureColor(Field, 6, 4);
            Pawn WhitePawn6 = new Pawn(1, '♟', 6, 5);

            WhitePawn6.SetToCell(Field, 6, 5);
            WhitePawn6.SetFigureColor(Field, 6, 5);
            Pawn WhitePawn7 = new Pawn(1, '♟', 6, 6);

            WhitePawn7.SetToCell(Field, 6, 6);
            WhitePawn7.SetFigureColor(Field, 6, 6);
            Pawn WhitePawn8 = new Pawn(1, '♟', 6, 7);

            WhitePawn8.SetToCell(Field, 6, 7);
            WhitePawn8.SetFigureColor(Field, 6, 7);
            Pawn BlackPawn1 = new Pawn(0, '♟', 1, 0);

            BlackPawn1.SetToCell(Field, 1, 0);
            BlackPawn1.SetFigureColor(Field, 1, 0);
            Pawn BlackPawn2 = new Pawn(0, '♟', 1, 1);

            BlackPawn2.SetToCell(Field, 1, 1);
            Pawn BlackPawn3 = new Pawn(0, '♟', 1, 2);

            BlackPawn3.SetToCell(Field, 1, 2);
            Pawn BlackPawn4 = new Pawn(0, '♟', 1, 3);

            BlackPawn4.SetToCell(Field, 1, 3);
            Pawn BlackPawn5 = new Pawn(0, '♟', 1, 4);

            BlackPawn5.SetToCell(Field, 1, 4);
            Pawn BlackPawn6 = new Pawn(0, '♟', 1, 5);

            BlackPawn6.SetToCell(Field, 1, 5);
            Pawn BlackPawn7 = new Pawn(0, '♟', 1, 6);

            BlackPawn7.SetToCell(Field, 1, 6);
            Pawn BlackPawn8 = new Pawn(0, '♟', 1, 7);

            BlackPawn8.SetToCell(Field, 1, 7);
        }
        public void PerformsMove(Position origin, Position destination)
        {
            Piece captured = ExecuteMove(origin, destination);

            if (IsKingInCheck(CurrentPlayer))
            {
                UndoMove(origin, destination, captured);
                throw new ChessBoardException("You can't put yourself in check!");
            }

            Piece piece = Board.GetPiece(destination);

            // #SpecialMove Pawn Promotion
            if (piece is Pawn)
            {
                if ((piece.Color == Color.White && destination.Line == 0) || (piece.Color == Color.Black && destination.Line == 7))
                {
                    piece = Board.RemovePiece(destination);
                    _pieces.Remove(piece);
                    Console.WriteLine("\nPawn Promotion!");
                    Console.WriteLine("Queen(Q), Rook(R), Bishop(B),Horse (H)");
                    Console.Write("Choose a new piece (Q/R/B/H): ");
                    char  pieceType = char.Parse(Console.ReadLine());
                    Piece newPiece;
                    if (pieceType == 'Q' || pieceType == 'q')
                    {
                        newPiece = new Queen(Board, piece.Color);
                    }
                    else if (pieceType == 'R' || pieceType == 'r')
                    {
                        newPiece = new Rook(Board, piece.Color);
                    }
                    else if (pieceType == 'B' || pieceType == 'b')
                    {
                        newPiece = new Bishop(Board, piece.Color);
                    }
                    else if (pieceType == 'H' || pieceType == 'h')
                    {
                        newPiece = new Horse(Board, piece.Color);
                    }
                    else
                    {
                        newPiece = new Queen(Board, piece.Color);
                    }

                    Board.InsertPiece(newPiece, destination);
                    _pieces.Add(newPiece);
                }
            }

            if (IsKingInCheck(Adversary(CurrentPlayer)))
            {
                InCheck = true;
                if (IsCheckMate(Adversary(CurrentPlayer)))
                {
                    IsMatchEnded = true;
                    return;
                }
            }
            else
            {
                InCheck = false;
            }
            Turn++;
            ChangeCurrentPlayer();

            piece = Board.GetPiece(destination);

            // #Special Move En Passant
            if (piece is Pawn && (destination.Line == origin.Line - 2 || destination.Line == origin.Line + 2) && piece.MovimentsQuantity == 1)
            {
                EnPassantVulnerable = piece;
            }
            else
            {
                EnPassantVulnerable = null;
            }
        }
Example #30
0
        public override void Move(Square source, Square dest, bool silentMode = false)
        {
            int source_col = GetColumnCoordinate(source);
            int source_row = GetRowCoordinate(source);
            int dest_col   = GetColumnCoordinate(dest);
            int dest_row   = GetRowCoordinate(dest);

            // Prüft auf gültigen Zug: VERTIKAL oder HORIZONTAL oder DIAGONAL
            // bei einer Reichweite von einem Feld
            if (IsMoveValid(dest))
            {
                if (!IsMoveBlocked(dest))
                {
                    if (this.game.board.GetChessmanAtSquare(dest) == null)
                    {
                        // Kleine Rochade
                        if (source_col - dest_col == -2 && source_row == dest_row)
                        {
                            Rook   rook        = this.game.board.GetRook("H" + this.Orig_position.Substring(1, 1));
                            Square rook_source = this.game.board.GetSquare(rook.Orig_position);

                            string last_pos      = this.Current_position;
                            string rook_last_pos = rook.Current_position;
                            this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row);
                            rook.Current_position = GetSquarenameFromCoordinates(dest_col - 1, dest_row);

                            if (!this.game.board.IsKingInCheck(this.Color))
                            {
                                if (!silentMode)
                                {
                                    source.Content             = "";
                                    rook_source.Content        = "";
                                    this.isMoved               = true;
                                    this.HasPerformedCastling  = true;
                                    rook.IsMoved               = true;
                                    this.game.board.lastAction = this.Desc + " FÜHRT DIE KLEINE ROCHADE"
                                                                 + " VON " + source.Name
                                                                 + " AUF " + dest.Name
                                                                 + " AUS";

                                    // Neuer Logeintrag
                                    LogEntry log = new LogEntry(this, last_pos, this.Current_position);
                                    log.PerformedCastlingKingsSide = true;
                                    log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color);
                                    this.game.logger.Add(log);
                                    this.game.View.movesList.Items.Add(log);
                                }
                            }
                            // Zug Rückgängig machen, wenn sich nach dem Zug
                            // der König im Schach befinden würde
                            else
                            {
                                this.Current_position = last_pos;
                                rook.Current_position = rook_last_pos;
                                throw new PlacedInCheckException();
                            }
                        }
                        // Große Rochade
                        else if (source_col - dest_col == 2 && source_row == dest_row)
                        {
                            Rook   rook        = this.game.board.GetRook("A" + this.Orig_position.Substring(1, 1));
                            Square rook_source = this.game.board.GetSquare(rook.Orig_position);

                            string last_pos      = this.Current_position;
                            string rook_last_pos = rook.Current_position;
                            this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row);
                            rook.Current_position = GetSquarenameFromCoordinates(dest_col + 1, dest_row);

                            if (!this.game.board.IsKingInCheck(this.Color))
                            {
                                if (!silentMode)
                                {
                                    source.Content             = "";
                                    rook_source.Content        = "";
                                    this.isMoved               = true;
                                    this.HasPerformedCastling  = true;
                                    rook.IsMoved               = true;
                                    this.game.board.lastAction = this.Desc + " FÜHRT DIE GROßE ROCHADE"
                                                                 + " VON " + source.Name
                                                                 + " AUF " + dest.Name
                                                                 + " AUS";

                                    // Neuer Logeintrag
                                    LogEntry log = new LogEntry(this, last_pos, this.Current_position);
                                    log.PerfomedCastlingQueensSide = true;
                                    log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color);
                                    this.game.logger.Add(log);
                                    this.game.View.movesList.Items.Add(log);
                                }
                            }
                            // Zug Rückgängig machen, wenn sich nach dem Zug
                            // der König im Schach befinden würde
                            else
                            {
                                this.Current_position = last_pos;
                                rook.Current_position = rook_last_pos;
                                throw new PlacedInCheckException();
                            }
                        }
                        // Einfacher Zug
                        else
                        {
                            string last_pos = this.Current_position;
                            this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row);

                            if (!this.game.board.IsKingInCheck(this.Color))
                            {
                                if (!silentMode)
                                {
                                    source.Content             = "";
                                    this.isMoved               = true;
                                    this.game.board.lastAction = "BEWEGE " + this.Desc
                                                                 + " VON " + source.Name
                                                                 + " AUF " + dest.Name;

                                    // Neuer Logeintrag
                                    LogEntry log = new LogEntry(this, last_pos, this.Current_position);
                                    log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color);
                                    this.game.logger.Add(log);
                                    this.game.View.movesList.Items.Add(log);
                                }
                            }
                            // Zug Rückgängig machen, wenn sich nach dem Zug
                            // der König im Schach befinden würde
                            else
                            {
                                this.Current_position = last_pos;
                                throw new PlacedInCheckException();
                            }
                        }
                    }
                    else
                    {
                        Chessman chessmanAtDest = this.game.board.GetChessmanAtSquare(dest);
                        // Angriffszug
                        if (chessmanAtDest.Color != this.Color)
                        {
                            string last_pos = this.Current_position;
                            this.Current_position = GetSquarenameFromCoordinates(dest_col, dest_row);
                            this.game.board.chessman.Remove(chessmanAtDest);

                            if (!this.game.board.IsKingInCheck(this.Color))
                            {
                                if (!silentMode)
                                {
                                    source.Content             = "";
                                    this.isMoved               = true;
                                    this.game.board.lastAction = this.Desc + " SCHLÄGT " + chessmanAtDest.Desc + " AUF " + dest.Name;

                                    // Neuer Logeintrag
                                    LogEntry log = new LogEntry(this, last_pos, this.Current_position);
                                    log.OpponentMan   = chessmanAtDest;
                                    log.PlacedInCheck = this.game.board.IsKingInCheck(this.game.GetWaitingPlayer().Color);
                                    this.game.logger.Add(log);
                                    this.game.View.movesList.Items.Add(log);
                                }
                            }
                            // Zug Rückgängig machen, wenn sich nach dem Zug
                            // der König im Schach befinden würde
                            else
                            {
                                this.Current_position = last_pos;
                                this.game.board.chessman.Add(chessmanAtDest);
                                throw new PlacedInCheckException();
                            }
                        }
                        else
                        {
                            throw new BlockedMoveException();
                        }
                    }
                }
                else
                {
                    throw new BlockedMoveException();
                }
            }
            else
            {
                throw new InvalidMoveException();
            }
        }
Example #31
0
        public void placeWhiteFigures(bool isStandardChess)
        {
            Figure[] pawns            = new Figure[8];
            char     currentChar      = 'A';
            char     charPositionPawn = 'A';

            if (isStandardChess)
            {
                for (int i = 0; i < 8; i++)
                {
                    pawns[i] = new Pawn(charPositionPawn, 7, true);
                    charPositionPawn++;


                    if ((currentChar == 'A') || (currentChar == 'H'))
                    {
                        otherFigures[i] = new Rook(currentChar, 8, true);
                    }
                    else if ((currentChar == 'B') || (currentChar == 'G'))
                    {
                        otherFigures[i] = new Knight(currentChar, 8, true);
                    }
                    else if ((currentChar == 'C') || (currentChar == 'F'))
                    {
                        otherFigures[i] = new Bishop(currentChar, 8, true);
                    }
                    else if (currentChar == 'E')
                    {
                        otherFigures[i] = new King(currentChar, 8, true);
                    }
                    else
                    {
                        otherFigures[i] = new Queen(currentChar, 8, true);
                    }

                    currentChar++;
                }
                for (int i = 0; i < 8; i++)
                {
                    placeFigure(pawns[i]);
                    placeFigure(otherFigures[i]);
                }
            }
            else if (!isStandardChess)
            {
                for (int i = 0; i < 8; i++)
                {
                    pawns[i] = new Pawn(charPositionPawn, 7, true);
                    charPositionPawn++;

                    currentChar++;
                }
                do
                {
                    char[] piecePlacement = boardSpaces.OrderBy(x => random.Next()).ToArray();
                    otherFigures[0] = new Bishop(piecePlacement[0], 8, true);
                    otherFigures[1] = new Bishop(piecePlacement[1], 8, true);
                    otherFigures[2] = new Rook(piecePlacement[2], 8, true);
                    otherFigures[3] = new Rook(piecePlacement[3], 8, true);
                    otherFigures[4] = new Knight(piecePlacement[4], 8, true);
                    otherFigures[5] = new Knight(piecePlacement[5], 8, true);
                    otherFigures[6] = new Queen(piecePlacement[6], 8, true);
                    otherFigures[7] = new King(piecePlacement[7], 8, true);
                    if (!(otherFigures[0].Xpositon % 2 == otherFigures[1].Xpositon % 2) &&
                        (((otherFigures[2].Xpositon > otherFigures[7].Xpositon) && (otherFigures[3].Xpositon < otherFigures[7].Xpositon)) ||
                         ((otherFigures[2].Xpositon < otherFigures[7].Xpositon) && (otherFigures[3].Xpositon > otherFigures[7].Xpositon))))
                    {
                        valid = true;
                    }
                } while (!valid);
                for (int i = 0; i < 8; i++)
                {
                    placeFigure(pawns[i]);
                    placeFigure(otherFigures[i]);
                }
                placeBlackFigures(isStandardChess);
            }
        }
Example #32
0
        public void Move(Figure f, char x, int y)

        {
            var  chessBoxStart = this.getChessBoxByCoordinates(f.Xpositon, f.Ypositon);
            var  chessBoxEnd   = this.getChessBoxByCoordinates(x, y);
            bool isFigureWhite = f.isWhite;

            if (f.getFigureType().Equals("Pawn"))
            {
                this.MovePawn(f, x, y);
            }
            else if (f.getFigureType().Equals("King") && chessBoxEnd.isFigureOn() && chessBoxEnd.Figure.getFigureType().Equals("Rook") && chessBoxStart.Figure.isWhite == chessBoxEnd.Figure.isWhite)
            {//checking for Rocade
                King king = (King)f;
                Rook rook = (Rook)chessBoxEnd.Figure;

                if (PathBetweenBoxesFree(chessBoxStart, chessBoxEnd))
                {
                    if ((!king.isMoved) && (!rook.isMoved))
                    {
                        if (rook.Xpositon == 'A')
                        {
                            chessBoxEnd.Figure.Move('D', chessBoxEnd.Ycoord);
                            this.getChessBoxByCoordinates('D', chessBoxEnd.Ycoord).Figure = chessBoxEnd.Figure;
                            chessBoxEnd.deleteFigure();

                            chessBoxStart.Figure.Move('C', chessBoxStart.Ycoord);
                            this.getChessBoxByCoordinates('C', chessBoxStart.Ycoord).Figure = chessBoxStart.Figure;
                            chessBoxStart.deleteFigure();

                            if (isInChess(f.isWhite))
                            {
                                king.BackToLastPosition();
                                rook.BackToLastPosition();
                                chessBoxEnd.Figure   = this.getChessBoxByCoordinates('D', chessBoxEnd.Ycoord).Figure;
                                chessBoxStart.Figure = this.getChessBoxByCoordinates('C', chessBoxStart.Ycoord).Figure;
                                this.getChessBoxByCoordinates('D', chessBoxEnd.Ycoord).deleteFigure();
                                this.getChessBoxByCoordinates('C', chessBoxStart.Ycoord).deleteFigure();
                                throw new KingInChessExeption("You cannot move here! You will be in chess!");
                            }
                        }
                        else
                        {
                            chessBoxEnd.Figure.Move('F', chessBoxEnd.Ycoord);
                            this.getChessBoxByCoordinates('F', chessBoxEnd.Ycoord).Figure = chessBoxEnd.Figure;
                            chessBoxEnd.deleteFigure();

                            chessBoxStart.Figure.Move('G', chessBoxStart.Ycoord);
                            this.getChessBoxByCoordinates('G', chessBoxStart.Ycoord).Figure = chessBoxStart.Figure;
                            chessBoxStart.deleteFigure();

                            if (isInChess(f.isWhite))
                            {
                                king.BackToLastPosition();
                                rook.BackToLastPosition();
                                chessBoxEnd.Figure   = this.getChessBoxByCoordinates('F', chessBoxEnd.Ycoord).Figure;
                                chessBoxStart.Figure = this.getChessBoxByCoordinates('G', chessBoxStart.Ycoord).Figure;
                                this.getChessBoxByCoordinates('F', chessBoxEnd.Ycoord).deleteFigure();
                                this.getChessBoxByCoordinates('G', chessBoxStart.Ycoord).deleteFigure();
                                throw new KingInChessExeption("You cannot move here! You will be in chess!");
                            }
                        }
                    }
                    else
                    {
                        throw new RocadeNotPossibleExeption("Rocade not possible!The figures has been moved");
                    }
                }
                else
                {
                    throw new RocadeNotPossibleExeption("Rocade not possible!There is a figure on the way!");
                }
            }
            else
            {
                if (PathBetweenBoxesFree(chessBoxStart, chessBoxEnd))
                {
                    if (chessBoxEnd.isFigureOn())
                    {
                        if (chessBoxStart.Figure.isWhite != chessBoxEnd.Figure.isWhite)
                        {
                            Figure figureToDestroy = chessBoxEnd.Figure;
                            f.Move(x, y);
                            chessBoxEnd.Figure.DestroyFigure();
                            chessBoxStart.Figure = null;
                            chessBoxEnd.Figure   = f;
                            if (isInChess(f.isWhite))
                            {
                                chessBoxStart.Figure = f;
                                f.BackToLastPosition();
                                figureToDestroy.BackToLastPosition();
                                chessBoxEnd.Figure = figureToDestroy;
                                throw new KingInChessExeption("You cannot move here! You will be in chess!");
                            }
                        }
                        else
                        {
                            throw new InvalidAttackExeption("Invalid movement! You cannot attack your figure!");
                        }
                    }
                    else
                    {
                        f.Move(x, y);
                        chessBoxStart.Figure = null;
                        chessBoxEnd.Figure   = f;
                        if (isInChess(f.isWhite))
                        {
                            f.BackToLastPosition();
                            chessBoxStart.Figure = f;
                            chessBoxEnd.Figure   = null;
                            throw new KingInChessExeption("You cannot move here! You will be in chess!");
                        }
                    }
                }
                else
                {
                    throw new PathBetweenBoxesNotFreeExeption("The path between the boxes is not free");
                }
            }

            ///if Move coordinates invalid figure.move -argument exeption
        }
Example #33
0
        public void promotePawn(ContentManager c)
        {
            for (int i = 0; i < 8; i++)
            {
                if (Pieces[i] != null)
                {
                    if (Pieces[i].Position.RowInBoard == 7 && Pieces[i] is Pawn)
                    {
                        PromotionForm p = new PromotionForm();
                        drawPiecesInForm(false);
                        Game1.pf.ShowDialog();
                        if (Game1.pf.isClicked)
                        {
                            switch (Game1.pf.choice)
                            {
                            case PromotionChoices.Queen:
                                Game1.pf.Close();
                                Pieces[i] = new Queen(false, Pieces[i].Position);
                                Pieces[i].Position.PieceInside = Pieces[i];
                                Pieces[i].loadTexture(c);
                                break;

                            case PromotionChoices.Rook:
                                Game1.pf.Close();
                                Pieces[i] = new Rook(false, Pieces[i].Position);
                                Pieces[i].Position.PieceInside = Pieces[i];
                                Pieces[i].loadTexture(c);
                                break;

                            case PromotionChoices.Bishop:
                                Game1.pf.Close();
                                Pieces[i] = new Bishop(false, Pieces[i].Position);
                                Pieces[i].Position.PieceInside = Pieces[i];
                                Pieces[i].loadTexture(c);
                                break;

                            case PromotionChoices.Knight:
                                Game1.pf.Close();
                                Pieces[i] = new Knight(false, Pieces[i].Position);
                                Pieces[i].Position.PieceInside = Pieces[i];
                                Pieces[i].loadTexture(c);
                                break;
                            }
                        }

                        /*Pieces[i] = new Queen(false, Pieces[i].Position);
                         * Pieces[i].Position.PieceInside = Pieces[i];
                         * Pieces[i].loadTexture(c);*/
                    }
                }
                if (Pieces[i + 8] != null)
                {
                    if (Pieces[i + 8].Position.RowInBoard == 0 && Pieces[i + 8] is Pawn)
                    {
                        PromotionForm p = new PromotionForm();
                        drawPiecesInForm(true);
                        Game1.pf.ShowDialog();
                        if (Game1.pf.isClicked)
                        {
                            switch (Game1.pf.choice)
                            {
                            case PromotionChoices.Queen:
                                Game1.pf.Close();
                                Pieces[i + 8] = new Queen(true, Pieces[i + 8].Position);
                                Pieces[i + 8].Position.PieceInside = Pieces[i + 8];
                                Pieces[i + 8].loadTexture(c);
                                break;

                            case PromotionChoices.Rook:
                                Game1.pf.Close();
                                Pieces[i + 8] = new Rook(true, Pieces[i + 8].Position);
                                Pieces[i + 8].Position.PieceInside = Pieces[i + 8];
                                Pieces[i + 8].loadTexture(c);
                                break;

                            case PromotionChoices.Bishop:
                                Game1.pf.Close();
                                Pieces[i + 8] = new Bishop(true, Pieces[i + 8].Position);
                                Pieces[i + 8].Position.PieceInside = Pieces[i + 8];
                                Pieces[i + 8].loadTexture(c);
                                break;

                            case PromotionChoices.Knight:
                                Game1.pf.Close();
                                Pieces[i + 8] = new Knight(true, Pieces[i + 8].Position);
                                Pieces[i + 8].Position.PieceInside = Pieces[i + 8];
                                Pieces[i + 8].loadTexture(c);
                                break;
                            }
                        }

                        /*Pieces[ i + 8] = new Queen(true, Pieces[ i + 8].Position);
                         * Pieces[i + 8].Position.PieceInside = Pieces[i + 8];
                         * Pieces[ i + 8].loadTexture(c);*/
                    }
                }
            }
        }
Example #34
0
File: Board.cs Project: jssmy/Chess
        private void Initialize()
        {
            this.matrix = new String[8, 8];
            int       count = 1;
            UnitBoard ub;

            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (count % 2 == 0)
                    {
                        ub = new UnitBoard(red.Width * col, red.Height * row, red);
                    }
                    else
                    {
                        ub = new UnitBoard(white.Width * col, white.Height * row, white);
                    }
                    this.matrix[row, col] = "*";
                    unitBoards.Add(ub);
                    count++;
                }
                count++;
            }
            //

            //horse
            this.matrix[0, 1] = "KN1";
            this.matrix[0, 6] = "kN1";
            hors    = new Horse(red.Width * 1, red.Height * 0, Properties.Resources.WhiteKnight);
            hors.ID = "KN11";
            pieces.Add(hors);
            hors    = new Horse(red.Width * 6, red.Height * 0, Properties.Resources.WhiteKnight);
            hors.ID = "KN12";
            pieces.Add(hors);
            //rook
            this.matrix[0, 0] = "R1";
            this.matrix[0, 7] = "R1";
            rook    = new Rook(red.Width * 0, red.Height * 0, Properties.Resources.WhiteRook);
            rook.ID = "R11";
            pieces.Add(rook);
            rook    = new Rook(red.Width * 7, red.Height * 0, Properties.Resources.WhiteRook);
            rook.ID = "R12";
            pieces.Add(rook);
            //alfil
            this.matrix[0, 2] = "B1";
            this.matrix[0, 5] = "B1";
            bip    = new Bishop(red.Width * 2, red.Height * 0, Properties.Resources.WhiteBishop);
            bip.ID = "B11";
            pieces.Add(bip);
            bip    = new Bishop(red.Width * 5, red.Height * 0, Properties.Resources.WhiteBishop);
            bip.ID = "B12";
            pieces.Add(bip);
            //king
            this.matrix[0, 3] = "K1";
            king    = new King(red.Width * 3, red.Height * 0, Properties.Resources.WhiteKing);
            king.ID = "K11";
            pieces.Add(king);
            this.matrix[0, 4] = "Q1";
            queen             = new Queen(red.Width * 4, red.Height * 0, Properties.Resources.WhiteQueen);
            queen.ID          = "Q11";
            pieces.Add(queen);



            for (int i = 0; i < 8; i++)
            {
                this.matrix[1, i] = "P1";
                paw    = new Pawn(red.Width * i, red.Height * 1, Properties.Resources.WhitePawn, 1);
                paw.ID = "P1" + (i + 1);
                pieces.Add(paw);
            }
            // second player

            //horse
            this.matrix[7, 1] = "KN2";
            this.matrix[7, 6] = "KN2";
            hors    = new Horse(red.Width * 1, red.Height * 7, Properties.Resources.BlackKnight);
            hors.ID = "KN21";
            pieces.Add(hors);
            hors    = new Horse(red.Width * 6, red.Height * 7, Properties.Resources.BlackKnight);
            hors.ID = "KN22";
            pieces.Add(hors);
            //rook
            this.matrix[7, 0] = "R2";
            this.matrix[7, 7] = "R2";
            rook    = new Rook(red.Width * 0, red.Height * 7, Properties.Resources.BlackRook);
            rook.ID = "R21";
            pieces.Add(rook);
            rook    = new Rook(red.Width * 7, red.Height * 7, Properties.Resources.BlackRook);
            rook.ID = "R22";
            pieces.Add(rook);
            //alfil
            this.matrix[7, 2] = "B2";
            this.matrix[7, 5] = "B2";
            bip    = new Bishop(red.Width * 2, red.Height * 7, Properties.Resources.BlackBishop);
            bip.ID = "B21";
            pieces.Add(bip);
            bip    = new Bishop(red.Width * 5, red.Height * 7, Properties.Resources.BlackBishop);
            bip.ID = "B22";
            pieces.Add(bip);
            //king
            this.matrix[7, 3] = "K2";
            king    = new King(red.Width * 3, red.Height * 7, Properties.Resources.BlackKing);
            king.ID = "K21";
            pieces.Add(king);
            this.matrix[7, 4] = "Q2";
            queen             = new Queen(red.Width * 4, red.Height * 7, Properties.Resources.BlackQueen);
            queen.ID          = "Q21";
            pieces.Add(queen);



            for (int i = 0; i < 8; i++)
            {
                this.matrix[6, i] = "P2";
                paw    = new Pawn(red.Width * i, red.Height * 6, Properties.Resources.BlackPawn, 2);
                paw.ID = "P2" + (i + 1);
                pieces.Add(paw);
            }
        }
Example #35
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();
            }
        }