This is an implementation of the game described in the 09/30/2007 edition of Dilbert.
Paul McLain has also created a C++ version of Carpet Fishing.
import threading
from random import randint
# Configuration
grid_size = 8 # An 8x8 grid
min_time = 30 * 60 # 30 minutes
max_time = 60 * 60 # 60 minutes
fish = ['Marlin', 'Rainbow Trout', 'Bass']
# Logic
def check_for_fish():
if (randint(1, 100) >= 95):
salmon_run()
else:
print "%s in square %s" % (fish[randint(0, len(fish) - 1)],
"%s%d" % (chr((randint(1, grid_size) - 1) % 26 + 65),
randint(1, grid_size)))
create_timer()
def salmon_run():
squares = ""
for i in xrange(0, int(pow(grid_size, 2) / 4)):
squares += "%s%d " % (chr((randint(1, grid_size) - 1) % 26 + 65),
randint(1, grid_size))
print "* Salmon in squares %s" % squares
def create_timer():
t = threading.Timer(randint(min_time, max_time), check_for_fish)
t.start()
create_timer()
beau@beaugunderson.com