Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Xs and Os Referee by eddy-geek
def matches(game, sol):
for g, s in zip(game, sol):
if s != ' ' and g != s:
return False
return True
def checkio(game_result):
g = ''.join(game_result)
x_wins = [
'X ' * 3, ' X ' * 3, ' X' * 3,
'XXX ', ' XXX ', ' XXX',
'X X X', ' X X X '
]
for sol in x_wins:
if matches(g, sol):
return 'X'
o_wins = [sol.replace('X', 'O') for sol in x_wins]
for sol in o_wins:
if matches(g, sol):
return 'O'
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. 17, 2015