from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = 'Gneezy game with no time pressure and the incentive to lie' class Constants(BaseConstants): name_in_url = 'GD_NTP' players_per_group = None num_rounds = 1 A1_payoff = 2.5 A2_payoff = 3 B1_payoff = 7.5 B2_payoff = 2.5 class Subsession(BaseSubsession): pass class Group(BaseGroup): def assign_type(self): players=self.get_players() for i in range(len(players)): if i == 0: players[i].type = 'R1' if i == 1: players[i].type = 'R2' if i >= 2: players[i].type = 'S' def set_payoffs(self): players= self.get_players() R1choice = players[0].choice R2choice = players[1].choice for p in players: if p.type == 'S' and p.message == '1': p.choice = R1choice if p.type == 'S' and p.message == '2': p.choice = R2choice if players[0].message == '2': players[3].choice = R1choice if players[1].message == '1': players[3].choice = R2choice for q in players: if q.choice == 'A' and q.type == 'S': q.payoff = Constants.A1_payoff if q.choice == 'B' and q.type == 'S': q.payoff = Constants.B1_payoff if q.choice == 'A' and q.type == 'R1': q.payoff = Constants.A2_payoff if q.choice == 'B' and q.type == 'R2': q.payoff = Constants.B2_payoff if q.choice == 'A' and q.type == 'R2': q.payoff = Constants.A2_payoff if q.choice == 'B' and q.type == 'R1': q.payoff = Constants.B2_payoff if q.type == 'S' and (q.message == '' or q.message == None): q.payoff = 0 def all_same_message(self): players=self.get_players() messages=[p.message for p in players] # intilize a null list unique_msg = [] # traverse for all elements for x in messages: # check if exists in unique_msg or not if x not in unique_msg: unique_msg.append(x) if '1' not in unique_msg: players[0].message='2' if '2' not in unique_msg: players[1].message='1' if not players[0].message: players[0].message='1' if not players[1].message: players[1].message='2' def set_expiry(self): players=self.get_players() for p in players: p.expiry_time=300 class Player(BasePlayer): type = models.StringField() message = models.StringField(choices=[['1', 'Message 1: "Option A will earn you more than Option B."'], ['2', 'Message 2: "Option B will earn you more than Option A."']], widget=widgets.RadioSelect) choice = models.StringField(choices=[['A', 'Option A'], ['B', 'Option B']], widget=widgets.RadioSelect) expiry_time = models.FloatField()