Guest User

Untitled

a guest
Oct 22nd, 2014
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #1 2 3
  2. #4 5 6
  3. #7 8 9
  4. import random
  5.  
  6. xwin = 0
  7. owin = 0
  8. draw = 0
  9.  
  10. result = [0] * 10
  11. for i in range(10000):    
  12.     x = []
  13.     o = []
  14.     _ = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  15.  
  16.     while 1 == 1:
  17.         turn = random.choice(_)
  18.         if len(_) == 9:
  19.             first = turn
  20.         _[_.index(turn):_.index(turn) + 1] = []
  21.         x.append(turn)
  22.         if ((1 in x and 2 in x and 3 in x) or
  23.             (4 in x and 5 in x and 6 in x) or
  24.             (7 in x and 8 in x and 9 in x) or
  25.             (1 in x and 4 in x and 7 in x) or
  26.             (2 in x and 5 in x and 8 in x) or
  27.             (3 in x and 6 in x and 9 in x) or
  28.             (1 in x and 5 in x and 9 in x) or
  29.             (3 in x and 5 in x and 7 in x)):
  30.             xwin += 1
  31.             result[first] += 1
  32.             break
  33.         if not _:
  34.             draw += 1
  35.             break
  36.         comp = random.choice(_)
  37.         _[_.index(comp):_.index(comp) + 1] = []
  38.         o.append(comp)
  39.         if ((1 in o and 2 in o and 3 in o) or
  40.             (4 in o and 5 in o and 6 in o) or
  41.             (7 in o and 8 in o and 9 in o) or
  42.             (1 in o and 4 in o and 7 in o) or
  43.             (2 in o and 5 in o and 8 in o) or
  44.             (3 in o and 6 in o and 9 in o) or
  45.             (1 in o and 5 in o and 9 in o) or
  46.             (3 in o and 5 in o and 7 in o)):
  47.             owin += 1
  48.        
  49.             break
  50. print(xwin, owin, draw)
  51.  
  52. i = 1
  53. while i <= 9:
  54.     if i in x:
  55.         print('x', end="")
  56.     elif i in o:
  57.         print('o', end="")
  58.     else:
  59.         print('.', end="")
  60.     if i % 3 == 0:
  61.         print()
  62.     i += 1
  63. print(result[1:])
Advertisement
Add Comment
Please, Sign In to add comment