Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Xs and Os Referee by Mahoter
def checkio(game_result):
col_1 = ''
col_2 = ''
col_3 = ''
a = 0
middle = ''
for row in game_result:
if row.count('X') == 3:
return 'X'
if row.count('O') == 3:
return 'O'
col_1 += str(row[0])
col_2 += str(row[1])
col_3 += str(row[2])
if a == 1:
middle = str(row[1])
a += 1
if col_1 == 'XXX' or col_2 == 'XXX' or col_3 == 'XXX':
return 'X'
if col_1 == 'OOO' or col_2 == 'OOO' or col_3 == 'OOO':
return 'O'
if col_1[0] == middle == col_3[2] == 'X' or col_1[2] == middle == col_3[0] == 'X':
return 'X'
if col_1[0] == middle == col_3[2] == 'O' or col_1[2] == middle == col_3[0] == 'O':
return 'O'
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"
Jan. 17, 2016