from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Joseph Lee' doc = """ NTUEXP: three_ring for Task 2 """ class Constants(BaseConstants): name_in_url = 'three_ring_t2' players_per_group = 3 num_rounds = 5 deletelink = c(110) remainlink = c(100) totime = 60 player1 = 'J' player2 = 'N' player3 = 'T' class Subsession(BaseSubsession): # Group the participants def creating_session(self): if self.round_number == 1: self.group_randomly() else: self.group_like_round(1) # Initialize the network for g in self.get_groups(): g.AB = 1 g.BA = 1 g.AC = 1 g.CA = 1 g.BC = 1 g.CB = 1 # initialize the counter to see how many people have chosen not to delete any link g.CO = 0 g.done = 0 for p in self.get_players(): p.rpayoff = c(0) p.participant.vars['PayoffT2b'] = c(0) class Group(BaseGroup): AB = models.IntegerField() AC = models.IntegerField() # AD = models.IntegerField() BA = models.IntegerField() BC = models.IntegerField() # BD = models.IntegerField() CA = models.IntegerField() CB = models.IntegerField() # CD = models.IntegerField() # DA = models.IntegerField() # DB = models.IntegerField() # DC = models.IntegerField() CO = models.IntegerField() done = models.IntegerField() p1sel = models.StringField( widget=widgets.RadioSelect, blank=True, ) p2sel = models.StringField( widget=widgets.RadioSelect, blank=True, ) p3sel = models.StringField( widget=widgets.RadioSelect, blank=True, ) def check_empty(self): if self.AB == 0 and self.AC == 0 and self.BC == 0: return 1 else: return 0 def set_var_1(self): p1 = self.get_player_by_id(1) if self.p1sel == 'Delete the link with Participant ' + Constants.player2: p1.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AB = 0 g.BA = 0 elif self.p1sel == 'Delete the link with Participant ' + Constants.player3: p1.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AC = 0 g.CA = 0 else: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO += 1 # check for empty network if self.check_empty() == 1: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = Constants.players_per_group def set_var_2(self): p2 = self.get_player_by_id(2) if self.p2sel == 'Delete the link with Participant ' + Constants.player1: p2.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AB = 0 g.BA = 0 elif self.p2sel == 'Delete the link with Participant ' + Constants.player3: p2.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BC = 0 g.CB = 0 else: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO += 1 if self.check_empty() == 1: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = Constants.players_per_group def set_var_3(self): p3 = self.get_player_by_id(3) if self.p3sel == 'Delete the link with Participant ' + Constants.player1: p3.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AC = 0 g.CA = 0 elif self.p3sel == 'Delete the link with Participant ' + Constants.player2: p3.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BC = 0 g.CB = 0 else: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO += 1 if self.check_empty() == 1: for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = Constants.players_per_group def set_payoff(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) if self.AB == 1: p1.participant.vars['PayoffT2b'] += Constants.remainlink p2.participant.vars['PayoffT2b'] += Constants.remainlink if self.AC == 1: p1.participant.vars['PayoffT2b'] += Constants.remainlink p3.participant.vars['PayoffT2b'] += Constants.remainlink if self.BC == 1: p2.participant.vars['PayoffT2b'] += Constants.remainlink p3.participant.vars['PayoffT2b'] += Constants.remainlink for p in self.get_players(): p.rpayoff = p.participant.vars['PayoffT2b'] p.payoff = p.rpayoff # - ws Apr def set_done(self): pass class Player(BasePlayer): rpayoff = models.CurrencyField()