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 Kumortas
def checkio(game_result):
for line in [[[0,0],[0,1],[0,2]], [[1,0],[1,1],[1,2]], [[2,0],[2,1],[2,2]], \
[[0,0],[1,0],[1,0]], [[0,1],[1,1],[2,1]], [[0,2],[1,2],[2,2]], \
[[0,0],[1,1],[2,2]], [[2,0],[1,1],[0,2]]]:
char = game_result[line[0][0]][line[0][1]]
if char != '.' and game_result[line[1][0]][line[1][1]]==char and game_result[line[2][0]][line[2][1]]==char:
return char
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. 11, 2015