-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_extra_credit.py
85 lines (61 loc) · 2.45 KB
/
test_extra_credit.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from tournament import *
from random import randint
from math import log, ceil
def setupTournament(tname):
createTournament(tname)
return
def registerPlayers(tournament="Default Tournament", tplayers=10):
"""Registers a list of randomly generated names. """
# Potential first names:
pFN = ["Eden ", "Sharilyn ", "Merissa ", "Dalia ",
"Ema ", "Dede ", "Raul ", "Genaro ", "Raelene ", "Merrie "]
# Potential last names:
pLN = ["Alcantar", "Armstrong", "Brafford",
"Loughran", "Stager", "Saia", "Lyall",
"Tuma", "Mccarville", "Sollars"]
for i in range(tplayers):
name = pFN[randint(0, 9)] + pLN[randint(0, 9)]
registerPlayer(name, tournament)
return
def gameon(lpp, tournament):
"""Play the games with a random winner or loser"""
print "Pairs for this round: \n {} \n ".format(lpp)
for pair in lpp:
# Random winner and loser
if not pair[1]:
# Making sure that if the pair contains a bye we don't put the by
# as winner.
reportMatch(pair[0], pair[1], tournament)
continue
if randint(0, 1):
reportMatch(pair[0], pair[1], tournament, True)
else:
r_win = randint(0, 1)
r_loser = (r_win + 1) % 2
reportMatch(pair[r_win], pair[r_loser], tournament)
def testReportMatches(tournament="Default Tournament", tot_players=4):
""" Registers players in a tournament,
figures out the minimum number of rounds to be played in order to find a winner,
makes the pairings based on swissSupPairings,
plays the games using gameon,
prints the final results"""
deleteMatches(tournament)
deletePlayers(tournament)
# Register n players
registerPlayers(tournament, tot_players)
rounds = int(ceil(log(tot_players, 2)))
print "PLAYING {} ROUNDS".format(rounds)
for i in range(rounds):
pairings = swissSupPairings(tournament)
gameon(pairings, tournament)
standings = playerSupStandings(tournament)
print "\n FINAL RESULT FOR '{0}'\n".format(tournament)
for row in standings:
print row
if __name__ == '__main__':
tournaments = [["World Cup", 10], ["Private Tournament", 7]]
for t in tournaments:
print "\n\n TESTING TOURNAMENT '{}' WITH {} PLAYERS".format(t[0], t[1])
setupTournament(t[0])
testReportMatches(t[0], t[1])
print "Success! All tests pass!"