Example #1
0
        public Board()
        {
            squares = new ChessPiece[8, 8];

            for(int x = 0; x < 8; x++)
            {
                squares[x, 1] = new Pawn(TeamColor.BLACK);
                squares[x, 6] = new Pawn(TeamColor.WHITE);
            }

            squares[0, 0] = new Rook(TeamColor.BLACK);
            squares[7, 0] = new Rook(TeamColor.BLACK);
            squares[0, 7] = new Rook(TeamColor.WHITE);
            squares[7, 7] = new Rook(TeamColor.WHITE);

            squares[1, 0] = new Knight(TeamColor.BLACK);
            squares[6, 0] = new Knight(TeamColor.BLACK);
            squares[1, 7] = new Knight(TeamColor.WHITE);
            squares[6, 7] = new Knight(TeamColor.WHITE);

            squares[2, 0] = new Bishop(TeamColor.BLACK);
            squares[5, 0] = new Bishop(TeamColor.BLACK);
            squares[2, 7] = new Bishop(TeamColor.WHITE);
            squares[5, 7] = new Bishop(TeamColor.WHITE);

            squares[3, 0] = new Queen(TeamColor.BLACK);
            squares[4, 0] = new King(TeamColor.BLACK);
            squares[3, 7] = new Queen(TeamColor.WHITE);
            squares[4, 7] = new King(TeamColor.WHITE);
        }
Example #2
0
        public Board(Board copy)
        {
            // Copy constructor
            // For use alongside Check()
            squares = new ChessPiece[8, 8];
            String temp;

            for(int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if(copy.squares[x, y] != null)
                    {
                        temp = copy.squares[x, y].GetType().ToString();

                        switch(temp)
                        {
                            case "Backend.Pawn":
                                squares[x,y] = new Pawn(copy.squares[x,y].Color);
                                break;
                            case "Backend.Rook":
                                squares[x, y] = new Rook(copy.squares[x, y].Color);
                                break;
                            case "Backend.Knight":
                                squares[x, y] = new Knight(copy.squares[x, y].Color);
                                break;
                            case "Backend.Bishop":
                                squares[x, y] = new Bishop(copy.squares[x, y].Color);
                                break;
                            case "Backend.Queen":
                                squares[x, y] = new Queen(copy.squares[x, y].Color);
                                break;
                            case "Backend.King":
                                squares[x, y] = new King(copy.squares[x, y].Color);
                                break;
                            default:
                                throw new ArgumentException();
                        }
                    }
                }
            }
        }