Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
XO's solution in Clear category for Xs and Os Referee by lucianes
def checkio(xo):
win = [[0, 0, 0, 1, 0, 2], [1, 0, 1, 1, 1, 2], [2, 0, 2, 1, 2, 2], [0, 0, 1, 0, 2, 0], [0, 1, 1, 1, 2, 1], [0, 2, 1, 2, 2, 2], [0, 0, 1, 1, 2, 2], [2, 0, 1, 1, 0, 2]]
for w in win:
if xo[w[0]][w[1]] == xo[w[2]][w[3]] == xo[w[4]][w[5]] and xo[w[0]][w[1]] in 'XO':
return xo[w[0]][w[1]]
return 'D'
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
Oct. 24, 2015