from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'svtask2' players_per_group = 2 num_rounds = 1 ritoku1 = c(20000) ritoku2 = c(40000) ritoku3 = c(60000) ritoku4 = c(-20000) class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): print('in set_payoffs') p1 = self.get_player_by_role('プレイヤー1') p2 = self.get_player_by_role('プレイヤー2') if p1.kakaku == 300 and p2.kakaku == 400: p1.is_winner = True p2.is_winner = False elif p1.kakaku == 400 and p2.kakaku == 300: p1.is_winner = False p2.is_winner = True elif p1.kakaku == 300 and p2.kakaku == 300: p1.is_draw1 = True p2.is_draw1 = True else: p1.is_draw2 = True p2.is_draw2 = True for player in [p1, p2]: if player.is_winner: player.payoff = Constants.ritoku3 elif player.is_draw1: player.payoff = Constants.ritoku1 elif player.is_draw2: player.payoff = Constants.ritoku2 else: player.payoff = Constants.ritoku4 class Player(BasePlayer): kakaku = models.IntegerField( choices=[300, 400], widget=widgets.RadioSelect ) is_winner = models.BooleanField() is_draw1 = models.BooleanField() is_draw2 = models.BooleanField() def role(self): if self.id_in_group == 1: return 'プレイヤー1' if self.id_in_group == 2: return 'プレイヤー2'