Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1 2 3
- #4 5 6
- #7 8 9
- import random
- xwin = 0
- owin = 0
- draw = 0
- result = [0] * 10
- for i in range(10000):
- x = []
- o = []
- _ = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- while 1 == 1:
- turn = random.choice(_)
- if len(_) == 9:
- first = turn
- _[_.index(turn):_.index(turn) + 1] = []
- x.append(turn)
- if ((1 in x and 2 in x and 3 in x) or
- (4 in x and 5 in x and 6 in x) or
- (7 in x and 8 in x and 9 in x) or
- (1 in x and 4 in x and 7 in x) or
- (2 in x and 5 in x and 8 in x) or
- (3 in x and 6 in x and 9 in x) or
- (1 in x and 5 in x and 9 in x) or
- (3 in x and 5 in x and 7 in x)):
- xwin += 1
- result[first] += 1
- break
- if not _:
- draw += 1
- break
- comp = random.choice(_)
- _[_.index(comp):_.index(comp) + 1] = []
- o.append(comp)
- if ((1 in o and 2 in o and 3 in o) or
- (4 in o and 5 in o and 6 in o) or
- (7 in o and 8 in o and 9 in o) or
- (1 in o and 4 in o and 7 in o) or
- (2 in o and 5 in o and 8 in o) or
- (3 in o and 6 in o and 9 in o) or
- (1 in o and 5 in o and 9 in o) or
- (3 in o and 5 in o and 7 in o)):
- owin += 1
- break
- print(xwin, owin, draw)
- i = 1
- while i <= 9:
- if i in x:
- print('x', end="")
- elif i in o:
- print('o', end="")
- else:
- print('.', end="")
- if i % 3 == 0:
- print()
- i += 1
- print(result[1:])
Advertisement
Add Comment
Please, Sign In to add comment