176 lines
5.8 KiB
Python
176 lines
5.8 KiB
Python
|
from otree.api import (
|
||
|
models,
|
||
|
widgets,
|
||
|
BaseConstants,
|
||
|
BaseSubsession,
|
||
|
BaseGroup,
|
||
|
BasePlayer,
|
||
|
Currency as c,
|
||
|
currency_range,
|
||
|
)
|
||
|
import random
|
||
|
|
||
|
|
||
|
doc = """
|
||
|
Modified dictator game
|
||
|
"""
|
||
|
|
||
|
|
||
|
class Constants(BaseConstants):
|
||
|
name_in_url = 'dictator_modif_class_v2'
|
||
|
players_per_group = None
|
||
|
num_rounds = 8
|
||
|
|
||
|
instructions_template = 'dictator_modif_class_v2/instructions.html'
|
||
|
|
||
|
exchangerate = 0.1
|
||
|
|
||
|
# Initial amount allocated to each player
|
||
|
#endowment = c(100)
|
||
|
#multiplier = 3
|
||
|
|
||
|
dgm1 = {1: [40, 3, 1], 2: [40, 1, 3], 3: [60, 2, 1], 4: [60, 1, 2],
|
||
|
5: [75, 2, 1], 6: [75, 1, 2], 7: [60, 1, 1], 8: [100, 1, 1]}
|
||
|
|
||
|
dgm2 = {8: [40, 3, 1], 7: [40, 1, 3], 6: [60, 2, 1], 5: [60, 1, 2],
|
||
|
4: [75, 2, 1], 3: [75, 1, 2], 2: [60, 1, 1], 1: [100, 1, 1]}
|
||
|
|
||
|
dgm3 = {8: [40, 3, 1], 2: [40, 1, 3], 1: [60, 2, 1], 4: [60, 1, 2],
|
||
|
3: [75, 2, 1], 6: [75, 1, 2], 5: [60, 1, 1], 7: [100, 1, 1]}
|
||
|
|
||
|
dgm4 = {5: [40, 3, 1], 6: [40, 1, 3], 7: [60, 2, 1], 8: [60, 1, 2],
|
||
|
1: [75, 2, 1], 2: [75, 1, 2], 3: [60, 1, 1], 4: [100, 1, 1]}
|
||
|
|
||
|
dgm5 = {4: [40, 3, 1], 1: [40, 1, 3], 6: [60, 2, 1], 3: [60, 1, 2],
|
||
|
8: [75, 2, 1], 5: [75, 1, 2], 2: [60, 1, 1], 7: [100, 1, 1]}
|
||
|
|
||
|
|
||
|
|
||
|
class Subsession(BaseSubsession):
|
||
|
pass
|
||
|
# def creating_session(subsession):
|
||
|
# # Random Matching
|
||
|
# subsession.group_randomly()
|
||
|
|
||
|
class Group(BaseGroup):
|
||
|
pass
|
||
|
# dot1 = models.IntegerField()
|
||
|
# s1 = models.IntegerField()
|
||
|
# g1 = models.IntegerField()
|
||
|
# send1 = models.IntegerField()
|
||
|
# send2 = models.IntegerField()
|
||
|
# keep1 = models.IntegerField()
|
||
|
# keep2 = models.IntegerField()
|
||
|
# roundselect = models.IntegerField()
|
||
|
# def dict_dgm(self):
|
||
|
# if self.id_in_subsession == 1 or self.id_in_subsession == 6 or self.id_in_subsession == 11:
|
||
|
# self.dot1 = Constants.dgm1[self.round_number-1][0]
|
||
|
# self.s1 = Constants.dgm1[self.round_number-1][1]
|
||
|
# self.g1 = Constants.dgm1[self.round_number-1][2]
|
||
|
# elif self.id_in_subsession == 2 or self.id_in_subsession == 7 or self.id_in_subsession == 12:
|
||
|
# self.dot1 = Constants.dgm2[self.round_number-1][0]
|
||
|
# self.s1 = Constants.dgm2[self.round_number-1][1]
|
||
|
# self.g1 = Constants.dgm2[self.round_number-1][2]
|
||
|
# elif self.id_in_subsession == 3 or self.id_in_subsession == 8 or self.id_in_subsession == 13:
|
||
|
# self.dot1 = Constants.dgm3[self.round_number-1][0]
|
||
|
# self.s1 = Constants.dgm3[self.round_number-1][1]
|
||
|
# self.g1 = Constants.dgm3[self.round_number-1][2]
|
||
|
# elif self.id_in_subsession == 4 or self.id_in_subsession == 9 or self.id_in_subsession == 14:
|
||
|
# self.dot1 = Constants.dgm4[self.round_number-1][0]
|
||
|
# self.s1 = Constants.dgm4[self.round_number-1][1]
|
||
|
# self.g1 = Constants.dgm4[self.round_number-1][2]
|
||
|
# elif self.id_in_subsession == 5 or self.id_in_subsession == 10 or self.id_in_subsession == 15:
|
||
|
# self.dot1 = Constants.dgm5[self.round_number-1][0]
|
||
|
# self.s1 = Constants.dgm5[self.round_number-1][1]
|
||
|
# self.g1 = Constants.dgm5[self.round_number-1][2]
|
||
|
# sent_amount = models.CurrencyField(
|
||
|
# min=0, max=Constants.endowment, doc="""Amount sent by P1"""
|
||
|
# )
|
||
|
#
|
||
|
# sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", min=c(0))
|
||
|
|
||
|
def sent_back_amount_max(self):
|
||
|
return self.sent_amount * Constants.multiplier
|
||
|
|
||
|
def set_payoffs(self):
|
||
|
p1 = self.get_player_by_id(1)
|
||
|
p2 = self.get_player_by_id(2)
|
||
|
|
||
|
self.send1 = p1.sent_amount
|
||
|
self.send2 = p2.sent_amount
|
||
|
self.keep1 = p1.keep_amount
|
||
|
self.keep2 = p2.keep_amount
|
||
|
|
||
|
if self.round_number == 8:
|
||
|
self.roundselect = random.randint(1, 8)
|
||
|
if p1.dictator == 1:
|
||
|
p1.gain_dgm = 23
|
||
|
p2.gain_dgm = 25
|
||
|
else:
|
||
|
p1.gain_dgm = 233
|
||
|
p2.gain_dgm = 255
|
||
|
|
||
|
|
||
|
# p1.payoff = self.keep1 * self.s1
|
||
|
# p2.payoff = self.send1 * self.g1
|
||
|
#
|
||
|
# p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount
|
||
|
# p2.payoff = self.sent_amount * Constants.multiplier - self.sent_back_amount
|
||
|
|
||
|
class Player(BasePlayer):
|
||
|
|
||
|
game_num = models.IntegerField()
|
||
|
app_sequence_select = models.IntegerField()
|
||
|
app_sequence_select_n = models.StringField()
|
||
|
questionnaire_before = models.IntegerField()
|
||
|
|
||
|
|
||
|
# def role(self):
|
||
|
# if self.id_in_group == 1:
|
||
|
# return 'dictator1'
|
||
|
# if self.id_in_group == 2:
|
||
|
# return 'dictator2'
|
||
|
# role1 = models.StringField()
|
||
|
# dictator = models.IntegerField()
|
||
|
dgm_selected = models.IntegerField()
|
||
|
round_selected = models.IntegerField()
|
||
|
|
||
|
r1 = models.IntegerField(
|
||
|
blank=False
|
||
|
)
|
||
|
r2 = models.IntegerField(
|
||
|
blank=False
|
||
|
)
|
||
|
r3 = models.IntegerField(
|
||
|
blank=False
|
||
|
)
|
||
|
r4 = models.IntegerField(
|
||
|
blank=False
|
||
|
)
|
||
|
keep_amount = models.IntegerField(
|
||
|
blank=False, initial=0, doc="""Vous gardez""" )
|
||
|
sent_amount = models.IntegerField(
|
||
|
blank=False, initial=0, doc="""Vous donnez""")
|
||
|
|
||
|
dot1 = models.IntegerField()
|
||
|
s1 = models.IntegerField()
|
||
|
g1 = models.IntegerField()
|
||
|
|
||
|
dot1_select = models.IntegerField()
|
||
|
s1_select = models.IntegerField()
|
||
|
g1_select = models.IntegerField()
|
||
|
keep_select = models.IntegerField()
|
||
|
sent_select = models.IntegerField()
|
||
|
|
||
|
gain_dgm = models.IntegerField()
|
||
|
gain_joueur2 = models.IntegerField()
|
||
|
|
||
|
gain_dgm_eur = models.FloatField()
|
||
|
gain_joueur2_eur = models.FloatField()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|