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 JeffersonHolbrook
def checkio(game_result):
row_1 = game_result[0]
row_2 = game_result[1]
row_3 = game_result[2]
#vertical columns
if row_1[0] == row_2[0] == row_3[0] and row_1[0] != '.':
winner = row_1[0]
elif row_1[1] == row_2[1] == row_3[1] and row_1[1] != '.':
winner = row_1[1]
elif row_1[2] == row_2[2] == row_3[2] and row_1[2] != '.':
winner = row_1[2]
#horizontal rows
elif row_1[0] == row_1[1] == row_1[2] and row_1[0] != '.':
winner = row_1[0]
elif row_2[0] == row_2[1] == row_2[2] and row_2[0] != '.':
winner = row_2[0]
elif row_3[0] == row_3[1] == row_3[2] and row_3[0] != '.':
winner = row_3[0]
#diagnoals
elif row_1[0] == row_2[1] == row_3[2] and row_1[0] != '.':
winner = row_1[0]
elif row_1[2] == row_2[1] == row_3[0] and row_1[2] != '.':
winner = row_1[2]
#draw
else:
winner = "D"
return winner
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"
July 28, 2014