Ejemplo n.º 1
0
  def __init__(
      self,
      params: Mapping[str, Any],
      network: Optional[dynamic_routing_utils.Network] = None,
      vehicles: Optional[List[dynamic_routing_utils.Vehicle]] = None,
      perform_sanity_checks: bool = True,
  ):
    """Initiliaze the game.

    Args:
      params: game parameters. It should define max_num_time_step and
        time_step_length.
      network: the network of the game.
      vehicles: a list of the vehicle. Their origin and their destination should
        be road sections of the game. The number of vehicles in the list sets
        the num_players attribute.
      perform_sanity_checks: set the perform_sanity_checks attribute.
    """
    max_num_time_step = params["max_num_time_step"]
    time_step_length = params["time_step_length"]
    self.network = network if network else dynamic_routing_data.BRAESS_NETWORK
    self._vehicles = (
        vehicles
        if vehicles else dynamic_routing_data.BRAESS_NETWORK_VEHICLES_DEMAND)
    self.network.check_list_of_vehicles_is_correct(self._vehicles)
    self.perform_sanity_checks = perform_sanity_checks
    self.time_step_length = time_step_length
    game_info = pyspiel.GameInfo(
        num_distinct_actions=self.network.num_actions(),
        max_chance_outcomes=0,
        num_players=len(self._vehicles),
        min_utility=-max_num_time_step - 1,
        max_utility=0,
        max_game_length=max_num_time_step)
    super().__init__(_GAME_TYPE, game_info, params if params else {})
Ejemplo n.º 2
0
 def __init__(self, params: Mapping[str, Any] = _DEFAULT_PARAMS):
     game_info = pyspiel.GameInfo(num_distinct_actions=_NUM_ACTIONS,
                                  max_chance_outcomes=max(
                                      params["size"], _NUM_CHANCE),
                                  num_players=_NUM_PLAYERS,
                                  min_utility=-np.inf,
                                  max_utility=+np.inf,
                                  utility_sum=0.0,
                                  max_game_length=params["horizon"])
     super().__init__(_GAME_TYPE, game_info, params)
     self.size = params["size"]
     self.horizon = params["horizon"]
Ejemplo n.º 3
0
 def __init__(self, params=_DEFAULT_PARAMS):
     max_game_length = params["max_game_length"]
     super().__init__(
         _GAME_TYPE,
         pyspiel.GameInfo(num_distinct_actions=2,
                          max_chance_outcomes=2,
                          num_players=2,
                          min_utility=np.min(_PAYOFF) * max_game_length,
                          max_utility=np.max(_PAYOFF) * max_game_length,
                          utility_sum=0.0,
                          max_game_length=max_game_length), params)
     self._termination_probability = params["termination_probability"]
Ejemplo n.º 4
0
 def __init__(self, params: Mapping[str, Any] = _DEFAULT_PARAMS):
     self.size = get_param("size", params)
     self.horizon = get_param("horizon", params)
     flat_reward_matrix = np.fromstring(get_param("reward_matrix", params),
                                        dtype=np.float,
                                        sep=" ")
     num_players = get_param("players", params)
     if len(flat_reward_matrix) != num_players**2:
         raise ValueError(
             f"Reward matrix passed in flat representation does not represent a "
             f"square matrix: {flat_reward_matrix}")
     self.reward_matrix = flat_reward_matrix.reshape(
         [num_players, num_players])
     self.geometry = get_param("geometry", params)
     game_info = pyspiel.GameInfo(num_distinct_actions=_NUM_ACTIONS,
                                  max_chance_outcomes=max(
                                      self.size * self.size, _NUM_CHANCE),
                                  num_players=num_players,
                                  min_utility=-np.inf,
                                  max_utility=+np.inf,
                                  utility_sum=0.0,
                                  max_game_length=self.horizon)
     super().__init__(_GAME_TYPE, game_info, params)
    chance_mode=pyspiel.GameType.ChanceMode.EXPLICIT_STOCHASTIC,
    information=pyspiel.GameType.Information.PERFECT_INFORMATION,
    utility=pyspiel.GameType.Utility.GENERAL_SUM,
    reward_model=pyspiel.GameType.RewardModel.REWARDS,
    max_num_players=_NUM_PLAYERS,
    min_num_players=_NUM_PLAYERS,
    provides_information_state_string=False,
    provides_information_state_tensor=False,
    provides_observation_string=False,
    provides_observation_tensor=False,
    provides_factored_observation_string=False,
    parameter_specification=_DEFAULT_PARAMS)
