from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class FirstPage(Page): def is_displayed(self): return self.round_number == 1 class Welcome(FirstPage): pass class Instructions(FirstPage): def vars_for_template(self): return dict( turns=int(C.NUM_ROUNDS / 2), instructionsMatrix=C.INSTRUCTIONSMATRIX, rounds_range=C.ROUNDS_RANGE, large_pile_practice=C.LARGE_PILES, small_pile_practice=C.SMALL_PILES, large_pile_practice_second=C.LARGE_PILES[1], small_pile_practice_second=C.SMALL_PILES[1], large_pile_practice_third=C.LARGE_PILES[2], small_pile_practice_third=C.SMALL_PILES[2], large_pile_practice_last=C.LARGE_PILES[-2], small_pile_practice_last=C.SMALL_PILES[-2], large_pile_practice_pass=C.LARGE_PILES[-1], small_pile_practice_pass=C.SMALL_PILES[-1] ) class Practice1Page1(FirstPage): pass class Practice1Page2(FirstPage): def vars_for_template(self): return dict( large_pile_practice=C.LARGE_PILES, small_pile_practice=C.SMALL_PILES, large_pile_practice_second=C.LARGE_PILES[1], small_pile_practice_second=C.SMALL_PILES[1], ) class Practice1Page3(FirstPage): def vars_for_template(self): return dict( large_pile_practice=C.LARGE_PILES, small_pile_practice=C.SMALL_PILES, large_pile_practice_second=C.LARGE_PILES[1], small_pile_practice_second=C.SMALL_PILES[1], ) class Practice1Page4(FirstPage): def vars_for_template(self): return dict( large_pile_practice=C.LARGE_PILES, small_pile_practice=C.SMALL_PILES, large_pile_practice_second=C.LARGE_PILES[1], small_pile_practice_second=C.SMALL_PILES[1], ) class Practice2Page1(FirstPage): def vars_for_template(self): return dict( large_pile_practice_second=C.LARGE_PILES[1], small_pile_practice_second=C.SMALL_PILES[1], large_pile_practice_third=C.LARGE_PILES[2], small_pile_practice_third=C.SMALL_PILES[2] ) class Practice2Page2(FirstPage): def vars_for_template(self): return dict( large_pile_practice_last=C.LARGE_PILES[-2], small_pile_practice_last=C.SMALL_PILES[-2], large_pile_practice_pass=C.LARGE_PILES[-1], small_pile_practice_pass=C.SMALL_PILES[-1], ) class Practice2Page3(FirstPage): pass class WaitPage1(WaitPage): def is_displayed(self): return self.round_number == 1 wait_for_all_groups = True class Decision(Page): form_model = 'player' form_fields = ['take'] def is_displayed(self): if self.player.id_in_group == 1 and self.round_number % 2 != 0 and self.group.game_on: return True elif self.player.id_in_group == 2 and self.round_number % 2 == 0 and self.group.game_on: return True else: return False def vars_for_template(self): return dict( game = self.subsession.game, game_node = self.subsession.game_node, large_pile = C.LARGE_PILES[self.subsession.game_node - 1], small_pile = C.SMALL_PILES[self.subsession.game_node - 1] ) def before_next_page(self): return self.group.stop_game(), self.group.set_payoffs() class WaitPage2(WaitPage): def after_all_players_arrive(self): pass class Results(Page): def is_displayed(self): if self.round_number in C.LAST_ROUNDS: return True else: return False def vars_for_template(self): return dict( game=self.subsession.game, last_node=self.group.last_node, large_pile=C.LARGE_PILES[self.group.last_node-1], small_pile=C.SMALL_PILES[self.group.last_node-1], large_pile_pass=C.LARGE_PILES[-1], small_pile_pass=C.SMALL_PILES[-1] ) class WaitPage3(WaitPage): def is_displayed(self): if self.round_number in C.LAST_ROUNDS: return True else: return False wait_for_all_groups = True after_all_players_arrive = 'advance_game' page_sequence = [ Welcome, Instructions, #Practice1Page1, #Practice1Page2, #Practice1Page3, #Practice1Page4, #Practice2Page1, #Practice2Page2, WaitPage1, Decision, WaitPage2, Results, WaitPage3 ]