<jupyter_start><jupyter_text>SpawnersSpawners allow you to define an area where certain Scene Elements will appear randomly.This can be interesting in foraging scenario, where agents move around to collect rewards.<jupyter_code>from simple_playgrounds.playgrounds.layouts import SingleRoom
from simple_playgrounds.engine import Engine

%matplotlib inline
import matplotlib.pyplot as plt


def plt_image(img):
    plt.axis('off')
    plt.imshow(img)
    plt.show()
    
my_playground = SingleRoom(size=(200, 200))

# we use the option screen=True to use a keyboard controlled agent later on.
engine = Engine(time_limit=1000, playground=my_playground, screen=False)

plt_image(engine.generate_playground_image(plt_mode=True))<jupyter_output>pygame 2.0.1 (SDL 2.0.14, Python 3.7.5)
Hello from the pygame community. https://www.pygame.org/contribute.html<jupyter_text>Now that we have an empty playground, lets create a spawner that produces candies in the top-left area of the playground.<jupyter_code>from simple_playgrounds.elements.collection.contact import Candy
from simple_playgrounds.elements.spawner import Spawner
from simple_playgrounds.common.position_utils import CoordinateSampler

area = CoordinateSampler(center=(50, 150), area_shape='circle', radius=30)
spawner = Spawner(probability=0.1, max_elements_in_playground=10, element_produced=Candy, production_area=area)
my_playground.add_spawner(spawner)<jupyter_output><empty_output><jupyter_text>Now we can let the playground run for some time, and see if the spawner produces candies.Run the following cell multiple times.<jupyter_code>engine.run(steps=10)

plt_image(engine.generate_playground_image(plt_mode=True))
engine.terminate()<jupyter_output><empty_output><jupyter_text>Finally, we can add an agent controlled by a keyboard.We see that the Candies are replaced little by little.<jupyter_code>from simple_playgrounds.agents.parts.controllers import Keyboard
from simple_playgrounds.agents.agents import BaseAgent

my_playground = SingleRoom(size=(200, 200))
engine = Engine(time_limit=10000, playground=my_playground, screen=True)

area = CoordinateSampler(center=(100, 100), area_shape='circle', radius=60)
spawner = Spawner(probability=0.05, production_limit=100, max_elements_in_playground=10, element_produced=Candy, production_area=area)
my_playground.add_spawner(spawner)

my_agent = BaseAgent(controller=Keyboard(), interactive=True)
my_playground.add_agent(my_agent)

engine.run(update_screen=True)
engine.terminate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08633663366336633, 'fraction_numerical': 0.023762376237623763, 'mean_word_length': 7.957446808510638, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '91978', 'license': 'MIT', 'n_tokens_mistral': 851, 'n_tokens_neox': 788, 'n_words': 192, 'path': 'tutorials/jupyter/05_Spawners.ipynb', 'repo_name': 'embaba/simple-playgrounds', 'size': '2525'}