Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def board_maker(rows, cols):
- w = rows * cols
- def n2b(n):
- s = f'{bin(n)[2:]:>0{w}}'
- s = s.replace('0', 'M').replace('1', 'B')
- return [list(x) for x in zip(*[iter(s)] * rows)]
- def calc(n):
- return calculate_score(n2b(n))
- return n2b, calc
- def iter_neighbors(board, x,y):
- n = len(board)
- m = max(map(len, board))
- for dx in (-1,0,1):
- for dy in (-1, 0, 1):
- if dx == dy == 0: continue
- if dy+y < 0 or dy+y >= n or dx+x < 0 or dx+x >= m: continue
- yield board[dy+y][dx+x]
- n2b, calc = board_maker(4, 4)
- n = max(range(2 ** 16), key=calc)
- display(n2b(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement