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 = None 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)] return {'choices_ind': choices_ind, 'choices_ind_percent': choices_ind_percent, '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 ]} def set_payoffs(self): for p in self.get_players(): p.payoff = 0 p1 = self.get_players()[self.session.vars['exp01_paying_players'][0]] p2 = self.get_players()[self.session.vars['exp01_paying_players'][1]] 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.get_players()[self.session.vars['exp01_paying_players'][0]].payoff, self.get_players()[self.session.vars['exp01_paying_players'][1]].payoff ] class Group(BaseGroup): pass class Player(BasePlayer): choice = models.StringField( choices=['G', 'L'], label = "Für was entscheiden Sie sich?", widget=widgets.RadioSelect )