Level 3 easier but still missing necessary clues to the player.
This commit is contained in:
@@ -91,14 +91,35 @@ def _get_oxs(x):
|
||||
else (x - 1, x + 1) if x % 3 == 1 \
|
||||
else (x - 2, x - 1)
|
||||
|
||||
def generate_random_box(nwells):
|
||||
"""Generate a box with random colors except white (111)."""
|
||||
def generate_random_box(nwells, min_nonblacks=0):
|
||||
"""
|
||||
Generate a box that triggers nwells wells, with random colors except white
|
||||
(111).
|
||||
|
||||
Arguments:
|
||||
min_nonblacks -- minimum number of well colours in a box required not to be
|
||||
black.
|
||||
"""
|
||||
def gen_wc():
|
||||
wc = [random.choice((0, 1)) for i in range(3)]
|
||||
if all(b == 1 for b in wc):
|
||||
wc[random.randrange(3)] = 0
|
||||
return wc
|
||||
return [tuple(gen_wc()) for _ in range(nwells)]
|
||||
def gen_wc_nonblack():
|
||||
wc = gen_wc()
|
||||
if all(b == 0 for b in wc):
|
||||
wc[random.randrange(3)] = 1
|
||||
return wc
|
||||
colours = [tuple(gen_wc()) for _ in range(nwells)]
|
||||
nonblack = lambda t: any(n == 1 for n in t)
|
||||
missing_nonblacks = min_nonblacks - len(list(filter(nonblack, colours)))
|
||||
i = 0
|
||||
while missing_nonblacks > 0:
|
||||
if not nonblack(colours[i]):
|
||||
colours[i] = gen_wc_nonblack()
|
||||
missing_nonblacks -= 1
|
||||
i += 1
|
||||
return colours
|
||||
|
||||
def get_colours(boxes):
|
||||
colours = []
|
||||
|
||||
Reference in New Issue
Block a user