Skip to content

Instantly share code, notes, and snippets.

@mjc-gh
Forked from KevinOConnor/tournaments.py
Created April 17, 2020 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjc-gh/eb75018f44fd22b8894c776b59220bf3 to your computer and use it in GitHub Desktop.
Save mjc-gh/eb75018f44fd22b8894c776b59220bf3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import itertools, copy
HOUSE_VALUE = {
'stark': 42,
'greyjoy': 20,
'martel': 25,
'baratheon': 40,
'lannister': 35,
'tyrell': 28
}
HOUSES = sorted(HOUSE_VALUE.keys())
NUM_GAMES = 6
NUM_PLAYERS = 6
NUM_HOUSES = len(HOUSES)
GAME_PERMUTATIONS = list(itertools.permutations(range(NUM_HOUSES)))
class Tournament:
def __init__(self):
self.games = []
self.house_avail_to_player = [[True] * NUM_HOUSES
for i in range(NUM_PLAYERS)]
def tournament_from_next_game(self, game):
new_tourn = copy.deepcopy(self)
new_tourn.games.append(game)
for player, house in enumerate(game):
new_tourn.house_avail_to_player[player][house] = False
return new_tourn
def gen_tournaments(self, round_no):
res = []
for game in GAME_PERMUTATIONS:
if game[0] != round_no or game[round_no] != 0:
continue
for player, house in enumerate(game):
if not self.house_avail_to_player[player][house]:
break
else:
res.append(self.tournament_from_next_game(game))
return res
def main():
tournaments = [Tournament()]
for round_no in range(NUM_GAMES):
next_tournaments = []
for tourn in tournaments:
new = tourn.gen_tournaments(round_no)
next_tournaments.extend(new)
print round_no, len(next_tournaments)
tournaments = next_tournaments
main()
@mjc-gh
Copy link
Author

mjc-gh commented Apr 23, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment