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 fariik
# migrated from python 2.7
def checkio(game_result):
for i in range(3):
#Test des lignes
if game_result[i].count(game_result[i][0]) == 3 and game_result[i][0] != '.':
return game_result[i][0]
#Test des colonnes
if game_result[0][i] == game_result[1][i] and game_result[1][i] == game_result[2][i] and game_result[0][i] != '.':
return game_result[0][i]
if game_result[0][0] == game_result[1][1] and game_result[1][1] == game_result[2][2] and game_result[0][0] != '.':
return game_result[0][0]
elif game_result[0][2] == game_result[1][1] and game_result[1][1] == game_result[2][0] and game_result[0][2] != '.':
return game_result[0][2]
else:
return 'D'
'''
return "D" or "X" or "O" '''
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"
June 4, 2014