from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ This is a 2-player 2-strategy coordination game. The name and story originated from Luce and Raiffa (1957) . """ class Constants(BaseConstants): name_in_url = 'elicitation2' players_per_group = None num_rounds = 1 instructions_template = 'elicitation2/Instructions.html' winning_pay = c(100) class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.participant.vars['PayoffT6'] = c(0) class Group(BaseGroup): pass class Player(BasePlayer): decision = models.PositiveIntegerField(initial=None) prev_decision = models.PositiveIntegerField(initial=None) count = models.IntegerField(initial=random.randint(1, 2)) islose = models.IntegerField(initial=0) u = models.IntegerField(initial=0) init = models.IntegerField(initial=0) def update(self): print("Updating ") print(self.count) if self.init == 0: self.init = 1 self.count = self.count + self.decision if self.count == 20: self.u = 1 self.islose = 1 elif self.count == 19: self.u = random.randint(1, 2) if self.u == 2: self.islose = 1 else: self.u = random.randint(1, 2) self.count = self.count + self.u if self.count >= 21 and self.islose == 0: self.payoff = Constants.winning_pay self.participant.vars['PayoffT6'] = Constants.winning_pay else: self.payoff = c(0) # - ws Apr self.prev_decision = self.decision # - ws May self.decision = None # - ws May def role(self): if self.id_in_group == 1: return 'Player 2'