from otree.api import * class Constants(BaseConstants): name_in_url = 'cournot_wiederholt' players_per_group = 2 num_rounds = 2 instructions_template = 'Cournot_Wettbewerb_wiederholt/instructions.html' # Total production capacity of all players total_capacity = 60 marginal_cost= 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): unit_price = models.FloatField() total_units = models.FloatField(doc="""Total units produced by all players""") class Player(BasePlayer): units = models.FloatField( min=0, doc="""Quantity of units to produce""", label="Wieviele Güter wollen Sie produzieren??", ) # FUNCTIONS def set_payoffs(group: Group): players = group.get_players() group.total_units = sum([p.units for p in players]) group.unit_price = max(Constants.total_capacity - group.total_units,0) for p in players: p.payoff = (group.unit_price-Constants.marginal_cost) * p.units def other_player(player: Player): return player.get_others_in_group()[0] # PAGES class Introduction(Page): pass class Decide(Page): form_model = 'player' form_fields = ['units'] class ResultsWaitPage(WaitPage): body_text = "Waiting for the other participant to decide." after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_units=other_player(player).units) class CombinedResults(Page): @staticmethod def is_displayed(player: Player): return player.round_number==Constants.num_rounds @staticmethod def vars_for_template(player: Player): total_Profit=0 for temp_player in player.in_all_rounds(): total_Profit=total_Profit+temp_player.payoff return { "Gewinn": total_Profit } page_sequence = [Introduction, Decide, ResultsWaitPage, Results,CombinedResults]