from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Joseph Lee' doc = """ NTUEXP: five_ring for Task 2 """ class Constants(BaseConstants): name_in_url = 'five_ring_t2' players_per_group = 5 num_rounds = 5 deletelink = c(110) remainlink = c(100) totime = 60 player1 = 'J' player2 = 'N' player3 = 'T' player4 = 'Y' player5 = 'E' 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 = 0 g.CA = 0 g.AD = 1 g.DA = 1 g.AE = 0 g.EA = 0 g.BC = 1 g.CB = 1 g.BD = 0 g.DB = 0 g.BE = 0 g.EB = 0 g.CD = 0 g.DC = 0 g.CE = 1 g.EC = 1 g.DE = 1 g.ED = 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() AE = models.IntegerField() BA = models.IntegerField() BC = models.IntegerField() BD = models.IntegerField() BE = models.IntegerField() CA = models.IntegerField() CB = models.IntegerField() CD = models.IntegerField() CE = models.IntegerField() DA = models.IntegerField() DB = models.IntegerField() DC = models.IntegerField() DE = models.IntegerField() EA = models.IntegerField() EB = models.IntegerField() EC = models.IntegerField() ED = models.IntegerField() CO = models.IntegerField() done = models.IntegerField() p1sel = models.StringField( widget=widgets.RadioSelect ) p2sel = models.StringField( widget=widgets.RadioSelect ) p3sel = models.StringField( widget=widgets.RadioSelect ) p4sel = models.StringField( widget=widgets.RadioSelect ) p5sel = models.StringField( widget=widgets.RadioSelect ) def check_empty(self): if self.AB == 0 and self.AC == 0 and self.AD == 0 and self.AE == 0 and self.BC == 0 and self.BD == 0 and self.BE == 0 and self.CD == 0 and self.CE == 0 and self.DE == 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 elif self.p1sel == 'Delete the link with Participant ' + Constants.player4: p1.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AD = 0 g.DA = 0 elif self.p1sel == 'Delete the link with Participant ' + Constants.player5: p1.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AE = 0 g.EA = 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 elif self.p2sel == 'Delete the link with Participant ' + Constants.player4: p2.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BD = 0 g.DB = 0 elif self.p2sel == 'Delete the link with Participant ' + Constants.player5: p2.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BE = 0 g.EB = 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 elif self.p3sel == 'Delete the link with Participant ' + Constants.player4: p3.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.CD = 0 g.DC = 0 elif self.p3sel == 'Delete the link with Participant ' + Constants.player5: p3.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.CE = 0 g.EC = 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_4(self): p4 = self.get_player_by_id(4) if self.p4sel == 'Delete the link with Participant ' + Constants.player1: p4.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AD = 0 g.DA = 0 elif self.p4sel == 'Delete the link with Participant ' + Constants.player2: p4.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BD = 0 g.DB = 0 elif self.p4sel == 'Delete the link with Participant ' + Constants.player3: p4.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.CD = 0 g.DC = 0 elif self.p4sel == 'Delete the link with Participant ' + Constants.player5: p4.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.DE = 0 g.ED = 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_5(self): p5 = self.get_player_by_id(5) if self.p5sel == 'Delete the link with Participant ' + Constants.player1: p5.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.AE = 0 g.EA = 0 elif self.p5sel == 'Delete the link with Participant ' + Constants.player2: p5.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.BE = 0 g.EB = 0 elif self.p5sel == 'Delete the link with Participant ' + Constants.player3: p5.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.CE = 0 g.EC = 0 elif self.p5sel == 'Delete the link with Participant ' + Constants.player4: p5.participant.vars['PayoffT2b'] += Constants.deletelink for g in self.in_rounds(self.round_number, Constants.num_rounds): g.CO = 0 g.DE = 0 g.ED = 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) p4 = self.get_player_by_id(4) p5 = self.get_player_by_id(5) 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.AD == 1: p1.participant.vars['PayoffT2b'] += Constants.remainlink p4.participant.vars['PayoffT2b'] += Constants.remainlink if self.AE == 1: p1.participant.vars['PayoffT2b'] += Constants.remainlink p5.participant.vars['PayoffT2b'] += Constants.remainlink if self.BC == 1: p2.participant.vars['PayoffT2b'] += Constants.remainlink p3.participant.vars['PayoffT2b'] += Constants.remainlink if self.BD == 1: p2.participant.vars['PayoffT2b'] += Constants.remainlink p4.participant.vars['PayoffT2b'] += Constants.remainlink if self.BE == 1: p2.participant.vars['PayoffT2b'] += Constants.remainlink p5.participant.vars['PayoffT2b'] += Constants.remainlink if self.CD == 1: p3.participant.vars['PayoffT2b'] += Constants.remainlink p4.participant.vars['PayoffT2b'] += Constants.remainlink if self.CE == 1: p3.participant.vars['PayoffT2b'] += Constants.remainlink p5.participant.vars['PayoffT2b'] += Constants.remainlink if self.DE == 1: p4.participant.vars['PayoffT2b'] += Constants.remainlink p5.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()