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 klaganowski
def checkio(game_result):
ow=False
xw=False
if (game_result[0] == "XXX") or (game_result[1] == "XXX") or (game_result[2] == "XXX"):
xw=True
if (game_result[0][0]+game_result[1][1]+game_result[2][2] == "XXX"):
xw=True
if (game_result[0][2]+game_result[1][1]+game_result[2][0] == "XXX"):
xw=True
if (game_result[0][0]+game_result[1][0]+game_result[2][0] == "XXX") or (game_result[0][1]+game_result[1][1]+game_result[2][1] == "XXX") or (game_result[0][2]+game_result[1][2]+game_result[2][2] == "XXX"):
xw=True
if (game_result[0] == "OOO") or (game_result[1] == "OOO") or (game_result[2] == "OOO"):
ow=True
if (game_result[0][0]+game_result[1][1]+game_result[2][2] == "OOO"):
ow=True
if (game_result[0][2]+game_result[1][1]+game_result[2][0] == "OOO"):
ow=True
if (game_result[0][0]+game_result[1][0]+game_result[2][0] == "OOO") or (game_result[0][1]+game_result[1][1]+game_result[2][1] == "OOO") or (game_result[0][2]+game_result[1][2]+game_result[2][2] == "OOO"):
ow=True
w=""
if xw == True:
if ow == True:
return "D"
else:
return "X"
elif ow == True:
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"
Dec. 5, 2016