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 fess89
def checkio(game_result):
var = "XO"
ran = range(3)
for i in ran:
row = game_result[i]
col = [line[i] for line in game_result]
for c in var:
if row.count(c) == 3 or col.count(c) == 3:
return c
diag1 = [game_result[i][i] for i in ran]
diag2 = [game_result[i][2 - i] for i in ran]
for c in var:
if diag1.count(c) == 3 or diag2.count(c) == 3:
return c
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"
Aug. 10, 2015