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 PsnDth
def checkio(game_result):
game = []
for x in game_result:
game.append(list(x))
#horizantal win
for x in game:
if (x[0] == x[1] and x[1] == x[2]) and (x[1] == 'X' or x[1] == "O"):
if x[1] == 'X':
return 'X'
else:
return 'O'
#vertical win
for x in range(0,3):
if (game[0][x] == game [1][x] and game[1][x] == game[2][x]) and (game[0][x] == 'X' or game[0][x] == 'O'):
if game[0][x] == 'X':
return 'X'
else:
return 'O'
#diagonal win
if ((game[0][0] == game[1][1] and game[1][1] == game[2][2]) or (game[0][2] == game[1][1] and game[1][1] == game[2][0])) and (game[1][1] == 'X' or game[1][1] == 'O'):
if game[1][1] == 'X':
return 'X'
else:
return 'O'
#no win
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. 23, 2014