class Group(BaseGroup): sent_amount = models.CurrencyField( choices=currency_range(c(0), c(10), c(10))) sent_back_amount = models.CurrencyField( choices=currency_range(c(0), c(15), c(15))) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = Constants.amount_allocated - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * Constants.multiplication_factor - self.sent_back_amount
class Constants(BaseConstants): name_in_url = 'ultimatum' # only one player is in a group players_per_group = None # the number of rounds is configured in 'ultimatum_config.py' num_rounds = CONFIG['num_rounds'] instructions_template = 'ultimatum/Instructions.html' popup_template = 'ultimatum/PopupMessage.html' # maximal amount that can be offered to a player endowment = c(100) payoff_if_rejected = c(0) offer_increment = c(1) # selfish_message = "We indicate that you will probably get a very selfish offer" # generous_message = "We indicate that you will probably get a very generous offer" # average_message = "We indicate that you will probably get an average offer" messages = CONFIG['messages_ultimatum'] # range of all the offers a player can get offer_choices = currency_range(0, endowment, offer_increment) offer_choices_count = len(offer_choices)
class Group(BaseGroup): sent_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, c(1)), doc="""Amount sent by P1""", ) sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", )
class Player(BasePlayer): contribution = models.CurrencyField(choices=currency_range( c(0), c(4), c(2)) # this gives: # [$0.00, $2.00, $4,00] ) def cumulate_contribution(self): #return players' cumulative contribution return sum([p.contribution for p in self.in_all_rounds()]) temp_payoff = models.CurrencyField() #define players' payoff in the round def cumulate_payoff(self): #define players' cumulative payoff return sum([p.temp_payoff for p in self.in_all_rounds()]) payoff = models.CurrencyField() #the realized payoff def contribution_each_player_round( self ): # return a list regarding to other players' contribution in each round history = [] for other_player in self.get_others_in_group(): each_round = [] for pr in other_player.in_previous_rounds(): each_round.append(pr.contribution) history.append(each_round) transpose_history = map(list, zip(*history)) #print('History matrix',history) return transpose_history
class Constants(BaseConstants): name_in_url = 'PG_standard' players_per_group = 5 num_rounds = 3 endowment = c(100) lumpsum = c(160) efficiency_factor = 2 contribution_limits = currency_range(0, endowment, 1) #define range of contribs
class Bid(Model): # inherits from Django's base "Model" BID_CHOICES = currency_range(c(Constants.reserve_price), c(Constants.maximum_bid), c(Constants.bid_price_increment)) round = models.PositiveIntegerField() bid = models.CurrencyField(choices=BID_CHOICES) accepted = models.PositiveIntegerField() pid_in_group = models.PositiveIntegerField() subsession_id = models.PositiveIntegerField() player = ForeignKey(Player) # creates 1:m relation -> this bid was made by a certain player
class Group(BaseGroup): request_1 = models.CurrencyField(choices=currency_range(11, 20, c(1))) request_2 = models.CurrencyField(choices=currency_range(11, 20, c(1))) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) if self.request_2 - self.request_1 == 1: p1.payoff = self.request_1 + 20 p2.payoff = self.request_2 else: if self.request_1 - self.request_2 == 1: p1.payoff = self.request_1 p2.payoff = self.request_2 + 20 else: p1.payoff = self.request_1 p2.payoff = self.request_2
class Constants(BaseConstants): name_in_url = 'MarkGame' players_per_group = 3 num_rounds = 5 endowment = c(10) offer_increment = c(0.01) offer_choices = currency_range(0, endowment - 2, offer_increment) accept_choices = ['A', 'B', 'Reject Both'] roles = {1: 'A', 2: 'B', 3: 'C'}
class Group(BaseGroup): sent_amount = models.CurrencyField(choices=currency_range( 0, Constants.endowment, c(1)), ) sent_back_amount = models.CurrencyField() def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * Constants.multiplication_factor - self.sent_back_amount
class Group(BaseGroup): sent_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, c(1)), doc="""Amount sent by P1""", ) sent_back_amount = models.CurrencyField(doc="""Amount sent back by P2""", ) def sent_back_amount_choices(self): return currency_range(c(0), self.sent_amount * Constants.multiplier, c(1))
class Player(BasePlayer): decision = models.CharField( choices=['♡', '☺︎'], doc="""Either ♡ or ☺︎""", widget=widgets.RadioSelect() ) option1 = models.CurrencyField( choices=currency_range(0, 4, c(0.01)) ) option2 = models.CurrencyField( choices=currency_range(0, 4, c(0.01)) ) option3 = models.CurrencyField( choices=currency_range(0, 4, c(0.01)) ) option4 = models.CurrencyField( choices=currency_range(0, 4, c(0.01)) ) option = models.IntegerField()
class Constants(BaseConstants): name_in_url = 'PG_punishment' players_per_group = 3 num_rounds = 1 endowment = c(100) lumpsum = c(160) efficiency_factor = 2 contribution_limits = currency_range(0, endowment, 1) # define range of contribs num_decisions_per_round = 2 pun_endowment = 4 # max amount spent on punishment pun_factor = 2 # efficiency of punishment
class Constants(BaseConstants): name_in_url = 'PGG_Conditional' players_per_group = 3 num_rounds = 1 instructions_template = 'PGG_Conditional/Instructions.html' # """Amount allocated to each player""" endowment = c(30) multiplier = 2 contribution_increment = c(3) contribute_choices = currency_range(0, endowment, contribution_increment)
class Constants(BaseConstants): name_in_url = 'mydictator_2b' players_per_group = 2 num_rounds = 1 # Initial amount allocated to the dictator endowment = c(100) kept_choices = range(10, 100, 10) multiplier = 2 offer_increment = c(10) offer_choices = currency_range(10, endowment, offer_increment)
class Group(BaseGroup): # プレイヤーの選択を定義する. ## プレイヤー1の選択は提案額を決める. proposal = models.CurrencyField( choices=currency_range(c(0), c(Constants.endowment), c(1)), label="あなたはいくら相手に渡しますか?", ) proposer_point = models.CurrencyField() # プレイヤー1の利得 accepter_point = models.CurrencyField() # プレイヤー2の利得 # 計算を実行する def compute(self): self.proposer_point = Constants.endowment - self.proposal #プレイヤー1の初期保有額-プレイヤー2への提案額 self.accepter_point = self.proposal #プレイヤー2への提案額
class Constants(BaseConstants): name_in_url = 'choose_thresholds' players_per_group = None instructions_template = 'choose_thresholds/Instructions.html' num_rounds = len(messages) endowment = c(100) payoff_if_rejected = c(0) offer_increment = c(1) offer_choices = currency_range(0, endowment, offer_increment) offer_choices_count = len(offer_choices)
class Group(BaseGroup): proposed_wage = models.CurrencyField(choices=currency_range( Constants.lowest_wage, Constants.highest_wage, c(5)), ) random_wage = models.IntegerField() guessed_wage = models.CurrencyField(choices=currency_range( Constants.lowest_wage, Constants.highest_wage, c(5)), ) effort = models.FloatField(choices=Constants.efforts, widget=widgets.RadioSelect) def get_cost(self): return Constants.costs[Constants.efforts.index(self.effort)] expected_effort = models.FloatField(choices=Constants.efforts, widget=widgets.RadioSelect) effort_cost = models.IntegerField() multiplier = models.FloatField(choices=[ 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ], widget=widgets.RadioSelect) guessed_multiplier = models.FloatField(choices=[ 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ], widget=widgets.RadioSelect) def set_payoffs(self): print('in set_payoffs') employer = self.get_player_by_role('Employer') worker = self.get_player_by_role('Worker') if self.subsession.round_number == self.session.vars['paying_round']: employer.payoff = c((120 - self.random_wage) * self.effort) worker.payoff = c(self.random_wage - 20 - self.get_cost())
class Constants(BaseConstants): name_in_url = 'ult2' players_per_group = 2 num_rounds = 4 endowment = c(1000) payoff_if_rejected = c(0) offer_increment = c(100) offer_choices = currency_range(0, endowment, offer_increment) offer_choicese_count = len(offer_choices) keep_give_amounts = [] for offer in offer_choices: keep_give_amounts.append((offer, endowment - offer))
class Group(BaseGroup): treatment = models.StringField() piece_rate = models.CurrencyField( choices=currency_range(0, 0.1, 0.03) ) guessed_piece_rate = models.CurrencyField( choices=currency_range(0, 0.1, 0.03) ) fair_piece_rate = models.CurrencyField( choices=currency_range(0, 0.1, 0.03) ) imaginary_piece_rate = models.CurrencyField( choices=currency_range(0, 0.1, 0.03) ) points = models.IntegerField(default='0') employer_points = models.IntegerField(default='0') guessed_points = models.IntegerField() target_points = models.IntegerField()
class Constants(BaseConstants): name_in_url = 'vigilante' players_per_group = None num_rounds = 1 instructions_template = 'karl/aInstructions.html' endowment = c(100) initial_endowment = c(100) take_away_endo = c(50) pool_multiplier = c(1.6) answer_increment = c(1) leader_decision = currency_range(0, take_away_endo, answer_increment) leader_decision_count = len(leader_decision)
class Constants(BaseConstants): name_in_url = 'ultimatum10' players_per_group = 2 num_rounds = 10 instructions_template = 'ultimatum/Instructions.html' endowment = c(10) payoff_if_rejected = c(0) offer_increment = c(1) offer_choices = currency_range(0, endowment, offer_increment) offer_choices_count = len(offer_choices) keep_give_amounts = [] for offer in offer_choices: keep_give_amounts.append((offer, endowment - offer))
class Group(BaseGroup): proposal = models.CurrencyField( choices=currency_range(c(0), c(Constants.endowment), c(1)), label="あなたはいくら相手に渡しますか?", ) accepted_or_not = models.BooleanField(doc="あなたは提案を受け入れますか?") proposer_point = models.CurrencyField() accepter_point = models.CurrencyField() def compute(self): if self.accepted_or_not == True: self.proposer_point = Constants.endowment - self.proposal self.accepter_point = self.proposal else: self.proposer_point = 0 self.accepter_point = 0
class Group(BaseGroup): allocation_bureau = models.CurrencyField( verbose_name='How much do you want to allocate?') allocation_pol = models.CurrencyField( choices=currency_range(c(0), c(100), 1), verbose_name='How much do you want to allocate?') public_payoff = models.CurrencyField(initial=c(0)) citizen_payoff = models.CurrencyField(initial=c(0)) is_elected = models.BooleanField( verbose_name= 'Do you want to re-elect the politician for another 4 rounds?') # def set_budget(self): # p2 = self.get_player_by_role('Bureaucrat') # p1 = self.get_player_by_role('Politician') # p2.bureau_budget= p1.allocation_pol def set_payoffs(self): politician = self.get_player_by_role('Politician') bureaucrat = self.get_player_by_role('Bureaucrat') citizen = self.get_player_by_role('Citizen') waiting = self.get_player_by_role('Waiting') for player in [politician, bureaucrat]: if (self.round_number == self.session.vars['paying_round']): player.payoff = sum([ p.public_payoff for p in self.player.in_all_rounds() ]) * (Constants.multiplication_factor / Constants.players_per_round) for player in [citizen]: if (self.round_number == self.session.vars['paying_round']): player.payoff = sum([ p.public_payoff for p in self.player.in_all_rounds() ]) * (Constants.multiplication_factor / Constants.players_per_round) + sum([ p.citizen_payoff for p in self.player.in_all_rounds() ])
class Constants(BaseConstants): name_in_url = 'ultimatum' players_per_group = 2 num_rounds = 4 instructions_template = 'ultimatum/Instructions.html' endowment = c( config_leex_1.UG_endowment) ## Notice this come from a config file payoff_if_rejected = c(0) offer_increment = c(1) offer_choices = currency_range(0, endowment, offer_increment) offer_choices_count = len(offer_choices) keep_give_amounts = [] for offer in offer_choices: keep_give_amounts.append((offer, endowment - offer))
class Player(BasePlayer): def sent_back_amount_choices(self): return currency_range( c(0), self.sent_amount * Constants.multiplication_factor, c(1) ) curpage=models.CharField() sent_amount = models.CurrencyField( choices=currency_range(0, Constants.endowment, c(1)), doc="""Amount sent by P1""", ) sent_back_amount = models.CurrencyField( doc="""Amount sent back by P2""", ) def set_payoffs(self): tripled_amount = self.sent_amount * Constants.multiplication_factor self.sent_back_amount=random.choice(self.sent_back_amount_choices()) # p1 = self # p2 = self.get_player_by_id(2) self.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount
class Constants(BaseConstants): name_in_url = 'sabotage' players_per_group = None task_timer = 120 #see Subsession, before_session_starts setting. num_rounds = 50 # must be more than the max one person can do in task_timer seconds tournament_rate= 100 sabotage_endowment = 50 sabotage_increment = 1 cost_of_sabotage_per_unit = 10 sabotage_choices = currency_range(0, sabotage_endowment, sabotage_increment) reference_texts = [ 'uIzR', 'o8sA', 'dWg5', '6kdA', 'ep7o', 'zflY', 'CwNg', 'OhZn', 'Xw0w', 'GJcR', 'OJ2D', 'kJ03', 'L5O8', '1MUj', 'GleS', '4gKx', 'mSol', 'oWKd', 'OFFz', 'CdsT', 'Mf4U', 'sUhJ', '1Ltw', '2mrm', 'f5UI', 'hNqN', 'boJa', '2Pqv', 'vLuq', 'IYYP', 'sy3O', 'M9X6', 'qflm', 'ovAU', '7PaW', 'YB4F', '2NFP', 'h6QM', 'xLkH', 'izif', 'r7Ml', 'ERJ8', 'geTe', 'L15N', 'uTKl', 'wRuQ', 'MFNc', 'YS4B', '80uw', 'syXc', ] # 'hNqN', # 'boJa', # '2Pqv', # 'vLuq', # 'IYYP', answer_key1 = [ 'uIzR', 'o8sA', 'dWg5', '6kdA', 'ep7o', 'zflY', 'CwNg', 'OhZn', 'Xw0w', 'GJcR', 'OJ2D', 'kJ03', 'L5O8', '1MUj', 'GleS', '4gKx', 'mSol', 'oWKd', 'OFFz', 'CdsT', '4gKx', 'mSol', 'oWKd', 'OFFz', 'CdsT', 'Mf4U', 'sUhJ', '1Ltw', '2mrm', 'f5UI', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', ] answer_key2 = [ 'uIzR', 'o8sA', 'dWg5', '6kdA', 'ep7o', 'zflY', 'CwNg', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', ] answer_key3 = [ 'uIzR', 'o8sA', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', ]
def sent_back_amount_choices(self): return currency_range(c(0), Constants.endowment, c(1))
def sent_back_amount_players_choices(self): return currency_range( c(0), self.player.sent_by_other * Constants.multiplication_factor, c(1))
def sent_back_amount_choices(self): return currency_range( c(0), self.group.sent_amount * Constants.multiplication_factor, c(1) )
def sent_back_amount_choices(self): return currency_range( c(0), self.group.sent_amount * Constants.multiplier, c(1) )
def sent_back_amount_choices(self): return currency_range(c(0), self.sent_amount * Constants.multiplier, c(1))