Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Unsafe solution in Clear category for Xs and Os Referee by elmopl
from collections import namedtuple
coord = namedtuple('coord', ('row', 'col'))
winning = []
winning.extend([coord(r, c) for r in range(3)] for c in range(3))
winning.extend([coord(c, r) for r in range(3)] for c in range(3))
winning.append([coord(i,i) for i in range(3)])
winning.append([coord(i,2-i) for i in range(3)])
def checkio(game_result):
# this does not check for invalid states
# with more than one winner
wins = []
for w in winning:
a, b, c = [game_result[c.row][c.col] for c in w]
if a != '.' and a == b and b == c:
return a
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"
Dec. 20, 2015
Comments: