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 Aissame
def horizontal(game_result):
res = "D"
for i in range(3):
if game_result[i][0] == game_result[i][1] == game_result[i][2] and game_result[i][1] != ".":
res = game_result[i][1]
return res
def vertical(game_result):
res = "D"
for i in range(3):
if game_result[0][i] == game_result[1][i] == game_result[2][i] and game_result[1][i] != ".":
res = game_result[1][i]
return res
def diagonal(game_result):
res = "D"
n = game_result[1][1]
if n == game_result[0][0] == game_result[2][2] or n== game_result[0][2] == game_result[2][0] and n != ".":
res = n
return res
def checkio(game_result):
res = "D"
l = []
l.append(horizontal(game_result))
l.append(vertical(game_result))
l.append(diagonal(game_result))
for i in l:
if i != "D" and i != ".":
res = i
return res
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!")
Nov. 28, 2017