from django.utils.translation import gettext as _ from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, ) author = 'D. Dubois' doc = """ Common Pool Resource Game """ class Constants(BaseConstants): name_in_url = 'relcpr' players_per_group = 4 num_rounds = 10 # parameters of the game a = 0.383 b = 0.001 c = 0.005 k = 0.005 max_extraction = 20 ressource = max_extraction * players_per_group max_others = (players_per_group - 1) * max_extraction communication_time = 180 # secondes # chronos sur les écrans decision_time = 120 result_time = 60 class Subsession(BaseSubsession): communication = models.BooleanField() def creating_session(self): self.communication = self.session.config.get("communication", True) def group_by_arrival_time_method(self, waiting_players): """ we keep the same groups as in the effort task :param waiting_players: :return: """ nb_groups = int(len(self.get_players()) / Constants.players_per_group) for i in range(1, nb_groups + 1): group = [p for p in waiting_players if p.participant.vars["task_group_id"] == f"task_g_{i}"] if len(group) == Constants.players_per_group: return group class Group(BaseGroup): group_extraction = models.IntegerField(initial=0) def set_group_extraction_and_payoffs(self): self.group_extraction = sum([p.extraction for p in self.get_players()]) for p in self.get_players(): p.extraction_others = self.group_extraction - p.extraction p.compute_payoff() class MyFields: @staticmethod def degrees(): return range(6) class Player(BasePlayer): # Extraction game ================================================================================================== extraction = models.IntegerField(min=0, max=Constants.max_extraction) extraction_others_simul = models.IntegerField( min=0, max=Constants.max_others) extraction_others = models.IntegerField() cumulative_payoff = models.CurrencyField() # page Questinonaire1 ---------------------------------------------------------------------------------------------- part_or_excluded = models.StringField( label=_("Did you feel part of the group or excluded?"), choices=[_("Part"), _("Excluded")], widget=widgets.RadioSelectHorizontal ) proud_or_shame = models.StringField( label=_("Did you feel proud or shame of how you play as a group?"), choices=[_("Proud"), _("Shame")], widget=widgets.RadioSelectHorizontal ) committed = models.BooleanField( label=_("Did you feel committed towards the group?"), widget=widgets.RadioSelectHorizontal ) motivated_for_coordination = models.BooleanField( label=_("Did you feel motivated to coordinate your actions with others?"), widget=widgets.RadioSelectHorizontal ) group_or_individual_pursue = models.StringField( label=_("When playing, did you pursue an individual goal or a group one?"), choices=[_("Individual"), _("Group")], widget=widgets.RadioSelectHorizontal ) acted_for_group_or_perso = models.StringField( label=_("Do you think you acted in the best personal interest or the interest of the group?"), choices=[_("Personal"), _("Group")], widget=widgets.RadioSelectHorizontal ) follow_group = models.StringField( label=_("Did you follow what others in the group did, or did you dare to do different things?"), choices=[_("Follow"), _("Do different things ")], widget=widgets.RadioSelectHorizontal ) # page Questinonaire2 ---------------------------------------------------------------------------------------------- game_emotion_1 = models.StringField(blank=True) game_emotion_2 = models.StringField(blank=True) game_emotion_3 = models.StringField(blank=True) # Please indicate in a scale from 0 to 5 (0 nothing, 5 max) the degree to which you feel game_Friendly = models.IntegerField(label=_('Friendly'), choices=MyFields.degrees()) game_Respectful = models.IntegerField(label=_('Respectful'), choices=MyFields.degrees()) game_Sympathy = models.IntegerField(label=_('Sympathy'), choices=MyFields.degrees()) game_CloseFeelings = models.IntegerField(label=_('Close feelings'), choices=MyFields.degrees()) game_Proud = models.IntegerField(label=_('Proud'), choices=MyFields.degrees()) game_Superior = models.IntegerField(label=_('Superior'), choices=MyFields.degrees()) game_Selfesteem = models.IntegerField(label=_('Self-esteem'), choices=MyFields.degrees()) game_Topworld = models.IntegerField(label=_('Top of the world'), choices=MyFields.degrees()) game_Guilty = models.IntegerField(label=_('Guilty'), choices=MyFields.degrees()) game_Indebted = models.IntegerField(label=_('Indebted'), choices=MyFields.degrees()) game_Afraid = models.IntegerField(label=_('Afraid'), choices=MyFields.degrees()) game_Ashamed = models.IntegerField(label=_('Ashamed'), choices=MyFields.degrees()) game_Disappointed = models.IntegerField(label=_('Disappointed'), choices=MyFields.degrees()) game_Frustrated = models.IntegerField(label=_('Frustrated'), choices=MyFields.degrees()) game_Angry = models.IntegerField(label=_('Angry'), choices=MyFields.degrees()) game_Sad = models.IntegerField(label=_('Sad'), choices=MyFields.degrees()) # page Questionnaire3 ---------------------------------------------------------------------------------------------- game_part_of_group_scale = models.IntegerField( label=_("Did you feel part of the group?\nPlease indicate in a scale from 0 (nothing) to 5 (max)"), choices=MyFields.degrees(), widget=widgets.RadioSelectHorizontal) game_part_of_group_img = models.IntegerField( label=_("select the pair of circles that best describes your relationship with X, where X represent the " "other members of your group")) # page Questionnaire4 ---------------------------------------------------------------------------------------------- game_Trustworthy = models.IntegerField(label=_('Trustworthy'), choices=MyFields.degrees()) game_Fair = models.IntegerField(label=_('Fair'), choices=MyFields.degrees()) game_Selfish = models.IntegerField(label=_('Selfish'), choices=MyFields.degrees()) game_Cooperative = models.IntegerField(label=_('Cooperative'), choices=MyFields.degrees()) game_Competitive = models.IntegerField(label=_('Competitive'), choices=MyFields.degrees()) game_Understanding = models.IntegerField(label=_('Understanding'), choices=MyFields.degrees()) game_Caring = models.IntegerField(label=_('Caring'), choices=MyFields.degrees()) game_Envious = models.IntegerField(label=_('Envious'), choices=MyFields.degrees()) game_Altruistic = models.IntegerField(label=_('Altruistic'), choices=MyFields.degrees()) game_Empathetic = models.IntegerField(label=_('Empathetic'), choices=MyFields.degrees()) # page Questionnaire5 ---------------------------------------------------------------------------------------------- game_Trustworthy_others = models.IntegerField(label=_('Trustworthy'), choices=MyFields.degrees()) game_Fair_others = models.IntegerField(label=_('Fair'), choices=MyFields.degrees()) game_Selfish_others = models.IntegerField(label=_('Selfish'), choices=MyFields.degrees()) game_Cooperative_others = models.IntegerField(label=_('Cooperative'), choices=MyFields.degrees()) game_Competitive_others = models.IntegerField(label=_('Competitive'), choices=MyFields.degrees()) game_Understanding_others = models.IntegerField(label=_('Understanding'), choices=MyFields.degrees()) game_Caring_others = models.IntegerField(label=_('Caring'), choices=MyFields.degrees()) game_Envious_others = models.IntegerField(label=_('Envious'), choices=MyFields.degrees()) game_Altruistic_others = models.IntegerField(label=_('Altruistic'), choices=MyFields.degrees()) game_Empathetic_others = models.IntegerField(label=_('Empathetic'), choices=MyFields.degrees()) game_feel_others_behave = models.IntegerField( label=_("In general, did the other players behave as you expected?"), choices=MyFields.degrees(), widget=widgets.RadioSelectHorizontal) game_feel_others_influence = models.IntegerField( label=_("Did you feel you had influence over the behavior of others?"), choices=MyFields.degrees(), widget=widgets.RadioSelectHorizontal) game_feel_others_reciprocity = models.IntegerField( label=_("Did you feel reciprocated by the others?"), choices=MyFields.degrees(), widget=widgets.RadioSelectHorizontal) # page Questionnaire6 ---------------------------------------------------------------------------------------------- game_communication_facility = models.IntegerField( label=_("Communication with the other members of your group was"), choices=[(0, _("0 - Difficult")), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, _("10 - Easy"))], widget=widgets.RadioSelectHorizontal ) game_communication_clear = models.IntegerField( label=_("Communication with the other members of your group was"), choices=[(0, _("0 - Confusing")), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, _("10 - Clear"))], widget=widgets.RadioSelectHorizontal ) game_communication_useful = models.IntegerField( label=_("Communication with the other members of your group was"), choices=[(0, _("0 - Unuseful")), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, _("10 - Useful"))], widget=widgets.RadioSelectHorizontal ) # FUNCTIONS ============================================================================================================ def compute_payoff(self): self.payoff = c( Constants.a * float(self.extraction) - Constants.b * pow(self.extraction, 2) - self.extraction * (Constants.c + Constants.k * self.group.group_extraction) ) self.cumulative_payoff = sum([p.payoff for p in self.in_all_rounds()]) if self.round_number == Constants.num_rounds: self.participant.payoff = c( self.cumulative_payoff * self.session.config.get("real_world_currency_per_point")) txt_final = _( "The game is over. Your cumulative payoff is {:.2f} ECUs, which is equal to {}.").format( self.cumulative_payoff, self.cumulative_payoff * self.session.config.get("real_world_currency_per_point") ) self.participant.vars["relations_cpr_game"] = dict( txt_final=txt_final, payoff=self.cumulative_payoff * self.session.config.get("real_world_currency_per_point") )