-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
64 lines (53 loc) · 1.71 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
import random
import string
from threading import Thread
from Game import Game
from PlayerSession import PlayerSession
def runOneWithUserName():
#logging.basicConfig(level=logging.DEBUG)
username = "pavle"
password = ""
with PlayerSession(username, password) as session:
data = {
"game": "testing",
"num_players": 3,
"is_observer": False,
"is_full": True
}
game = Game(session, data)
print(game.isWinner())
# game.quitDisplay()
def __threadBody(data, i, playerName):
with PlayerSession(playerName, "") as session:
game = Game(session, data)
if game.isWinner():
winners.append(i) # remove comment for seeing number of winners
pass
def runAutomatically(numPlayers: int, numTurns: int, iteration: int):
letters = string.ascii_letters
randomGameName = ''.join(random.choice(letters) for _ in range(10)) # name
data = {"game": "test" + str(iteration), "num_turns": numTurns, "num_players": 2, "is_full": False}
threads = []
for i in range(numPlayers):
playerName = ''.join(random.choice(letters) for _ in range(10)) # player name
thread = Thread(target=__threadBody, args=(data, i, playerName))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
if __name__ == "__main__":
# logging.basicConfig(level=logging.DEBUG)
winners = []
runOneWithUserName()
"""
Code for automatic running of threads
winners = []
winByPlayer = [0, 0, 0]
numGames = 5
for i in range(numGames):
runAutomatically(3, 99, i)
for winner in winners:
winByPlayer[winner] += 1
print(winByPlayer)
"""