Commit 9b4a645b authored by Taddeüs Kroes's avatar Taddeüs Kroes

Improve bomb detection

parent c91e1e2e
......@@ -22,7 +22,9 @@ HUE_TOLERANCE = 5
DETECT_BASIC_X = 9
DETECT_BASIC_Y = 15
DETECT_BOMB_X = 22
DETECT_BOMB_Y = 45
DETECT_BOMB_Y = 43
DETECT_BOMB_Y_TOLERANCE = 7
DETECT_BOMB_CHECK = 9, 20, 137, 230, 9 # x, y, hue, value, tolerance
MIN_BASIC_SAT = 180
MIN_BOMB_SAT = 130
......@@ -79,13 +81,24 @@ def detect_block_type(board, x, y):
if is_hue(h, hexpect):
return ty
# if no basic block is detected, check another pixel for bomb contents
h, s, v = board.getpixel((x + DETECT_BOMB_X,
y + DETECT_BOMB_Y))
if s >= MIN_BOMB_SAT:
for ty, hexpect in enumerate(BOMB_HUES):
if is_hue(h, hexpect):
return ty + BOMB_OFFSET
# if no basic block is detected, check another range of pixels for bomb
# contents
def check_bomb():
dx, dy, hexpect, minval, tolerance = DETECT_BOMB_CHECK
for offset in range(tolerance):
h, s, v = board.getpixel((x + dx, y + dy + offset))
if is_hue(h, hexpect) and v >= minval:
return True
return False
if check_bomb():
for offset in range(DETECT_BOMB_Y_TOLERANCE):
h, s, v = board.getpixel((x + DETECT_BOMB_X,
y + DETECT_BOMB_Y + offset))
if s >= MIN_BOMB_SAT:
for basic_ty, hexpect in enumerate(BOMB_HUES):
if is_hue(h, hexpect):
return basic_ty + BOMB_OFFSET
# no basic block or bomb -> empty slot
return NOBLOCK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment