Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def checkio(game_result):
- win_posX=[['XXX']
- ['XXX']
- ['XXX']]
- win_posO=[['OOO']
- ['OOO']
- ['OOO']]
- res, pr=[],[]
- for i in win_posX:
- if game_result in win_pos:
- res.append('X')
- else:
- for k in range(len(game_result)):
- for z in game_result:
- if z[k][0] == 'X':
- pr.append('X')
- if pr == ['X','X','X']: res.append('X')
- if z[k][k] == 'X':
- pr.append('X')
- if pr == ['X','X','X']: res.append('X')
- if z[k][2] and z[k][1] and z[k][0]: res.append('X')
- for i in win_posO:
- if game_result in win_pos:
- res.append('O')
- else:
- for k in range(len(game_result)):
- for z in game_result:
- if z[k][0] == 'O':
- pr.append('O')
- if pr == ['O','O','O']: res.append('O')
- if z[k][k] == 'O':
- pr.append('O')
- if pr == ['O','O','O']: res.append('X')
- if z[k][2] and z[k][1] and z[k][0]: res.append('O')
- if res == ['X','O']:
- return 'D'
- elif res==['X']:
- return 'X'
- elif res==['O']:
- return 'O'
- else: return -1
- 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"
Advertisement
Add Comment
Please, Sign In to add comment