from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Maxim Ott' doc = """ Experiment for the lecture "Strategische Interaktion" by Prof. Dr. Sandra Ludwig. G or L. """ class Constants(BaseConstants): name_in_url = 'SI_exp01' players_per_group = 2 num_rounds = 1 payoff_meyou_GG = c(1) payoff_meyou_LL = c(4) payoff_meyou_GL = c(5) payoff_meyou_LG = c(0) class Subsession(BaseSubsession): def creating_session(self): self.group_randomly() # Note: Stupid python list indexing[start=zero, end=exclusive!] print('in creating_session') if self.round_number == 1: self.session.vars['exp01_paying_players'] = random.sample(range(0,self.session.num_participants,1), 2) # print('set the paying players to', self.session.vars['exp01_paying_players']) def vars_for_admin_report(self): all_choices_ind = sorted([p.choice for p in self.get_players()]) count_G = all_choices_ind.count('G') count_L = all_choices_ind.count('L') # choices_ind = [count_G, count_L] choices_ind_percent = [ 100 * count_G / (count_G + count_L), 100 * count_L / (count_G + count_L)] count_GG = count_LL = count_GL = 0 for g in self.get_groups(): if g.get_player_by_id(1).choice == g.get_player_by_id(2).choice == 'G': count_GG = count_GG + 1 elif g.get_player_by_id(1).choice == g.get_player_by_id(2).choice == 'L': count_LL = count_LL + 1 else: count_GL = count_GL + 1 choices_grp = [count_GG, count_LL, count_GL] return {'choices_ind': choices_ind, 'choices_ind_percent': choices_ind_percent, 'choices_grp': choices_grp, 'paying_players': [ self.get_players()[self.session.vars['exp01_paying_players'][0]].participant.label, self.get_players()[self.session.vars['exp01_paying_players'][0]].payoff, self.get_players()[self.session.vars['exp01_paying_players'][1]].participant.label, self.get_players()[self.session.vars['exp01_paying_players'][1]].payoff ]} class Group(BaseGroup): def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) if p1.choice == p2.choice == 'G': p1.payoff = Constants.payoff_meyou_GG p2.payoff = Constants.payoff_meyou_GG elif p1.choice == p2.choice == 'L': p1.payoff = Constants.payoff_meyou_LL p2.payoff = Constants.payoff_meyou_LL elif p1.choice == 'L' and p2.choice == 'G': p1.payoff = Constants.payoff_meyou_LG p2.payoff = Constants.payoff_meyou_GL elif p1.choice == 'G' and p2.choice == 'L': p1.payoff = Constants.payoff_meyou_GL p2.payoff = Constants.payoff_meyou_LG for player in self.get_players(): player.participant.vars['exp01_my_choice'] = player.choice player.participant.vars['exp01_others_choice'] = self.get_player_by_id(player.id_in_group % 2 + 1).choice player.participant.vars['exp01_my_payoff'] = player.payoff # # Save payoffs for live payout # self.session.vars['exp01_paying_players_payoff'] = [ # self.session.get_players()[self.session.vars['exp01_paying_players'][0]].payoff, # self.session.get_players()[self.session.vars['exp01_paying_players'][1]].payoff # ] class Player(BasePlayer): choice = models.StringField( choices=['G', 'L'], label = "Für was entscheiden Sie sich?", widget=widgets.RadioSelect )