from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'pure_coalition_game' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 A_ROLE = 'A' B_ROLE = 'B' C_ROLE = 'C' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): choice = models.StringField() share = models.IntegerField() class MainPage(Page): form_model = 'player' form_fields = ['choice', 'share'] @staticmethod def vars_for_template(player: Player): session = player.session subsession = player.subsession group = player.group if player.role == 'A': others = 'B and C' elif player.role == 'B': others = 'A and C' else: others = 'A and B' channelABC = 'ABC' + str(group.id_in_subsession) channelAB = 'AB' + str(group.id_in_subsession) channelAC = 'AC' + str(group.id_in_subsession) channelBC = 'BC' + str(group.id_in_subsession) choices = '' if player.role == 'A': choices += ' Coalition with B and C
' choices += ' Coalition with only B
' choices += ' Coalition with only C
' if player.role == 'B': choices += ' Coalition with A and C
' choices += ' Coalition with only A
' choices += ' Coalition with only C
' if player.role == 'C': choices += ' Coalition with A and B
' choices += ' Coalition with only A
' choices += ' Coalition with only B
' choices += ' No coalition
' return dict( others = others, channelABC=channelABC, channelAB=channelAB, channelAC=channelAC, channelBC=channelBC, choices=choices ) class MyWaitPage(WaitPage): pass class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): group = player.group if player.choice == 'ABC': choice = 'coalition with all players.' elif player.choice == 'B': choice = 'coalition with B.' elif player.choice == 'A': choice = 'coalition with A.' elif player.choice == 'C': choice = 'coalition with C.' else: choice = 'not to join a coalition.' a = group.get_player_by_role(C.A_ROLE) b = group.get_player_by_role(C.B_ROLE) c = group.get_player_by_role(C.C_ROLE) return dict( choice = choice, ashare = a.share, bshare = b.share, cshare = c.share, achoice = a.choice, bchoice = b.choice, cchoice = c.choice ) page_sequence = [MainPage, MyWaitPage, Results]