public
Created — forked from leif/timekeeperville.py

timekeeperville

  • Download Gist
timekeeperville.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
"timekeeperville is a game where you must keep time"
# by Leif Ryge, 2012, WTFPL
from sys import argv
from time import time
from collections import deque
rate = 4 if len(argv) < 2 else int(argv[1])
level = 4 if len(argv) < 3 else int(argv[2])
data = [ deque([], 1) ]
start = time()
prev = start - (1.0/rate)
i = 0
while True:
now = time()
clock = now - start
delta = now - prev
prev = now
if len(data[-1]) == 2**(len(data)-1): data.append(deque(data[-1], 2**len(data)))
widths = []
for window in data:
window.append( delta )
width = int(0.5+((level)*sum((delta*rate) for delta in window)/float(len(window))))
widths.append( width )
print "\x1b[H\x1b[2J\x0d",
print "Instructions: make all lines the correct length by hitting Enter %s times/second" % rate
if i>1 and list(set( widths[:level] )) == [ level ]:
print ":) |", "v" * level
print "\n".join("%6s| %s" % (len(window), ">" * width) for window, width in zip(data[:level], widths))
print ":) |", "^" * level
level += 1
else:
print " |", "_" * level
print "\n".join("%6s| %s" % (len(window), "=" * width) for window, width in zip(data[:level], widths))
print " |", "^" * level
if i > 0:
seconds = clock % 60
minutes = (clock - seconds)/60
print "Level %s. After %dm %ds, cumulative mean speed is %.3f%% of target" % (level,minutes,seconds, 100/(1.0/(i/clock/rate)))
i += 1
if raw_input() == "z":
print "Paused. Hit ENTER again to continue."
before = time()
raw_input()
pause = time() - before
start += pause
prev += pause

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.