Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
best_moves and winning_combos solution in Clear category for Xs and Os Champion by flpo
best_moves = [[1, 1], [0, 0], [0, 2], [2, 0], [2, 2], [0, 1], [1, 0], [1, 2], [2, 1]]
winning_combos = ([0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6])
def x_and_o(state, player):
statestr = ''.join(state)
enemy = 'O' if player == 'X' else 'X'
for u in (player, enemy):
for combo in winning_combos:
state_combo = ''.join(statestr[i] for i in combo)
if state_combo.count('.') == 1 and state_combo.count(u) == 2:
return divmod(combo[state_combo.index('.')], 3)
return next((x, y) for x, y in best_moves if state[x][y] == '.')
Sept. 8, 2017
Comments: