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 Vaibhav
def checkio(game_result):
rows = game_result
cols = [''.join([game_result[j][i] for j in range(0, 3)]) for i in range(0, 3)]
diag1 = ''.join([game_result[i][i] for i in range(0, 3)])
diag2 = ''.join([game_result[i][2 - i] for i in range(0, 3)])
if "XXX" in rows or "XXX" in cols or "XXX" in diag1 or "XXX" in diag2:
return 'X'
elif "OOO" in rows or "OOO" in cols or "OOO" in diag1 or "OOO" in diag2:
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"
July 20, 2015
Comments: