from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import itertools doc = """ This is a game that demonstrates the anchoring effect. """ class Constants(BaseConstants): name_in_url = 'anchoring2' players_per_group = None num_rounds = 1 instructions_template = 'anchoring2/Instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): #low_player = () #high_player = () average_guess_low = models.FloatField() average_guess_high = models.FloatField() average_guess_low2 = models.FloatField() average_guess_high2 = models.FloatField() average_guess_low3 = models.FloatField() average_guess_high3 = models.FloatField() #def set_groups(self): def average_guess(self): high_contributions = 0 num_high_players = 0 low_contributions = 0 num_low_players = 0 for player in self.get_players(): if player.role() == 'High Player': high_contributions += player.guess num_high_players += 1 if player.role() == 'Low Player': low_contributions += player.guess num_low_players += 1 self.average_guess_high = high_contributions / num_high_players self.average_guess_low = low_contributions / num_low_players high_contributions2 = 0 num_high_players2 = 0 low_contributions2 = 0 num_low_players2 = 0 for player in self.get_players(): if player.role() == 'High Player': high_contributions2 += player.guess2 num_high_players2 += 1 if player.role() == 'Low Player': low_contributions2 += player.guess2 num_low_players2 += 1 self.average_guess_high2 = high_contributions2 / num_high_players2 self.average_guess_low2 = low_contributions2 / num_low_players2 high_contributions3 = 0 num_high_players3 = 0 low_contributions3 = 0 num_low_players3 = 0 for player in self.get_players(): if player.role() == 'High Player': high_contributions3 += player.guess3 num_high_players3 += 1 if player.role() == 'Low Player': low_contributions3 += player.guess3 num_low_players3 += 1 self.average_guess_high3 = high_contributions3 / num_high_players3 self.average_guess_low3 = low_contributions3 / num_low_players3 class Player(BasePlayer): social = models.FloatField( doc="""last two digits of social security number""", min=0, max=99 ) guess = models.FloatField( doc=""" Guess by this player. """, min=0, max=1000000 ) guess2 = models.FloatField( doc=""" Guess by this player. """, min=0, max=1000000 ) guess3 = models.FloatField( doc=""" Guess by this player. """, min=0, max=1000000 ) def role(self): if self.social >= 51: return 'High Player' if self.social <= 50: return 'Low Player'