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 bswitaj
def checkio(game_result):
if game_result[1-1][1-1]==game_result[1-1][2-1] and game_result[1-1][2-1]==game_result[1-1][3-1] and game_result[1-1][1-1]!='.':
if game_result[1-1][1-1]=='X':
return 'X'
elif game_result[1-1][1-1]=='O':
return 'O'
elif game_result[2-1][1-1]==game_result[2-1][2-1] and game_result[2-1][2-1]==game_result[2-1][3-1] and game_result[2-1][1-1]!='.':
if game_result[2-1][1-1]=='X':
return 'X'
elif game_result[2-1][1-1]=='O':
return 'O'
elif game_result[3-1][1-1]==game_result[3-1][2-1] and game_result[3-1][2-1]==game_result[3-1][3-1] and game_result[3-1][1-1]!='.':
if game_result[3-1][1-1]=='X':
return 'X'
elif game_result[3-1][1-1]=='O':
return 'O'
##############
elif game_result[1-1][1-1]==game_result[2-1][1-1] and game_result[3-1][1-1]==game_result[1-1][1-1] and game_result[1-1][1-1]!='.':
if game_result[1-1][1-1]=='X':
return 'X'
elif game_result[1-1][1-1]=='O':
return 'O'
elif game_result[1-1][2-1]==game_result[2-1][2-1] and game_result[3-1][2-1]==game_result[1-1][2-1] and game_result[1-1][2-1]!='.':
if game_result[1-1][2-1]=='X':
return 'X'
elif game_result[1-1][2-1]=='O':
return 'O'
elif game_result[1-1][3-1]==game_result[2-1][3-1] and game_result[3-1][3-1]==game_result[1-1][3-1] and game_result[1-1][3-1]!='.':
if game_result[1-1][3-1]=='X':
return 'X'
elif game_result[1-1][3-1]=='O':
return 'O'
#####################
elif game_result[1-1][1-1]==game_result[2-1][2-1] and game_result[2-1][2-1]==game_result[3-1][3-1] and game_result[1-1][1-1]!='.':
if game_result[1-1][1-1]=='X':
return 'X'
elif game_result[1-1][1-1]=='O':
return 'O'
elif game_result[1-1][3-1]==game_result[2-1][2-1] and game_result[2-1][2-1]==game_result[3-1][1-1] and game_result[1-1][3-1]!='.':
if game_result[1-1][3-1]=='X':
return 'X'
elif game_result[1-1][3-1]=='O':
return 'O'
else:
return "D"
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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Oct. 14, 2017