from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants import random # before the game starts players are matched based on their score on Value Survey. ID_score=3 is just a random number, Still need to decide for this '''class GroupingWait(WaitPage): group_by_arrival_time = True def get_players_for_group(self, waiting_players): col_players = [] idv_players = [] for player in waiting_players: idv_score = player.participant.vars['score'] print(idv_score) if idv_score >= 3: idv_players.append(player) else: col_players.append(player) if len(idv_players) >= 2: first_idv_player = idv_players[0] second_idv_player = idv_players[1] return [first_idv_player, second_idv_player] elif len(col_players) >= 2: first_col_player = col_players[0] second_col_player = col_players[1] return [first_col_player, second_col_player] ''' class Introduction(Page): timeout_seconds = 100 def is_displayed(self): return (self.round_number == 1) class Strategy(Page): form_model = 'player' form_fields = ['strategy_0', 'strategy_1', 'strategy_2', 'strategy_3', 'strategy_4'] def is_displayed(self): return (self.round_number == 1) def before_next_page(self): self.player.player_strategy() class Strategy_Results(Page): def is_displayed(self): return (self.round_number == 1) class Decision(Page): form_model = 'player' form_fields = ['decision'] def is_displayed(self): return not self.participant.vars.get('finished') class ResultsWaitPage(WaitPage): def is_displayed(self): return not self.participant.vars.get('finished') def after_all_players_arrive(self): group = self.group group.is_last_round = (random.random() < Constants.stopping_probability) if group.is_last_round and self.round_number > 1: for player in group.get_players(): player.participant.vars['finished'] = True player.participant.vars['last_round'] = self.round_number for p in self.group.get_players(): p.set_payoff() p.set_roundstrategy() class Results(Page): def is_displayed(self): return not self.participant.vars.get('finished') def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() return { 'my_decision': self.player.decision.lower(), 'other_player': self.player.other_player().decision.lower(), 'same_choice': self.player.decision == self.player.other_player().decision, } class End(Page): def is_displayed(self): return (self.round_number == Constants.num_rounds) def vars_for_template(self): player_in_all_rounds = self.player.in_rounds(1, self.participant.vars['last_round']) decisions = [p.decision for p in player_in_all_rounds] other_decisions = [p.other_player().decision for p in player_in_all_rounds] my_payoffs = [p.payoff for p in player_in_all_rounds] previous_player = self.player.in_all_rounds() total = sum([p.payoff for p in player_in_all_rounds]) self.participant.vars['total'] = total strategies = [p.roundstrategy for p in player_in_all_rounds] return { 'my_decisions': decisions, 'other_player': other_decisions, 'my_payoffs': my_payoffs, 'total': total, 'previous_player': player_in_all_rounds, 'strategies': strategies } page_sequence = [ #GroupingWait, Introduction, Strategy, Strategy_Results, Decision, ResultsWaitPage, Results, End, ]