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 briang
def checkio(result):
# horizontal vertical diagonal
WINS = [ [0, 1, 2], [0, 3, 6], [0, 4, 8],
[3, 4, 5], [1, 4, 7], [2, 4, 6],
[6, 7, 8], [2, 5, 8]]
# make board be 9 individual strings
board = [x for abc in result for x in abc]
for a, b, c in WINS:
if board[a] != "." and board[a] == board[b] == board[c]:
return board[a]
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"
June 17, 2014