from otree.api import * import random doc = """ One player decides how to divide a certain amount between himself and the other player while the other player simultaneously does the same. Both players are blind to the other's opportunity. Essentially a blind, simultaneous dictator game. """ class C(BaseConstants): NAME_IN_URL = 'Help_colleague' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 1 # Initial amount allocated to the dictator ENDOWMENT = cu(100) participation_fee = cu(200) #track cell sizes SESSION_FIELDS = ['num_winner_winner_pairs', 'num_winner_loser_pairs','num_winner_loser_pairs'] # might need to make some of the constants go to the subsession depending on the code integration class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): is_out = models.BooleanField(initial=False) giving = models.CurrencyField( doc="""Amount player decided to give to a colleague""", min=0, max=C.ENDOWMENT, label="I will provide help to my partner, incurring a personal cost of", ) def other_giving(self): other_player = self.get_others_in_group()[0] return other_player.giving if other_player else None # FUNCTIONS # function to calculate the individual player payoff #def payoff(self): # other_player = self.get_others_in_group()[0] # return C.participation_fee + C.ENDOWMENT + other_player.giving - self.giving # PAGES class instructions(Page): pass class Introduction(Page): pass class Offer(Page): form_model = 'player' form_fields = ['giving'] def vars_for_template(self): player = self other_player = player.get_others_in_group()[0] #determine the winning policy player_vote_result = 'won' if player.participant.vars['policy_vote_result'] == 'winner' else 'lost' other_vote_result = 'won' if other_player.participant.vars['policy_vote_result'] == 'winner' else 'lost' return{ 'endowment': C.ENDOWMENT, 'other_player_vote': other_player.policy_vote, 'player_vote': player.participant.vars['policy_vote'], 'vote_result': 'similar' if player.participant.vars['policy_vote'] == other_player.policy_vote else 'different', 'player_vote_result': player_vote_result, 'other_vote_result': other_vote_result } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): for player in self.group.get_players(): if player.is_out: player.payoff = C.participation_fee else: player.payoff = C.participation_fee + C.ENDOWMENT + player.other_giving() - player.giving class Results(Page): def vars_for_template(self): player = self.player other_player = player.get_others_in_group()[0] return {'other_giving': other_player.giving} page_sequence = [Offer, ResultsWaitPage, Results]