def game_to_payoffs(game: Game) -> List[np.ndarray]: """Turn a noncooperative game into strategic form through calculation of payoff arrays. Args: game (Game): Noncooperative game, all players must have a finite number of actioms. Returns: List[np.ndarray]: List of payoff arrays defining the game. """ num_act = [len(ac) for ac in game.actions] payoffs = [None] * game.N for i, player in enumerate(game.players): payoff_i = np.zeros(num_act) # generate all possible types of action indices for a in product(*[range(n_i) for n_i in num_act]): payoff_i[a] = game.U_i(i, a) payoffs[i] = payoff_i return payoffs
def __init__(self, players: List[StrategicPlayer]): Game.__init__(self, players) self.payoffs: List[np.ndarray] = [p.payoff for p in self.players]
def test_verify_game(self): self.assertRaises(ValueError, verify_player_list, Game([])) self.assertRaises(ValueError, verify_player_list, Game([Player('0', 0, Actions()), Player('1', 2, Actions())]))
def __init__(self, players: List[Player]): Game.__init__(self, players)
def __init__(self, players, board): Game.__init__(self, players) self.board = board
def __init__(self, players: List[CongestionPlayer], r_m: int): Game.__init__(self, players) self.r_m: int = r_m
def __init__(self, players): Game.__init__(self, players)