from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): """Description of the game: How to play and returns expected""" def is_displayed(self): return self.round_number == 1 class Contribute(Page): """Player: Choose how much to contribute""" form_model = models.Player form_fields = ['contribution'] timeout_submission = {'contribution': Constants.endowment / 2} def vars_for_template(self): return { 'players_in_your_group': self.group.get_players() } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() body_text = "Ждем остальных..." class Results(Page): """Players payoff: How much each has earned""" form_model = models.Player def get_form_fields(self): if self.player.id_in_group == 1: return ['punish_P2','punish_P3'] if self.player.id_in_group == 2: return ['punish_P1', 'punish_P3'] if self.player.id_in_group == 3: return ['punish_P1', 'punish_P2'] def vars_for_template(self): return { 'total_earnings': self.group.total_contribution * Constants.multiplier, 'others': self.player.get_others_in_group() } def before_next_page(self): for g in self.subsession.get_groups(): g.execute_punishment() class Punished(Page): """Players payoff: How much each has earned""" def vars_for_template(self): label_one ='' label_two = '' punishment_one = 0 punishment_two = 0 if self.player.id_in_group == 1: label_one = self.group.get_player_by_id(2).participant.label label_two = self.group.get_player_by_id(3).participant.label punishment_one = self.group.get_player_by_id(2).punish_P1 punishment_two = self.group.get_player_by_id(3).punish_P1 if self.player.id_in_group == 2: label_one = self.group.get_player_by_id(1).participant.label label_two = self.group.get_player_by_id(3).participant.label punishment_one = self.group.get_player_by_id(1).punish_P2 punishment_two = self.group.get_player_by_id(3).punish_P2 if self.player.id_in_group == 3: label_one = self.group.get_player_by_id(1).participant.label label_two = self.group.get_player_by_id(2).participant.label punishment_one = self.group.get_player_by_id(1).punish_P3 punishment_two = self.group.get_player_by_id(2).punish_P3 my_punishment = (self.player.punish_P1 + self.player.punish_P2 + self.player.punish_P3)/2 they_punished_me = punishment_one+punishment_two my_payoff = self.player.payoff - they_punished_me - my_punishment return { 'label_one': label_one, 'label_two': label_two, 'punishment_one': punishment_one, 'punishment_two': punishment_two, 'my_punishment': my_punishment, 'my_payoff': my_payoff } class TotalResult(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): pay_round = self.session.vars['paying_round'] p = self.player.in_all_rounds() return { 'paying_round': pay_round, } page_sequence = [ Introduction, Contribute, ResultsWaitPage, Results, ResultsWaitPage, Punished, TotalResult ]