Spaces:
Paused
Paused
File size: 1,562 Bytes
e40dce0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | from otree.api import *
doc = """
This bargaining game involves 2 players. Each demands for a portion of some
available amount. If the sum of demands is no larger than the available
amount, both players get demanded portions. Otherwise, both get nothing.
"""
class C(BaseConstants):
NAME_IN_URL = 'bargaining'
PLAYERS_PER_GROUP = 2
NUM_ROUNDS = 1
AMOUNT_SHARED = cu(100)
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
total_requests = models.CurrencyField()
class Player(BasePlayer):
request = models.CurrencyField(
doc="""
Amount requested by this player.
""",
min=0,
max=C.AMOUNT_SHARED,
label="Please enter an amount from 0 to 100",
)
# FUNCTIONS
def set_payoffs(group: Group):
players = group.get_players()
group.total_requests = sum([p.request for p in players])
if group.total_requests <= C.AMOUNT_SHARED:
for p in players:
p.payoff = p.request
else:
for p in players:
p.payoff = cu(0)
def other_player(player: Player):
return player.get_others_in_group()[0]
# PAGES
class Introduction(Page):
pass
class Request(Page):
form_model = 'player'
form_fields = ['request']
class ResultsWaitPage(WaitPage):
after_all_players_arrive = set_payoffs
class Results(Page):
@staticmethod
def vars_for_template(player: Player):
return dict(other_player_request=other_player(player).request)
page_sequence = [Introduction, Request, ResultsWaitPage, Results]
|