Пример #1
0
            self.move_towards(obj=self.target, n=10)


class Collectible(BaseCollectible):
    def on_trigger(self, obj):
        obj.score += 1
        obj.target = None


#==================================================================================================
# SIMULATION
#==================================================================================================

# Setup agents
agent = Agent(1, 1, color=RED)
agent2 = Agent(75, 25, color=BLUE)

# Setup collectibles as random spawner
collectible_spawner = lambda x, y: Collectible(x, y, color=WHITE)

# Setup environment
env = GridEnvironment(80, 30, 10, objects=[agent, agent2])
env.spawn(collectible_spawner, 100)
env.render()

# Prepare simulation
sim = Simulation(env, fps=30, name="CollectiblesMultiplayer")

if __name__ == "__main__":
    sim.run_episode(n_steps=1000, save=True)
Пример #2
0
class Agent(BaseGridAgent):
    def step(self):
        self.wander()


obstacle = BaseObstacle(10, 0, 1, 7, color=BLUE)
agent_spawner = lambda x, y: Agent(x, y, color=GREEN)
coll_spawner = lambda x, y: BaseCollectible(
    x, y, color=WHITE, circle=True, radius=0.3)
agent1 = agent_spawner(1, 1)

# Setup grid
BOX_SIZE = 20
WIDTH = 20
HEIGHT = 10

env = GridEnvironment(WIDTH,
                      HEIGHT,
                      BOX_SIZE,
                      show_grid=True,
                      objects=[obstacle, agent1])
env.spawn(coll_spawner, 120)
env.render()

# Prepare simulation
sim = Simulation(env, fps=30, name="CollectiblesObstacle")

if __name__ == "__main__":
    sim.run_episode(n_steps=200, save=True)
Пример #3
0

#==================================================================================================
# SIMULATION
#==================================================================================================

# Prepare layer
layer = BaseLayer(
    img_filepath="examples/assets/layers/Layer_1590257407_boxsize=20.png",
    img_transparency=(255, 255, 255))

# Prepare agents
agents = [
    Agent(0, 0, color=RED),
    WanderAgent(17, 7, color=BLUE, curiosity=20),
    RandomAgent(10, 11, color=GREEN),
]

# Prepare environment
env = GridEnvironment(cell_size=20,
                      show_grid=True,
                      background_color=WHITE,
                      grid_color=(200, 200, 200),
                      objects=agents + [layer])

# Prepare simulation and run it
sim = Simulation(env, fps=30, name="LayerPathfindingMouse")

if __name__ == "__main__":
    sim.run_episode(n_steps=200, save=True)
Пример #4
0
CONTACT_RISK = 6
RECOVERY_DURATION_RANGE = [20, 50]

spawner = lambda state: lambda x, y: SIRAgent(x,
                                              y,
                                              state=state,
                                              contact_risk=CONTACT_RISK,
                                              recovery_duration_range=
                                              RECOVERY_DURATION_RANGE)

# Setup grid
CELL_SIZE = 20
WIDTH = 40
HEIGHT = 30
env = GridEnvironment(cell_size=CELL_SIZE,
                      width=WIDTH,
                      height=HEIGHT,
                      show_grid=False,
                      callbacks_step=[callback_logger])
env.spawn(spawner("S"), 100)
env.spawn(spawner("I"), 1)

# Prepare simulation and run it
sim = Simulation(env, fps=10, name="SimpleSIR")

if __name__ == "__main__":
    sim.run_episode(n_steps=200, save=False)

    logger.df[["S", "I", "R"]].plot()
    plt.show()
from westworld.colors import *

obstacle = BaseObstacle(10, 0, 1, 7, color=RED)
agent_spawner = lambda x, y: CollectibleFinderAgent(
    x, y, color=(0, 200, 255), search_radius=3, img_asset="blob")
coll_spawner = lambda x, y: BaseCollectible(
    x,
    y,
    color=(220, 150, 50),
    img_filepath="examples/assets/sprites/sprite_lemon.png")

# Setup grid
BOX_SIZE = 40
WIDTH = 20
HEIGHT = 10
env = GridEnvironment(WIDTH,
                      HEIGHT,
                      BOX_SIZE,
                      show_grid=True,
                      objects=[obstacle])
env.spawn(agent_spawner, 1)
env.spawn(coll_spawner, 20)
env.render()
env.get_img()

# Prepare simulation
sim = Simulation(env, fps=10, name="CollectiblesFinder")

if __name__ == "__main__":
    sim.run_episode(n_steps=1000, save=False)
Пример #6
0
spawner = lambda state: lambda x, y: SIRQuarantineAgent(
    x,
    y,
    state=state,
    contact_risk=CONTACT_RISK,
    recovery_duration_range=RECOVERY_DURATION_RANGE)

# Prepare layer
layer = BaseLayer(
    img_filepath="examples/assets/layers/Layer_1590257407_boxsize=20.png",
    img_transparency=(255, 255, 255))

# Prepare environment
env = GridEnvironment(cell_size=10,
                      show_grid=True,
                      background_color=WHITE,
                      grid_color=(200, 200, 200),
                      callbacks_step=[callback_logger],
                      objects=[layer])

env.spawn(spawner("S"), 100)
env.spawn(spawner("I"), 10)

# Prepare simulation and run it
sim = Simulation(env, fps=25, name="RoomSIR")

if __name__ == "__main__":
    sim.run_episode(n_steps=500, save=True, save_format="video")

    logger.df[["S", "I", "R"]].plot()
    plt.show()
Пример #7
0
        x, y = self.target
        self.move_towards(x=x, y=y, n=15)


class PathfindingClickSimulation(Simulation):
    def on_event(self, event):

        if self.event_is_click(event):

            x, y = self.get_mouse_pos()
            obstacle = obstacle_spawner(x, y)
            env.add_object(obstacle)

        if self.event_is_rightclick(event):

            new_target = self.get_mouse_pos()

            for agent in self.env.objects:
                agent.target = new_target


agent_spawner = lambda x, y: Agent(x, y)
obstacle_spawner = lambda x, y: BaseObstacle(x, y, 5, 5, color=GREEN)

# Setup grid
env = GridEnvironment(200, 100, 4)
env.spawn(agent_spawner, 100)

# Setup simulation
sim = PathfindingClickSimulation(env, fps=25)
sim.run_episode(n_steps=500, save=True)
Пример #8
0
from westworld.agents import BaseGridAgent
from westworld.objects import BaseObstacle, BaseTrigger, BaseCollectible
from westworld.simulation import Simulation
from westworld.colors import *

BOX_SIZE = 10
WIDTH = 50
HEIGHT = 30
N_ZONES = 10
TARGETS = list(
    zip(np.random.randint(0, WIDTH, N_ZONES),
        np.random.randint(0, HEIGHT, N_ZONES)))


class Agent(BaseGridAgent):
    def init(self):
        self.target = random.choice(TARGETS)

    def step(self):
        self.move_towards(*self.target, n=20)


agent_spawner = lambda x, y: Agent(x, y, color=GREEN)

# Setup grid
env = GridEnvironment(WIDTH, HEIGHT, BOX_SIZE)
env.spawn(agent_spawner, 100)

# Setup simulation
sim = Simulation(env, fps=30, name="PathfindingZonesSimulation")
sim.run_episode(n_steps=250, save=False)