Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by slygoblin
def checkio(game_result):
result = "D"
game_res_rev = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(game_result)):
for j in range(len(game_result[i])):
game_res_rev[j][i] = game_result[i][j]
for i in range(len(game_result)):
if game_result[i].count("X") ==3 or game_res_rev[i].count("X") == 3:
result = "X"
break
if game_result[i].count("O") == 3 or game_res_rev[i].count("O") == 3:
result = "O"
break
if game_result[0][0] == "X" and game_result[1][1] == "X" and game_result[2][2] == "X":
result = "X"
if game_result[2][0] == "X" and game_result[1][1] == "X" and game_result[0][2] == "X":
result = "X"
if game_result[0][0] == "O" and game_result[1][1] == "O" and game_result[2][2] == "O":
result = "O"
if game_result[2][0] == "O" and game_result[1][1] == "O" and game_result[0][2] == "O":
result = "O"
return result
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. 9, 2015