from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) # import numpy as np import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'cyberRMob_cont_3' players_per_group = None num_rounds = 11 prob = [0.65,0.35] fromX = ["Z","Y"] fromY = ["Z","X"] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): throw = models.StringField( choices=["X","Y"], widget=widgets.RadioSelect ) exit_game = models.BooleanField(initial=False) location = models.StringField(initial='Z') def loc_ball(self): if self.in_round(self.round_number-1).location == 'Z': self.location = self.throw return self.location, print('from PPT, location is ',self.location) elif self.in_round(self.round_number-1).location == 'X': randthrow = np.random.choice(C.FROMX,p=C.PROB) self.location = str(randthrow) return self.location, print('from X location is ',self.location, 'random is ', randthrow) elif self.in_round(self.round_number-1).location == 'Y': randthrow = np.random.choice(C.FROMY,p=C.PROB) self.location = randthrow return self.location, print('from Y location is ',self.location, 'random is ', randthrow) else: return None def location_in_prev(self): while self.round_number >= 2: return self.in_round(self.round_number-1).location def vars_for_template(self): if self.round_number >= 2: a = self.in_round(self.round_number-1).location else: a = "Z" if self.round_number >= 2: b = self.location else: b = "Z" return dict(a=a,b=b) p = models.FloatField( initial=random.uniform(0,1.5) )