Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. from random import sample
  2.  
  3.  
  4. def tic_tac_toe():
  5. board = []
  6. s = 3
  7. win = False
  8.  
  9. for x in range(s):
  10. y = sample(range(s), s)
  11. board.append(y)
  12. print(y)
  13.  
  14.  
  15. #horizontal check:
  16. for x in range(s):
  17. if (board[x][0] == board[x][1] == board[x][2]) and board[x][0] != 0:
  18. print("Player {} wins!".format(board[x][0]))
  19. win = True
  20.  
  21. #vertical check:
  22. for x in range(s):
  23. if (board[0][x] == board[1][x] == board[2][x]) and board[0][x] != 0:
  24. print("Player {} wins!".format(board[0][x]))
  25. win = True
  26.  
  27. #diagonal_check:
  28. if (board[0][0] == board[1][1] == board[2][2]) and board[1][1] != 0:
  29. print("Player {} wins!".format(board[1][1]))
  30. win = True
  31. elif (board[0][2] == board[1][1] == board[2][0]) and board[1][1] != 0:
  32. print("Player {} wins!".format(board[1][1]))
  33. win = True
  34.  
  35. if not win:
  36. print("Draw..")
  37.  
  38. tic_tac_toe()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement