-
Notifications
You must be signed in to change notification settings - Fork 0
/
wamole.py
executable file
·45 lines (34 loc) · 950 Bytes
/
wamole.py
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
#!/usr/bin/env python
from lpfk import lpfk
from random import sample
def wamole(moles):
lp = lpfk()
# starting pattern
for k in sample(range(32), moles):
lp.keys[k] = 1
lp.update_lights()
while True:
cmd = lp.get()
if not len(cmd):
continue
if cmd == lp.RETRANSMIT:
print ('got error, resending')
update_lights()
continue
cmd = ord(cmd)
if lp.quitcheck(cmd):
break
if lp.keys[cmd] == 0:
# do nothing if we whacked a non-existent mole
continue
# choose a new light that isn't on
choices = sample(range(32), moles + 2)
for k in choices:
if lp.keys[k] == 0:
lp.keys[k] = 1
break
# and whack the current mole
lp.keys[cmd] = 0
lp.update_lights()
if __name__ == '__main__':
wamole(4)