_GAME_INFO = pyspiel.GameInfo(num_distinct_actions=2,
                              max_chance_outcomes=2,
                              num_players=2,
                              min_utility=0.,
                              max_utility=np.inf,
                              utility_sum=0.0,
                              max_game_length=9999)


class Action(enum.IntEnum):
    COOPERATE = 0
    DEFECT = 1


class Chance(enum.IntEnum):
    CONTINUE = 0
    STOP = 1

Ejemplo n.º 6
0
    dynamics=pyspiel.GameType.Dynamics.SEQUENTIAL,
    chance_mode=pyspiel.GameType.ChanceMode.DETERMINISTIC,
    information=pyspiel.GameType.Information.PERFECT_INFORMATION,
    utility=pyspiel.GameType.Utility.ZERO_SUM,
    reward_model=pyspiel.GameType.RewardModel.TERMINAL,
    max_num_players=_NUM_PLAYERS,
    min_num_players=_NUM_PLAYERS,
    provides_information_state_string=True,
    provides_information_state_tensor=False,
    provides_observation_string=True,
    provides_observation_tensor=True,
    parameter_specification={})
_GAME_INFO = pyspiel.GameInfo(num_distinct_actions=_NUM_CELLS,
                              max_chance_outcomes=0,
                              num_players=2,
                              min_utility=-1.0,
                              max_utility=1.0,
                              utility_sum=0.0,
                              max_game_length=_NUM_CELLS)


class TicTacToeGame(pyspiel.Game):
    """A Python version of the Tic-Tac-Toe game."""
    def __init__(self, params=None):
        super().__init__(_GAME_TYPE, _GAME_INFO, params or dict())

    def new_initial_state(self):
        """Returns a state corresponding to the start of a game."""
        return TicTacToeState(self)

    def make_py_observer(self, iig_obs_type=None, params=None):
Ejemplo n.º 7
0
    dynamics=pyspiel.GameType.Dynamics.SEQUENTIAL,
    chance_mode=pyspiel.GameType.ChanceMode.EXPLICIT_STOCHASTIC,
    information=pyspiel.GameType.Information.IMPERFECT_INFORMATION,
    utility=pyspiel.GameType.Utility.ZERO_SUM,
    reward_model=pyspiel.GameType.RewardModel.TERMINAL,
    max_num_players=_NUM_PLAYERS,
    min_num_players=_NUM_PLAYERS,
    provides_information_state_string=True,
    provides_information_state_tensor=True,
    provides_observation_string=True,
    provides_observation_tensor=True,
    provides_factored_observation_string=True)
_GAME_INFO = pyspiel.GameInfo(
    num_distinct_actions=2,  # 0 = Pass, 1 = Bet
    max_chance_outcomes=3,  # The deck has 3 cards
    num_players=2,
    min_utility=-2.0,
    max_utility=2.0,
    utility_sum=0.0,
    max_game_length=3)  # e.g. Pass, Bet, Bet


class KuhnPokerGame(pyspiel.Game):
    """A Python version of Kuhn poker."""
    def __init__(self, params=None):
        super().__init__(_GAME_TYPE, _GAME_INFO, params or dict())

    def new_initial_state(self):
        """Returns a state corresponding to the start of a game."""
        return KuhnPokerState(self)

    def make_py_observer(self, iig_obs_type=None, params=None):
Ejemplo n.º 8
0
    dynamics=pyspiel.GameType.Dynamics.SEQUENTIAL,
    chance_mode=pyspiel.GameType.ChanceMode.EXPLICIT_STOCHASTIC,
    information=pyspiel.GameType.Information.IMPERFECT_INFORMATION,
    utility=pyspiel.GameType.Utility.ZERO_SUM,
    reward_model=pyspiel.GameType.RewardModel.TERMINAL,
    max_num_players=_NUM_PLAYERS,
    min_num_players=_NUM_PLAYERS,
    provides_information_state_string=True,
    provides_information_state_tensor=True,
    provides_observation_string=True,
    provides_observation_tensor=True,
    provides_factored_observation_string=True)
