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 mjazy
def checkio(game_result):
result = None
index = 0;
for line in game_result:
if line[0] == line[1] == line[2] and line[0] != ".":
if line[0] == "O":
result = "O"
if line[0] == "X":
result = "X"
rotatedGameResult = zip(*game_result)
for line in rotatedGameResult:
if line[0] == line[1] == line[2] and line[0] != ".":
if line[0] == "O":
result = "O"
if line[0] == "X":
result = "X"
if (game_result[0][0] == game_result[1][1] == game_result[2][2]) or (game_result[0][2] == game_result[1][1] == game_result[2][0]):
if game_result[1][1] == "O":
result = "O"
if game_result[1][1] == "X":
result = "X"
if result == None:
result = "D"
return result
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!")
Jan. 7, 2018