from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'negotiations_game' players_per_group = 3 num_rounds = 5 instructions_template = 'negotiations_game/instructions.html' sc_role = 'SC' cc_role = 'CC' thor_role = 'Thor' class Subsession(BaseSubsession): def creating_session(self): # this shuffles the players but keeps their roles fixed self.group_randomly(fixed_id_in_group=True) pass # for player in self.get_players(): # player.id_in_chat = 'Player {}'.format(player.id_in_group) class Group(BaseGroup): group_merger_success = models.BooleanField() def verify_contracts(self): self.group_merger_success = False sc = self.get_player_by_role('SC') cc = self.get_player_by_role('CC') thor = self.get_player_by_role('Thor') if sc.merger_type == 1 and cc.merger_type == 1 and thor.merger_type == 1: if sc.merger_share + cc.merger_share + thor.merger_share == 100: self.group_merger_success = True return if sc.merger_type == 2 and cc.merger_type == 2: if sc.merger_share + cc.merger_share == 90: thor.merger_share = 0 self.group_merger_success = True return if sc.merger_type == 3 and thor.merger_type == 3: if sc.merger_share + thor.merger_share == 70: cc.merger_share = 0 self.group_merger_success = True return if cc.merger_type == 4 and thor.merger_type == 4: if cc.merger_share + thor.merger_share == 40: sc.merger_share = 0 self.group_merger_success = True return sc.merger_share = 0 cc.merger_share = 0 thor.merger_share = 0 return class Player(BasePlayer): # id_in_chat = models.StringField() merger_type = models.IntegerField( label="What is the merger type?" ) merger_share = models.IntegerField( label="What is your personal share/payoff from the above merger?" ) def merger_type_choices(self): choices = [] if self.role == 'SC': choices = [ [1, 'SC, CC, and Thor'], [2, 'SC and CC'], [3, 'SC and Thor'], [5, 'None'], ] if self.role == 'CC': choices = [ [1, 'SC, CC, and Thor'], [2, 'CC and SC'], [4, 'CC and Thor'], [5, 'None'], ] if self.role == 'Thor': choices = [ [1, 'SC, CC, and Thor'], [3, 'Thor and SC'], [4, 'Thor and CC'], [5, 'None'], ] return choices def one_to_one_chat_configs(self): configs = [] for other in self.get_others_in_group(): if other.id_in_group < self.id_in_group: lower_id, higher_id = other.id_in_group, self.id_in_group else: lower_id, higher_id = self.id_in_group, other.id_in_group configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, lower_id, higher_id), 'label': 'Private Chat with {}'.format(other.role) }) return configs def sc_controls_chat_configs(self): configs = [] if self.role == 'SC': configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 1, 2), 'label': 'Private Chat with CC' }) configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 1, 3), 'label': 'Private Chat with Thor' }) else: configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 1, self.id_in_group), 'label': 'Private Chat with SC' }) return configs def cc_controls_chat_configs(self): configs = [] if self.role == 'CC': configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 1, 2), 'label': 'Private Chat with SC' }) configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 2, 3), 'label': 'Private Chat with Thor' }) else: configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, min(self.id_in_group, 2), max(self.id_in_group, 2)), 'label': 'Private Chat with CC' }) return configs def thor_controls_chat_configs(self): configs = [] if self.role == 'Thor': configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 1, 3), 'label': 'Private Chat with SC' }) configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, 2, 3), 'label': 'Private Chat with CC' }) else: configs.append({ # make a name for the channel that is the same for all # channel members. That's why we order it (lower, higher) 'channel': '{}-{}-{}-{}'.format(self.round_number, self.group.id, self.id_in_group, 3), 'label': 'Private Chat with Thor' }) return configs