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 Vereena
def checkio(field):
for row in field:
if row[0] == row [1] == row[2] !=".": return row[0]
rot_field = zip(*field)
for row in rot_field:
if row[0] == row [1] == row[2] !=".": return row[0]
if field[0][0] == field[1][1] == field[2][2] !=".": return field[0][0]
if field[0][2] == field[1][1] == field[2][0] !=".": return field[0][2]
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!")
Dec. 16, 2017