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 Degusto
def checkio(game_result):
if check_if_winner(game_result, 'X'):
return 'X'
elif check_if_winner(game_result, 'O'):
return 'O'
else:
return 'D'
def check_if_winner(result, player):
if result[0][0] == result[0][1] == result[0][2] == player:
return True
if result[1][0] == result[1][1] == result[1][2] == player:
return True
if result[2][0] == result[2][1] == result[2][2] == player:
return True
if result[0][0] == result[1][0] == result[2][0] == player:
return True
if result[0][1] == result[1][1] == result[2][1] == player:
return True
if result[0][2] == result[1][2] == result[2][2] == player:
return True
if result[0][0] == result[1][1] == result[2][2] == player:
return True
if result[2][0] == result[1][1] == result[0][2] == player:
return True
return False
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"
Nov. 17, 2015
Comments: