from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c ) import random """ Sim for Hawk Dove Game """ class Constants(BaseConstants): name_in_url = 'HawkDovePossessor' players_per_group = 2 num_rounds = 10 #endowment m = 25 # value of resource v = 50 # cost of conflict (each) c = 50 # cost of delay (each) a = 10 # payoff if 1 player fights and the other retreats""", Hawk_payoff = 75 # Hawk_payoff = Constants.m + Constants.v Dove_payoff = 25 # Dove_payoff = Constants.m # payoff if both players fight or both retreat Fight_payoff = 0 # Fight_payoff = Constants.m + Constants.v/2 - Constants.c Split_payoff = 40 # Split_payoff = Constants.m + Constants.v/2 - Constants.a class Subsession(BaseSubsession): def creating_session(self): self.group_randomly() class Group(BaseGroup): pass class Player(BasePlayer): def other_player(self): return self.get_others_in_group()[0] def role(self): return 'Possessor' if self.id_in_group == 1 else 'Challenger' decision = models.StringField( choices=['Fight', 'Do NOT Fight'], doc="""This player's decision""", widget=widgets.RadioSelect ) def set_payoff(self): payoff_matrix = { 'Fight': { 'Fight': Constants.m + Constants.v/2 - Constants.c, 'Do NOT Fight': Constants.m + Constants.v }, 'Do NOT Fight': { 'Fight': Constants.m, 'Do NOT Fight': Constants.m + Constants.v/2 - Constants.a } } self.payoff = payoff_matrix[self.decision][self.other_player().decision]