from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'battle_of_sexes' players_per_group = 4 num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if (p.id_in_group % 2) == 0: p.type = 2 p.partner = p.id_in_group - 1 else: p.type = 1 p.partner = p.id_in_group + 1 class Group(BaseGroup): pass class Player(BasePlayer): partner = models.IntegerField() choice = models.IntegerField(choices=[(1, 'Opera'), (2, 'Football match')]) type = models.IntegerField() matching = models.BooleanField() def set_payoff(self): others = self.group.get_players() other = others[self.partner - 1] if self.choice == 1 and other.choice == 1: self.matching = True if self.type == 1: self.payoff = c(20) else: self.payoff = c(10) if self.choice == 2 and other.choice == 2: self.matching = True if self.type == 1: self.payoff = c(10) else: self.payoff = c(20) if (self.choice == 1 and other.choice == 2) or (self.choice == 2 and other.choice == 1): self.matching = False self.payoff = c(0)