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. L or R. """ class Constants(BaseConstants): name_in_url = 'SI_exp04' players_per_group = None num_rounds = 1 payoff_meyou_LL = c(9) payoff_meyou_RR = c(7) payoff_meyou_LR = c(-10) payoff_meyou_RL = c(8) class Subsession(BaseSubsession): def creating_session(self): # self.group_randomly() # Note: Stupid python list indexing[start=zero, end=exclusive!] print('In creating_session(): SI_04') if self.round_number == 1: self.session.vars['exp04_paying_players'] = random.sample(range(0,self.session.num_participants,1), 2) # print('set the paying players to', self.session.vars['exp1_paying_players']) def vars_for_admin_report(self): all_choices_ind = sorted([p.choice for p in self.get_players()]) count_L = all_choices_ind.count('L') count_R = all_choices_ind.count('R') # choices_ind = [count_L, count_R] choices_ind_percent = [ 100 * count_L / (count_R + count_L), 100 * count_R / (count_R + count_L)] # count_LL = count_RR = count_LR = 0 # for g in self.get_groups(): # if g.get_player_by_id(1).choice == g.get_player_by_id(2).choice == 'L': # count_LL = count_LL + 1 # elif g.get_player_by_id(1).choice == g.get_player_by_id(2).choice == 'R': # count_RR = count_RR + 1 # else: # count_LR = count_LR + 1 # # choices_grp = [count_LL, count_RR, count_LR] # print('########################################') # print(self.session.vars['paying_players']) # print(self.session.vars['paying_players'][0]) # print(self.session.vars['paying_players'][1]) # print(self.get_players()) # print(self.get_players()[0]) # print(self.get_players()[1]) return {'choices_ind': choices_ind, 'choices_ind_percent': choices_ind_percent, 'paying_players': [ self.get_players()[self.session.vars['exp04_paying_players'][0]].participant.label, self.get_players()[self.session.vars['exp04_paying_players'][0]].payoff, self.get_players()[self.session.vars['exp04_paying_players'][1]].participant.label, self.get_players()[self.session.vars['exp04_paying_players'][1]].payoff ]} def set_payoffs(self): for p in self.get_players(): p.payoff = 0 print('in set_payoffs') p1 = self.get_players()[self.session.vars['exp04_paying_players'][0]] p2 = self.get_players()[self.session.vars['exp04_paying_players'][1]] if p1.choice == p2.choice == 'L': p1.payoff = Constants.payoff_meyou_LL p2.payoff = Constants.payoff_meyou_LL elif p1.choice == p2.choice == 'R': p1.payoff = Constants.payoff_meyou_RR p2.payoff = Constants.payoff_meyou_RR elif p1.choice == 'L' and p2.choice == 'R': p1.payoff = Constants.payoff_meyou_LR p2.payoff = Constants.payoff_meyou_RL elif p1.choice == 'R' and p2.choice == 'L': p1.payoff = Constants.payoff_meyou_RL p2.payoff = Constants.payoff_meyou_LR # for player in self.get_players(): # player.participant.vars['exp04_my_choice'] = player.choice # player.participant.vars['exp04_others_choice'] = self.get_player_by_id(player.id_in_group % 2 + 1).choice # player.participant.vars['exp04_my_payoff'] = player.payoff # Save payoffs for live payout self.session.vars['exp04_paying_players_payoff'] = [ self.get_players()[self.session.vars['exp04_paying_players'][0]].payoff, self.get_players()[self.session.vars['exp04_paying_players'][1]].payoff ] class Group(BaseGroup): pass class Player(BasePlayer): choice = models.StringField( choices=['L', 'R'], label = "Für was entscheiden Sie sich?", widget=widgets.RadioSelect )