def play_single_dilemma(player_1: Team, player_2: Team, player_1_score: int, player_2_score: int, player_1_moves: str, player_2_moves: str, suppress_exceptions: bool = True): player_1_round_score = 0 player_2_round_score = 0 try: player_1_move = player_1.move(player_1_moves, player_2_moves, player_1_score, player_2_score, player_2.team_name) except Exception: player_1_move = 'n' if not suppress_exceptions: raise try: player_2_move = player_2.move(player_2_moves, player_1_moves, player_2_score, player_1_score, player_1.team_name) except Exception: player_2_move = 'n' if not suppress_exceptions: raise if player_1_move not in GLOBALS.ACCEPTABLE_RESPONSES or player_1_move == 'n': player_1_round_score = GLOBALS.CRASH player_1_move = 'n' print( f"{player_1.team_name} crashed in a match against {player_2.team_name}, deducting {GLOBALS.CRASH * -1} points as a result" ) if player_2_move not in GLOBALS.ACCEPTABLE_RESPONSES or player_1_move == 'n': player_2_round_score = GLOBALS.CRASH player_2_move = 'n' print( f"{player_2.team_name} crashed in a match against {player_1.team_name}, deducting {GLOBALS.CRASH * -1} points as a result" ) if (player_1_move == GLOBALS.COLLUDE) and (player_2_move == GLOBALS.COLLUDE): player_1_round_score += GLOBALS.REWARD player_2_round_score += GLOBALS.REWARD elif (player_1_move == GLOBALS.COLLUDE) and (player_2_move == GLOBALS.BETRAY): player_1_round_score += GLOBALS.SUCKER player_2_round_score += GLOBALS.TEMPTATION elif (player_1_move == GLOBALS.BETRAY) and (player_2_move == GLOBALS.COLLUDE): player_1_round_score += GLOBALS.TEMPTATION player_2_round_score += GLOBALS.SUCKER elif (player_1_move == GLOBALS.BETRAY) and (player_2_move == GLOBALS.BETRAY): player_1_round_score += GLOBALS.PUNISHMENT player_2_round_score += GLOBALS.PUNISHMENT return player_1_round_score,\ player_2_round_score,\ player_1_move,\ player_2_move
def load_modules(module_names: List[str]): """ Given a list of strings with paths to modules, load them. Return a list of teams, which are instances of Team from teamclass.py """ teams = [] for team_number, module_name in enumerate(module_names): teams.append(Team(module_name, team_number)) return teams
def load_modules(module_names): ''' Given a list of strings with paths to modules, load them. Return a list of teams, which are instances of Team from teamclass.py ''' teams = [False for i in range(len(module_names))] for count in range(len(module_names)): teams[count] = Team(module_names[count]) assert False not in teams, "There's a False somewhere in teams" return teams