Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clean and simple. solution in Clear category for Xs and Os Referee by Celshade
def checkio(game_result: list) -> str:
"""Return the winner of a game.
Args:
game_result: A list of strings representing player positions.
Returns:
winner(default="D"): "X" if -X won, "O" if -O won, or "D" for a draw.
"""
MID = game_result[1][1]
verticals = ["", "", ""]
winner = "D"
for row in game_result:
# Build a list of vertical strings.
verticals[0] += row[0]
verticals[1] += row[1]
verticals[2] += row[2]
# Check for horizontal and vertical wins.
if "XXX" in game_result or "XXX" in verticals:
winner = "X"
elif "OOO" in game_result or "OOO" in verticals:
winner = "O"
# Check for diagonal wins.
elif MID != ".":
if game_result[0][0] == MID == game_result[2][2]:
winner = game_result[0][0]
elif game_result[0][2] == MID == game_result[2][0]:
winner = game_result[0][2]
return winner
July 31, 2018