Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2017 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5b2c1333548b6d7edebe7dd4af99335c to your computer and use it in GitHub Desktop.
Save anonymous/5b2c1333548b6d7edebe7dd4af99335c to your computer and use it in GitHub Desktop.
import simpy
import random
a, b, c = 10, 30, 5
strict = +1 # +1 for version A, -1 for version B
def lap(sim, event):
laps[event.data] = strict * event.priority
if abs(laps[0] - laps[1]) > 1:
sim.stop_at(event.time)
sim.publish(simpy.Event(event.time + c + random.randint(a, b),
event.priority + strict, '', event.data))
laps = [0, 0]
sim = simpy.Simulation()
sim.subscribe('', lap)
for player in range(2):
sim.publish(simpy.Event(random.randint(a, b), 0, '', player))
sim.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment