Spaces:
Paused
Paused
File size: 1,812 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | from otree.api import *
doc = """
Simple trust game
"""
class C(BaseConstants):
NAME_IN_URL = 'trust_simple'
PLAYERS_PER_GROUP = 2
NUM_ROUNDS = 1
ENDOWMENT = cu(10)
MULTIPLIER = 3
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
sent_amount = models.CurrencyField(
min=cu(0),
max=C.ENDOWMENT,
doc="""Amount sent by P1""",
label="How much do you want to send to participant B?",
)
sent_back_amount = models.CurrencyField(
doc="""Amount sent back by P2""", label="How much do you want to send back?"
)
class Player(BasePlayer):
pass
# FUNCTIONS
def sent_back_amount_choices(group: Group):
return currency_range(0, group.sent_amount * C.MULTIPLIER, 1)
def set_payoffs(group: Group):
p1 = group.get_player_by_id(1)
p2 = group.get_player_by_id(2)
p1.payoff = C.ENDOWMENT - group.sent_amount + group.sent_back_amount
p2.payoff = group.sent_amount * C.MULTIPLIER - group.sent_back_amount
# PAGES
class Introduction(Page):
pass
class Send(Page):
form_model = 'group'
form_fields = ['sent_amount']
@staticmethod
def is_displayed(player: Player):
return player.id_in_group == 1
class WaitForP1(WaitPage):
pass
class SendBack(Page):
form_model = 'group'
form_fields = ['sent_back_amount']
@staticmethod
def is_displayed(player: Player):
return player.id_in_group == 2
@staticmethod
def vars_for_template(player: Player):
group = player.group
return dict(tripled_amount=group.sent_amount * C.MULTIPLIER)
class ResultsWaitPage(WaitPage):
after_all_players_arrive = set_payoffs
class Results(Page):
pass
page_sequence = [Introduction, Send, WaitForP1, SendBack, ResultsWaitPage, Results]
|