from otree.api import Page from otree.api import WaitPage from otree.api import ( Currency as c, currency_range, SubmissionMustFail, Submission ) from .models import Constants, Group, Player class Instruction(Page): def is_displayed(self): return self.round_number == 1 class Decision_Row(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = 'group' form_fields = ['player1_decision'] class Decision_Column(Page): def is_displayed(self): return self.player.id_in_group == 2 form_model = 'group' form_fields = ['player2_decision'] class Waitforall(WaitPage): def after_all_players_arrive(self): p1 = self.group.get_player_by_id(1) p2 = self.group.get_player_by_id(2) # Check player decisions and assign payoffs accordingly if self.group.player1_decision == 'U' and self.group.player2_decision == 'L': p1.round_payoff = Constants.Row_Payoff[0][0] p2.round_payoff = Constants.Column_Payoff[0][0] p2.other_payoff = Constants.Row_Payoff[0][0] p1.other_payoff = Constants.Column_Payoff[0][0] elif self.group.player1_decision == 'U' and self.group.player2_decision == 'N': p1.round_payoff = Constants.Row_Payoff[0][1] p2.round_payoff = Constants.Column_Payoff[0][1] p2.other_payoff = Constants.Row_Payoff[0][1] p1.other_payoff = Constants.Column_Payoff[0][1] elif self.group.player1_decision == 'U' and self.group.player2_decision == 'R': p1.round_payoff = Constants.Row_Payoff[0][2] p2.round_payoff = Constants.Column_Payoff[0][2] p2.other_payoff = Constants.Row_Payoff[0][2] p1.other_payoff = Constants.Column_Payoff[0][2] elif self.group.player1_decision == 'M' and self.group.player2_decision == 'L': p1.round_payoff = Constants.Row_Payoff[1][0] p2.round_payoff = Constants.Column_Payoff[1][0] p2.other_payoff = Constants.Row_Payoff[1][0] p1.other_payoff = Constants.Column_Payoff[1][0] elif self.group.player1_decision == 'M' and self.group.player2_decision == 'N': p1.round_payoff = Constants.Row_Payoff[1][1] p2.round_payoff = Constants.Column_Payoff[1][1] p2.other_payoff = Constants.Row_Payoff[1][1] p1.other_payoff = Constants.Column_Payoff[1][1] elif self.group.player1_decision == 'M' and self.group.player2_decision == 'R': p1.round_payoff = Constants.Row_Payoff[1][2] p2.round_payoff = Constants.Column_Payoff[1][2] p2.other_payoff = Constants.Row_Payoff[1][2] p1.other_payoff = Constants.Column_Payoff[1][2] elif self.group.player1_decision == 'D' and self.group.player2_decision == 'L': p1.round_payoff = Constants.Row_Payoff[2][0] p2.round_payoff = Constants.Column_Payoff[2][0] p2.other_payoff = Constants.Row_Payoff[2][0] p1.other_payoff = Constants.Column_Payoff[2][0] elif self.group.player1_decision == 'D' and self.group.player2_decision == 'N': p1.round_payoff = Constants.Row_Payoff[2][1] p2.round_payoff = Constants.Column_Payoff[2][1] p2.other_payoff = Constants.Row_Payoff[2][1] p1.other_payoff = Constants.Column_Payoff[2][1] else: p1.round_payoff = Constants.Row_Payoff[2][2] p2.round_payoff = Constants.Column_Payoff[2][2] p2.other_payoff = Constants.Row_Payoff[2][2] p1.other_payoff = Constants.Column_Payoff[2][2] for p in self.group.get_players(): app1_list = p.participant.vars.get('app1_payoffs',[]) app1_list.append(p.round_payoff) p.participant.vars['app1_payoffs'] = app1_list for p in self.group.get_players(): if self.round_number == Constants.num_rounds: payoff_list = p.participant.vars.get('payoffs', []) app1_list = p.participant.vars.get('app1_payoffs', []) payoff_list.append(app1_list) p.participant.vars['payoffs'] = payoff_list class Results(Page): def before_next_page(self): for p in self.group.get_players(): self.participant.vars['groupid'] = self.player.id_in_group def vars_for_template(self): round = self.round_number return{'round': round} page_sequence = [Instruction, Decision_Row, Decision_Column, Waitforall, Results]