_GAME_INFO = pyspiel.GameInfo(num_distinct_actions=len(Action),
                              max_chance_outcomes=len(_DECK),
                              num_players=_NUM_PLAYERS,
                              min_utility=-2.0,
                              max_utility=2.0,
                              utility_sum=0.0,
                              max_game_length=3)  # e.g. Pass, Bet, Bet


class KuhnPokerGame(pyspiel.Game):
    """A Python version of Kuhn poker."""
    def __init__(self, params=None):
        super().__init__(_GAME_TYPE, _GAME_INFO, params or dict())

    def new_initial_state(self):
        """Returns a state corresponding to the start of a game."""
        return KuhnPokerState(self)

    def make_py_observer(self, iig_obs_type=None, params=None):
Ejemplo n.º 9
0
    dynamics=pyspiel.GameType.Dynamics.SEQUENTIAL,
    chance_mode=pyspiel.GameType.ChanceMode.DETERMINISTIC,
    information=pyspiel.GameType.Information.IMPERFECT_INFORMATION, 
    utility=pyspiel.GameType.Utility.GENERAL_SUM,
    reward_model=pyspiel.GameType.RewardModel.TERMINAL,
    max_num_players=_MAX_PLAYERS,
    min_num_players=2,
    provides_information_state_string=False,
    provides_information_state_tensor=True,
    provides_observation_string=False,
    provides_observation_tensor=False,
    provides_factored_observation_string=False)
_GAME_INFO = pyspiel.GameInfo(
    num_distinct_actions=_NUM_REGIONS,
    max_chance_outcomes=0,
    num_players=5,
    min_utility=-10.0,
    max_utility=10.0,
    utility_sum=0.0,
    max_game_length=_MAX_PLAYERS)


class CastilloGameState(pyspiel.State):
    """El Grande Castillo Game - subgame of El Grande which decides on the optimum positioning of
    pieces moved from the Castillo in the scoring phase of rounds 3/6/9
    Parameters:
    players - number of players between 1 and 5
    rewards - array of 1st/2nd/3rd place triples, one per region
    board - string of lowercase alpha characters representing numbers of caballeros per player/region: 'A'==0 and region 0 has castillo cabs
    grandes - array of grande region IDs from 1.._NUM_REGIONS
    king - region ID of king
    """
Ejemplo n.º 10
0
    dynamics=pyspiel.GameType.Dynamics.MEAN_FIELD,
    chance_mode=pyspiel.GameType.ChanceMode.EXPLICIT_STOCHASTIC,
    information=pyspiel.GameType.Information.PERFECT_INFORMATION,
    utility=pyspiel.GameType.Utility.GENERAL_SUM,
    reward_model=pyspiel.GameType.RewardModel.REWARDS,
    max_num_players=_NUM_PLAYERS,
    min_num_players=_NUM_PLAYERS,
    provides_information_state_string=True,
    provides_information_state_tensor=False,
    provides_observation_string=True,
    provides_observation_tensor=True,
    parameter_specification=_DEFAULT_PARAMS)
_GAME_INFO = pyspiel.GameInfo(num_distinct_actions=_NUM_ACTIONS,
                              max_chance_outcomes=max(_SIZE, _NUM_CHANCE),
                              num_players=_NUM_PLAYERS,
                              min_utility=-np.inf,
                              max_utility=+np.inf,
                              utility_sum=0.0,
                              max_game_length=_HORIZON)


class MFGCrowdModellingGame(pyspiel.Game):
    """A Mean Field Crowd Modelling game.


    A game starts by an initial chance node that select the initial state
    of the MFG.
    Then the game sequentially alternates between:
      - An action selection node (Where the player Id >= 0)
      - A Mean Field node (the player id is pyspiel.PlayerId.MEAN_FIELD)
      - A chance node (the player id is pyspiel.PlayerId.CHANCE)