Created
April 16, 2020 23:17
-
-
Save KevinOConnor/06295e78f7187ad694bfa37e1cb78d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment