Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
urgent cells first solution in Creative category for Xs and Os Champion by David_Jones
URGENT_CELLS = (4, 0, 2, 6, 8, 1, 3, 5, 7)
LINES = (
(0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6)
)
to_coords = lambda cell: divmod(cell, 3)
def x_and_o(grid, your_mark):
grid = ''.join(grid)
enemy_mark = 'XO'[your_mark == 'X']
for mark in (your_mark, enemy_mark):
for cells in LINES:
line = [grid[cell] for cell in cells]
if line.count('.') == 1 and line.count(mark) == 2:
return to_coords(cells[line.index('.')])
return next(to_coords(cell) for cell in URGENT_CELLS if grid[cell] == '.')
July 5, 2019