Ejemplo n.º 1
0
        public static Level GetSubsetLevel(Level level, bool withSokoban, int boxes)
        {
            // Validate the desired numberes of boxes.
            if (boxes > level.Boxes)
            {
                throw new InvalidOperationException("too many boxes");
            }

            // Remove all the undesired occupants.
            int removeCount = level.Boxes - boxes;
            Array2D<Cell> newData = new Array2D<Cell>(level.Data);
            int removed = 0;
            foreach (Coordinate2D coord in level.InsideCoordinates)
            {
                // Remove the undesired boxes.
                if (removed < removeCount && level.IsBox(coord))
                {
                    newData[coord] &= ~Cell.Box;
                    removed++;
                }
                if (!withSokoban)
                {
                    newData[coord] &= ~Cell.Sokoban;
                }
            }

            return new Level(newData);
        }