allow grid to be between 2 and 9

This commit is contained in:
Daniel Tsvetkov 2022-04-09 11:19:56 +02:00
parent 9997434ac2
commit 47ccffaf81

13
main.py
View File

@ -24,12 +24,12 @@ OP_LAMBDAS = {
OP_NONE: lambda x: x[0],
}
BOX_H_LABELS = 'ABCDEF'
BOX_V_LABELS = '654321'
BOX_H_LABELS = 'ABCDEFGHI'
BOX_V_LABELS = '123456789'
def translate_box_to_rc(box):
return BOX_V_LABELS.index(box[1]), BOX_H_LABELS.index(box[0])
def translate_box_to_rc(box, grid_size):
return BOX_V_LABELS.index(box[1]), BOX_H_LABELS[grid_size-1::-1].index(box[0])
def has_line_integrity(line):
@ -47,7 +47,7 @@ def fill_grid(grid, solution):
for box_value in solution:
box_values.append(box_value)
for box, value in box_values:
br, bc = translate_box_to_rc(box)
br, bc = translate_box_to_rc(box, len(grid))
grid[br][bc] = value
return grid
@ -145,7 +145,8 @@ class Block(object):
class Game(object):
def __init__(self, grid_size, blocks):
def __init__(self, grid_size: int, blocks):
assert 2 <= grid_size <= 9
self.blocks = blocks
self.grid_size = grid_size
self.verify()