forked from ecbtln/dynamics_sim
-
Notifications
You must be signed in to change notification settings - Fork 3
Games
Andrew F edited this page Aug 6, 2015
·
5 revisions
Here is an example of the Hawk Dove game:
from games.game import Game
class HawkDove(Game):
DEFAULT_PARAMS = dict(v=30, c=60)
STRATEGY_LABELS = ('Hawk', 'Dove')
PLAYER_LABELS = ('Player 1', 'Player 2')
EQUILIBRIA_LABELS = ('All_Hawk', 'All_Dove', 'Hawk_Dove', 'Dove_Hawk')
def __init__(self, v, c, equilibrium_tolerance=0.1):
payoff_matrix = (( (v - c) / 2.0, v),
(0, v / 2.0))
player_dist = (1/2, 1/2)
super(HawkDove, self).__init__(payoff_matrices=payoff_matrix, player_frequencies=player_dist, equilibrium_tolerance=equilibrium_tolerance)
@classmethod
def classify(cls, params, state, tolerance):
p = params
threshold = 1-tolerance
if state[0][0] >= threshold:
return 0
elif state[1][1] >= threshold:
return 1
elif state[1][0] >= threshold:
return 2
elif state[0][1] >= threshold:
return 3
else:
return super(HawkDove, cls).classify(params, state, tolerance)
Determine which game you wish to model and subclass the game class.
First create the defaults for the game.
Next determine the payoff matrices for each player they should be n-dimensional matrices which vary player 1's strategy at the first level, then player 2's strategy at the second level etc...
Call the super class method with the matrices, player distributions, and equilibria.
Override the classification of equilibria method if you wish to classify different equilibria.
The first index of the state determines the player, and the second index determine their strategy.