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 kamilinho20
def checkio(game_result):
result = 'D'
for i in range(len(game_result)):
if game_result[i][0] == game_result[i][1] and game_result[i][1] == game_result[i][2]:
result = game_result[i][0]
if result == '.':
result = 'D'
elif game_result[0][i] == game_result[1][i] and game_result[1][i] == game_result[2][i]:
result = game_result[0][i]
if result == '.':
result = 'D'
if game_result[0][0] == game_result[1][1] and game_result[1][1] == game_result[2][2]:
result = game_result[0][0]
if result == '.': result = 'D'
elif game_result[2][0] == game_result[1][1] and game_result[1][1] == game_result[0][2]:
result = game_result[2][0]
if result == '.': result = 'D'
print(result)
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. 20, 2016