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 frantisek.jahoda
def gen_lines(res):
for x in range(3):
yield res[x]
yield [res[i][x] for i in range(3)]
yield [res[x][x] for x in range(3)]
yield [res[x][2-x] for x in range(3)]
def checkio(game_result):
for line in gen_lines(game_result):
for ch in 'OX':
if all(x == ch for x in line):
return ch
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"
April 4, 2016