from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants import random class Introduction(Page): """Description of the game: How to play and returns expected""" pass class Contribute(Page): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['contribution'] class ContributeWaitPage(WaitPage): def after_all_players_arrive(self): group = self.group group.roll_dice= random.randint(1, 6) if group.roll_dice < 3: group.factor=0 else: group.factor=1.5 body_text = "Waiting for other participants to contribute." class Dice(Page): """Player 2 rolls dice""" def is_displayed(self): return self.player.id_in_group == 2 class DiceWaitPage(WaitPage): body_text = "Player 2 id rolling the Dice " class DiceResults(Page): """Players see what the dice got""" class ResultsWaitPage (WaitPage): def after_all_players_arrive(self): group = self.group players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = sum(contributions) group.individual_share = ((group.total_contribution * Constants.multiplier)* self.group.factor)/ Constants.players_per_group for p in players: p.payoff = Constants.endowment - p.contribution + group.individual_share class Results(Page): """Players payoff: How much each has earned""" def vars_for_template(self): return { 'total_earnings': self.group.total_contribution * Constants.multiplier* self.group.factor, } page_sequence = [ Introduction, Contribute, ContributeWaitPage, Dice, DiceWaitPage, DiceResults, ResultsWaitPage, Results ]