Skip to content

Instantly share code, notes, and snippets.

@douglasgoodwin
Last active April 10, 2019 20:21
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 douglasgoodwin/a22a14c32d14c85e177c8cab525d997d to your computer and use it in GitHub Desktop.
Save douglasgoodwin/a22a14c32d14c85e177c8cab525d997d to your computer and use it in GitHub Desktop.
a tiny flask server that will give you randomized compass directions for the Termite Lab.

LAB: Let's simulate termites!

ingredients

  1. a regular grid
  2. a sack of beans
  3. bottle caps or portion cups, one per termite
  4. one die per termite (or use the simulator)

instructions

  • Draw or make a large regular grid of 2"x2" cells
  • randomly distribute dried beans on the grid
  • give each termite player a portion cup or bottle cap
  • "carrying" a woodchip is placing a bean on the cap/cup
  • termites may only carry one woodchip at a time

procedure

  1. Wander randomly around the grid by rolling the die (see below)
  2. When if you enter a cell containing a chip and your cup is empty, put it in the cup.
  3. Carry the bean and wander some more until you enter a cell containing a bean. Drop your bean.

Use the die to tell you where to move. You may define your own mapping (which would give you another bit of randomness!) or use this:

1:NW 2:N 3:NE
4:W 5:E
6:S

or start the Flask server on your local machine and hit http://127.0.0.1:5000/die.

viz

questions

  1. what happened?
  2. did you create orderly piles? if so, how many?
  3. how long did it take?
  4. why does this happen?
  5. is this simulation alive?
  6. does the medium matter?
  7. could you sort different kinds of beans? what rules would you add?
from random import choice
from flask import Flask
die = ['NW','N','NE','E','SE','S','SW','W']
app = Flask(__name__)
@app.route('/die')
def index():
roll = choice(die)
page = """<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>tumbling die</title>
<meta http-equiv="refresh" content="2;URL='http://127.0.0.1:5000/die'" />
</head>
<body>
<H1>%s</H1>
</body>
</html>""" %(roll)
return page
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment