-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournament.py
executable file
·59 lines (50 loc) · 1.88 KB
/
tournament.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import itertools
from redbot import RedBot
PLAYFIELDS = ['playfields/basic.txt']
MAX_PLAYERS_IN_TOURNAMENT = 4
REPEAT = 2
class Tournament():
def __init__(self, playfields, players, repeat=REPEAT):
self.playfields = playfields
self.players = players
self.repeat = repeat
self.playfied_scores = dict()
self.players_in_tournament = min(len(players), MAX_PLAYERS_IN_TOURNAMENT)
self.total_scores = dict()
for player in players:
self.total_scores[player] = 0
for playfield in playfields:
self.playfied_scores[playfield] = dict()
for player in players:
self.playfied_scores[playfield][player] = 0
def run(self):
groups = itertools.permutations(self.players, self.players_in_tournament)
for group in groups:
for i in range(self.repeat):
for playfield in self.playfields:
redbot_game = RedBot(playfield, group)
redbot_game.play()
# TODO: store results, make video of images
for winner in redbot_game.get_winners():
self.playfied_scores[playfield][winner] += 1
self.total_scores[winner] += 1
def get_winners_of_playfield(self, playfield):
maxpoints = max(self.playfied_scores[playfield].values())
return [player for player in self.players if self.playfied_scores[playfield][player] == maxpoints]
def get_winners(self):
maxpoints = max(self.total_scores.values())
return [player for player in self.players if self.total_scores[player] == maxpoints]
def main():
tournament = Tournament(PLAYFIELDS, sys.argv[1:])
tournament.run()
winners = tournament.get_winners()
if len(winners) == 1:
print("Winner of the tournament is %s" % winners[0])
else:
print("Winners of the tournament are " + ", ".join(winners))
print tournament.playfied_scores
if __name__ == '__main__':
main()