from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'rockpaperscissorsVHBincomplete' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 5 SYMBOLS = ['Rock', 'Paper', 'Scissors'] class Subsession(BaseSubsession): pass class Group(BaseGroup): is_draw = models.BooleanField(initial= False) class Player(BasePlayer): hand = models.StringField(choices=C.SYMBOLS, label="Please choose your hand") result= models.StringField() win = models.BooleanField(initial=False) num_wins = models.IntegerField() num_wins_opp = models.IntegerField() ### Method def calculate_group_winner(group: Group): ### ''' Determine which player won, lost or whether it is a draw store outcome in result-variable and win-variable of player ''' def calculate_group_result(group: Group): ''' Determine how many times the player won, how many times the opponent won and how many times it was a draw ''' ### player1 = group.get_players()[0] player2 = group.get_players()[1] player1.num_wins = sum([p.win for p in player1.in_all_rounds()]) player2.num_wins = sum([p.win for p in player2.in_all_rounds()]) player1.num_wins_opp = player2.num_wins player2.num_wins_opp = player1.num_wins # PAGES class GameRound(Page): ''' here something needs to be done ''' class WaitForOther(WaitPage): @staticmethod def after_all_players_arrive(group): calculate_group_winner(group) class Results(Page): @staticmethod def vars_for_template(player): return dict( outcome= player.result ) class WaitForOtherFinal(WaitPage): @staticmethod def is_displayed(player: Player): return player.round_number==C.NUM_ROUNDS @staticmethod def after_all_players_arrive(group): calculate_group_result(group) class FinalResults(Page): ''' display page only in the final round ''' @staticmethod def vars_for_template(player): return dict( ''' retrieve how many times player won, the opponent one, and number of draws and store it in the variables below ''' outcome_self= outcome_other= num_draws = ) page_sequence = [GameRound, WaitForOther, Results, WaitForOtherFinal, FinalResults]