from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = """ This is a one-shot "Prisoner's Dilemma". Two players are asked separately whether they want to cooperate or defect. Their choices directly determine the payoffs. """ class Constants(BaseConstants): name_in_url = 'd_prisoners_dilemma3' players_per_group = 2 num_rounds = 1 instructions_template = 'd_prisoners_dilemma3/Instructions.html' CC_payoff = c(6) CD_payoff = c(0) DC_payoff = c(10) DD_payoff = c(2) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): guessp = models.IntegerField( choices=[ [1,'Human'], [0,'Computer'], ], doc="""This player's guess""", widget=widgets.RadioSelectHorizontal ) message = models.LongStringField() decision = models.StringField( choices=['C', 'D'], doc="""This player's decision""", widget=widgets.RadioSelect ) guessPD_payoff = models.IntegerField() def other_player(self): return self.get_others_in_group()[0] def set_guess_payoff(self): self.guessPD_payoff = 5 * self.guessp def set_payoff(self): payoff_matrix = { 'C': { 'C': Constants.CC_payoff, 'D': Constants.CD_payoff }, 'D': { 'C': Constants.DC_payoff, 'D': Constants.DD_payoff } } self.payoff = self.guessPD_payoff + payoff_matrix[self.decision][self.other_player().decision] self.participant.vars['Post2'] = self.payoff