Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. board = {'A':' ', 'B':' ', 'C':' ',
  2. 'D':' ', 'E':' ', 'F':' ',
  3. 'G':' ', 'H':' ', 'I':' '}
  4.  
  5. def play(move):
  6. if board[move] == '':
  7. board[move] = 'X'
  8.  
  9. def printBoard(board):
  10. print(board['A']+ '|' + board['B'] + '|' + board['C'])
  11. print('-+-+-')
  12. print(board['D']+ '|' + board['E'] + '|' + board['F'])
  13. print('-+-+-')
  14. print(board['G']+ '|' + board['H'] + '|' + board['I'])
  15.  
  16. def didYouWin(board, letter):
  17. return ((board['A']==letter and board['B']==letter and board['C']==letter) or
  18. (board['D']==letter and board['E']==letter and board['F']==letter) or
  19. (board['G']==letter and board['H']==letter and board['I']==letter) or
  20. (board['A']==letter and board['E']==letter and board['I']==letter) or
  21. (board['A']==letter and board['D']==letter and board['G']==letter) or
  22. (board['C']==letter and board['E']==letter and board['G']==letter) or
  23. (board['C']==letter and board['F']==letter and board['I']==letter) or
  24. (board['B']==letter and board['E']==letter and board['H']==letter))
  25.  
  26. turn = 'X'
  27.  
  28. for i in range(9):
  29. printBoard(board)
  30.  
  31. print('player ' + turn + ' what is your move??')
  32. move = input()
  33. board[move] = turn
  34.  
  35. if didYouWin(board,turn):
  36. printBoard(board)
  37. print('YAY! you won, player '+ turn)
  38. break
  39.  
  40. if turn == 'X':
  41. turn = 'O'
  42. else:
  43. turn = 'X'
  44. printBoard(board)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement