CAMS-Replicator-2D-Simulation/main.py

38 lines
772 B
Python

from sim import Environment, CAMSReverseAndSidestepAgent, Direction
import time
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
STEPS = 1000
np.random.seed(12345)
fig, ax = plt.subplots()
env = Environment((40, 30))
first_agent = CAMSReverseAndSidestepAgent(
environment=env,
position=(20,15),
initial_direction=Direction.NORTH
)
second_agent = CAMSReverseAndSidestepAgent(
environment=env,
position=(11,13),
initial_direction=Direction.EAST
)
im = ax.imshow(env.render(), aspect="equal", origin="lower")
def update(frame_number):
env.step()
im.set_data(env.render())
return im,
ani = FuncAnimation(
fig=fig,
func=update,
frames=STEPS,
blit=True)
plt.show()