Replicator Games¶
The replicator_game.c and replicator_game.h files handle the functionality of defining the game being played for replicator dynamics simulations.
Constants¶
- CACHE_NONE¶
This constant indicates that nothing should be cached. It is a cache_mask.
- CACHE_PROFILES¶
This constant indicates that only the strategy profiles should be cached. It is a cache_mask.
- CACHE_PAYOFFS¶
This constant indicates that only the payoffs should be cached. It is a cache_mask.
- CACHE_ALL¶
This constant indicates that both the profiles and payoffs should be cached. It is equivalent to CACHE_PROFILES | CACHE_PAYOFFS. It is a cache_mask.
Types¶
- cache_mask¶
This type is an unsigned int. It is specially named to indicate that one of CACHE_NONE, CACHE_PROFILES, CACHE_PAYOFFS, or CACHE_ALL should be used.
- double *(*payoff_function)(int players, int *strategy_profile)¶
This type defines the signature for a payoff function that takes a strategy profile and returns an array of payoff values.
- strategyprofiles_t¶
This is an alias for the StrategyProfiles struct.
- payoffcache_t¶
This is an alias for the PayoffCache struct.
- struct StrategyProfiles¶
This struct holds the information for strategy profiles (tuples of interaction possibility)
- int StrategyProfiles.count¶
This is the number of profiles the struct holds.
- int StrategyProfiles.size¶
This is the size of each profile.
- int* StrategyProfiles.types¶
This is an array of types (the number of types for player i is in the ith entry). The size member indicates the size of this array.
- int StrategyProfiles.has_cached_info¶
This is a flag to indicate whether the struct has cached information stored. It is used for the StrategyProfiles_destroy() function.
- int** StrategyProfiles.profiles¶
This is an array of the possible strategy profiles. It has size stored in count and each element has size from the size member.
- int*** StrategyProfiles.player_strategy_profiles¶
This is an array of the possible strategy profiles sorted by players participating in them. It has the size defined by the size member. The first dimension corresponds to the player. The second dimension corresponds to the number of strategies for that player (size count/types[i]). The third dimension is a list of the profiles in which that strategy participates, represented by indices referring to the StrategyProfiles.profiles list.
- struct Game¶
This struct holds data about the game being played under the dynamics.
- int Game.populations¶
This is how many populations the game has.
- int Game.players¶
This is how many players there are in the game.
- int* Game.types¶
This is a list, for each player, how many strategies that player has.
- payoff_function Game.payoffs¶
This is the function that returns a payoff vector for a certain strategy profile in the game.
- struct PayoffCache¶
This is a struct that holds a cache of pre-calculated payoff vectors.
- int PayoffCache.count¶
This is how many items are in the cache.
- int PayoffCache.has_cached_info¶
This is a flag to indicate that the cache has information in it that should be freed.
- int PayoffCache.free_profiles¶
This is a flag to indicate that the profiles are cached and should be freed.
- payoff_function PayoffCache.payoffs¶
This is the payoff function that generates the payoffs.
- strategyprofiles_t* PayoffCache.profiles¶
This is the pointer to the cache of strategy profiles.
- double** PayoffCache.payoff_cache¶
This is the cache of payoff vectors. Each payoff vector is an array of doubles, and the collection is an array of those arrays.
Functions¶
StrategyProfiles¶
- strategyprofiles_t * StrategyProfiles_create(int players, int *types, cache_mask cache)¶
This creates a strategyprofiles_t struct for the requisite number of players.
The types parameter is a list of number of strategies that each player has.
The cache parameter is how much of the profiles and payoffs to cache.
- int * StrategyProfiles_getProfile(strategyprofiles_t *sprofs, int num)¶
This returns the strategy profile corresponding to the num`th entry in the :c:data:`sprofs array.
- int * StrategyProfiles_getPlayerProfile(strategyprofiles_t *sprofs, int player, int strategy, int num)¶
This returns the num`th strategy profile that player :c:data:`player‘s strategy strategy is involved in.
- int StrategyProfiles_getPlayerProfileNumber(strategyprofiles_t *sprofs, int player, int strategy, int num)¶
This returns the index in the profile list of sprofs that the num`th strategy profile of player :c:data:`player‘s strategy strategy is involved in.
- void StrategyProfiles_destroy(strategyprofiles_t *sprofs)¶
This frees all data associated with sprofs.
Game¶
- game_t * Game_create(int players, int populations, int *types, payoff_function payoffs)¶
This creates a game_t struct based on the requested data.
The number of populations must either be 1 or equal to the number of players.
The parameter types is a list of the number of strategies for each player.
The parameter payoffs is the payoff function for the game.
- strategyprofiles_t * Game_StrategyProfiles_create(game_t *game, cache_mask cache)¶
This creates a strategyprofiles_t struct from the data already present in a game_t struct.
PayoffCache¶
- payoffcache_t * PayoffCache_create(game_t *game, strategyprofiles_t *profiles, cache_mask do_cache)¶
This creates a payoffcache_t struct based on the provided information.
- double * PayoffCache_getPayoffs(payoffcache_t *cache, int profile_index)¶
This returns the payoffs for the cached profile index profile_index.
- void PayoffCache_destroy(payoffcache_t *cache)¶
This frees all data associated with cache.