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 JackSchneider
def checkio(game_result):
g=game_result
if g[0][0]== "X" and g[0][1]== "X" and g[0][2]== "X" \
or g[1][0]== "X" and g[1][1]== "X" and g[1][2]== "X" \
or g[2][0]== "X" and g[2][1]== "X" and g[2][2]== "X" \
or g[0][0]== "X" and g[1][0]== "X" and g[2][0]== "X" \
or g[0][1]== "X" and g[1][1]== "X" and g[2][1]== "X" \
or g[0][2]== "X" and g[1][2]== "X" and g[2][2]== "X" \
or g[0][0]== "X" and g[1][1]== "X" and g[2][2]== "X" \
or g[0][2]== "X" and g[1][1]== "X" and g[2][0]== "X":
return "X"
if g[0][0]== "O" and g[0][1]== "O" and g[0][2]== "O" \
or g[1][0]== "O" and g[1][1]== "O" and g[1][2]== "O" \
or g[2][0]== "O" and g[2][1]== "O" and g[2][2]== "O" \
or g[0][0]== "O" and g[1][0]== "O" and g[2][0]== "O" \
or g[0][1]== "O" and g[1][1]== "O" and g[2][1]== "O" \
or g[0][2]== "O" and g[1][2]== "O" and g[2][2]== "O" \
or g[0][0]== "O" and g[1][1]== "O" and g[2][2]== "O" \
or g[0][2]== "O" and g[1][1]== "O" and g[2][0]== "O":
return "O"
return "D"
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
Sept. 18, 2013
Comments: