Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
check horz, diag, vert #comments solution in Clear category for Xs and Os Referee by mlb00
# migrated from python 2.7
def checkio(game_result):
if 'XXX' in game_result: #first check 'XXX' or 'OOO' in horizontal (given)
return 'X'
elif 'OOO' in game_result:
return 'O'
d = [game_result[0][0] + game_result[1][1] + game_result[2][2], \
game_result[0][2] + game_result[1][1] + game_result[2][0]]
if 'XXX' in d: #next try 'XXX' or 'OOO' in diagonal
return 'X'
elif 'OOO' in d:
return 'O'
v = ['','','']
for s in game_result:
i = 0
for e in s:
v[i]+=e
i+=1
if 'XXX' in v: #last, try 'XXX' or 'OOO' in vertical
return 'X'
elif 'OOO' in v:
return 'O'
return 'D' #if none of those it must be a draw
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"
March 26, 2015
Comments: