from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random doc = """ A Modified Version of the Moonlighting Game. See: Abbink, Klaus & Irlenbusch, Bernd & Renner, Elke, 2000. "The moonlighting game: An experimental study on reciprocity and retribution," Journal of Economic Behavior & Organization: 42(2), P. 265-277 """ class Constants(BaseConstants): name_in_url = 'MoonlightingGame' players_per_group = 2 num_rounds = 1 instructions_template = 'MoonlightingGame/instructions.html' instructionsp2_template = 'MoonlightingGame/instructionsp2.html' # Initial amount allocated to each player endowment = c(20) multiplier = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): # Action = models.StringField( ## choices=[ ## ('altruistic (2:0.5,0:0.3,-2:0.2)'), ## ('selfish (2:0.3,0:0.4,-2:0.3)'), ## ] ##) ## ## Action = models.IntegerField( choices=[ ## [1, 'altruistic (2:0.5,0:0.3,-2:0.2)'], ## [2, 'selfish (2:0.3,0:0.4,-2:0.3)'] ## ]) ## Action = models.IntegerField() ## def Action_choices(group): ## import random ## value1 = random.choices([2,0,-2],[0.5,0.3,0.2],k=1) ## value2 = random.choices([2,0,-2],[0.3,0.4,0.3],k=1) ## choices=[ ## [value1[0], 'altruistic (2:0.5,0:0.3,-2:0.2)'], ## [value2[0], 'selfish (2:0.3,0:0.4,-2:0.3)'] ## ] ## return choices def ActionCH(group): ActionCH = group.get_field_display('Action') return dict( ActionCh=ActionCh ) @staticmethod def vars_for_template(group): ActionCh = get_field_display('Action') return dict( ActionCh=ActionCh ) @staticmethod def before_next_page(player, timeout_happened): player.tripled_apples = player.num_apples * 3 def ActionValue(group): import random value1 = random.choices([2,0,-2],[0.5,0.3,0.3]) value2 = random.choices([2,0,-2],[0.3,0.4,0.3]) if group.Action == 1: ActionValue = value1[0] elif group.Action == 2: ActionValue = value2[0] return ActionValue Action = models.IntegerField( choices=[ [1, 'altruistic (2:0.5,0:0.3,-2:0.2)'], [2, 'selfish (2:0.3,0:0.4,-2:0.3)'] ] ) ## def set_Action(self): ## import random ## value1 = random.choices([2,0,-2],[0.5,0.3,0.3]) ## value2 = random.choices([2,0,-2],[0.3,0.4,0.3]) ## if self.Action == 1: ## ActionResult = models.IntegerField(value1) ## elif self.Action == 2: ## ActionResult = models.IntegerField(value2) ## Reaction = models.StringField( choices=[ ('punish'), ('do not punish'), ]) def set_payoffs(self): import random p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) sl = random.choice([1,2,3,4]) if sl[0] == 1: if p1.Fairness1 == p2.Fairness1: p1.payoff = Constants.endowment - self.Action + self.Reaction + c(5) if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction +c(5) else: p2.payoff = Constants.endowment + self.Action -self.Reaction +c(5) else: p1.payoff = Constants.endowment - self.Action + self.Reaction if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction else: p2.payoff = Constants.endowment + self.Action -self.Reaction elif sl[0] == 2: if p1.Fairness2 == p2.Fairness2: p1.payoff = Constants.endowment - self.Action + self.Reaction +c(5) if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction +c(5) else: p2.payoff = Constants.endowment + self.Action -self.Reaction +c(5) else: p1.payoff = Constants.endowment - self.Action + self.Reaction if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction else: p2.payoff = Constants.endowment + self.Action -self.Reaction elif sl[0] == 3: if p1.Fairness3 == p2.Fairness3: p1.payoff = Constants.endowment - self.Action + self.Reaction +c(5) if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction +c(5) else: p2.payoff = Constants.endowment + self.Action -self.Reaction +c(5) else: p1.payoff = Constants.endowment - self.Action + self.Reaction if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction else: p2.payoff = Constants.endowment + self.Action -self.Reaction else: if p1.Fairness4 == p2.Fairness4: p1.payoff = Constants.endowment - self.Action + self.Reaction +c(5) if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction +c(5) else: p2.payoff = Constants.endowment + self.Action -self.Reaction +c(5) else: p1.payoff = Constants.endowment - self.Action + self.Reaction if self.Action >0: p2.payoff = Constants.endowment + 2 * self.Action -self.Reaction else: p2.payoff = Constants.endowment + self.Action -self.Reaction class Player(BasePlayer): Fairness1 = models.StringField( doc="""Fairness Situation 1""", widget=widgets.RadioSelectHorizontal, choices=['sehr unfair', 'unfair', 'ausgeglichen', 'fair', 'sehr fair'], label = "Spieler 2 hat 0 Punkte zurücküberwiesen.", ) Fairness2 = models.StringField( doc="""Fairness Situation 2""", widget=widgets.RadioSelectHorizontal, choices=['sehr unfair', 'unfair', 'ausgeglichen', 'fair', 'sehr fair'], label = "Spieler 2 hat 5 Punkte zurücküberwiesen.", ) Fairness3 = models.StringField( doc="""Fairness Situation 3""", widget=widgets.RadioSelectHorizontal, choices=['sehr unfair', 'unfair', 'ausgeglichen', 'fair', 'sehr fair'], label = "Spieler 2 hat 10 Punkte zurücküberwiesen.", ) Fairness4 = models.StringField( doc="""Fairness Situation 4""", widget=widgets.RadioSelectHorizontal, choices=['sehr unfair', 'unfair', 'ausgeglichen', 'fair', 'sehr fair'], label = "Spieler 2 hat 15 Punkte zurücküberwiesen.", )