from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Introduction(Page): def is_displayed(self): return self.round_number == 1 class DecisionPage(Page): form_model = 'player' form_fields = ['strategy'] class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): players = self.group.get_players() actions = [] for p in players: actions.append(p.strategy) for p in players: if p.id_in_group == 1: other = 2 else: other = 1 if actions[p.id_in_group-1] == 1 and actions[other-1] == 1: p.payoff = 12 p.round_payoff = 12 elif actions[p.id_in_group-1] == 7 and actions[other-1] == 7: p.payoff = 0 p.round_payoff = 0 elif actions[p.id_in_group-1] == 1 and actions[other-1] == 7: p.payoff = 0 p.round_payoff = 0 elif actions[p.id_in_group-1] == 4 and actions[other-1] >= 5: p.payoff = 21 p.round_payoff = 21 elif actions[p.id_in_group-1] >= 5 and actions[other-1] == 4: p.payoff = 1 p.round_payoff = 1 elif actions[p.id_in_group-1] == actions[other-1] - 1: p.payoff = 21 p.round_payoff = 21 elif actions[p.id_in_group-1] == actions[other-1] + 1: p.payoff = 1 p.round_payoff = 1 else: p.payoff = 11 p.round_payoff = 11 class Results(Page): def vars_for_template(self): if self.player.id_in_group == 1: return { 'other_player': self.group.get_player_by_id(2) } else: return { 'other_player': self.group.get_player_by_id(1) } page_sequence = [ Introduction, DecisionPage, ResultsWaitPage, Results ]