Beispiel #1
0
        // --- Constructor ---
        public Board()
        {
            // Create squares
            for (uint y = 0; y < BOARD_SIZE_Y; y++)
            {
                for (uint x = 0; x < BOARD_SIZE_X; x++)
                {
                    squares[x, y] = new Square(x, y, reward[x,y]);
                }
            }

            // Create white pieces
            squares[0, 0].setPiece(new Rook(0, 0, COLOUR_WHITE));
            squares[1, 0].setPiece(new Knight(1, 0, COLOUR_WHITE));
            squares[2, 0].setPiece(new Bishop(2, 0, COLOUR_WHITE));
            squares[3, 0].setPiece(new Queen(3, 0, COLOUR_WHITE));
            squares[4, 0].setPiece(new King(4, 0, COLOUR_WHITE));
            squares[5, 0].setPiece(new Bishop(5, 0, COLOUR_WHITE));
            squares[6, 0].setPiece(new Knight(6, 0, COLOUR_WHITE));
            squares[7, 0].setPiece(new Rook(7, 0, COLOUR_WHITE));
            for (uint x = 0; x < BOARD_SIZE_X; x++)
            {
                squares[x, 1].setPiece(new Pawn(x, 0, COLOUR_WHITE));
            }

            // Create black pieces
            squares[0, BOARD_SIZE_Y - 1].setPiece(new Rook(0, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[1, BOARD_SIZE_Y - 1].setPiece(new Knight(1, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[2, BOARD_SIZE_Y - 1].setPiece(new Bishop(2, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[3, BOARD_SIZE_Y - 1].setPiece(new Queen(3, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[4, BOARD_SIZE_Y - 1].setPiece(new King(4, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[5, BOARD_SIZE_Y - 1].setPiece(new Bishop(5, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[6, BOARD_SIZE_Y - 1].setPiece(new Knight(6, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            squares[7, BOARD_SIZE_Y - 1].setPiece(new Rook(7, BOARD_SIZE_Y - 1, COLOUR_BLACK));
            for (uint x = 0; x < BOARD_SIZE_X; x++)
            {
                squares[x, BOARD_SIZE_Y - 2].setPiece(new Pawn(x, BOARD_SIZE_Y - 2, COLOUR_BLACK));
            }

            // Add cover
            QueryFunc qf = getSquareAt;
            foreach (Square s in squares)
            {
                Piece p = s.getPiece();

                if (p != null)
                {
                    List<Tuple<uint, uint>> cover = p.getPossibleMoves(qf);
                    foreach (Tuple<uint, uint> t in cover)
                    {
                        if (p.getColour() == COLOUR_WHITE)
                        {
                            squares[t.Item1, t.Item2].addWhiteCover();
                        }
                        else
                        {
                            squares[t.Item1, t.Item2].addBlackCover();
                        }

                    }
                }
            }
        }