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 Kurush
# migrated from python 2.7
def checkio(game_result):
if CheckLine(game_result, 'X') == 'X': return 'X'
if CheckLine(game_result, 'O') == 'O': return 'O'
return "D"
def CheckLine(game_result, Symbol):
for i in range(3):
if (game_result[i][0] == game_result[i][1] == game_result[i][2] == Symbol):
return Symbol
for i in range(3):
if (game_result[0][i] == game_result[1][i] == game_result[2][i] == Symbol):
return Symbol
if (game_result[0][0] == game_result[1][1] == game_result[2][2] == Symbol):
return Symbol
if (game_result[0][2] == game_result[1][1] == game_result[2][0] == Symbol):
return Symbol
#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. 17, 2013