from otree.api import * from collegeRanking import collegeFirstPage, firstPage, officialRoundsBegins, resultForColleges, resultForStudents #Currency as c, currency_range, expect, Bot, SubmissionMustFail #from . import * import random class PlayerBot(Bot): #cases1 = ['basic', 'p1_wins', 'all_0', 'all_max'] cases = ['allS']#, 'allC','9S9C'] #'allS', 'allC', def play_round(self): case = self.case cut_off_for_s = 0 cut_off_for_c = 0 # Introduction #yield Introduction '''if case == 'basic': for invalid_cut_off in [-5,-4,-1,101,102,100.5]: if self.player.id_in_group < 3: yield SubmissionMustFail(collegeFirstPage, dict(cutOff=invalid_cut_off))''' if self.player.round_number == 2: yield officialRoundsBegins if case == 'allS': if self.player.id_in_group == 1: '''cutOff=30 yield collegeFirstPage''' cut_off_for_s = random.randint(1,100) yield collegeFirstPage, dict(cutOff=cut_off_for_s) elif self.player.id_in_group == 2: cut_off_for_c = random.randint(1,100) yield collegeFirstPage, dict(cutOff=cut_off_for_c) else: print(self.player.examScore) yield firstPage, dict(choseS=True) if case == 'allC': sumScore = 0 admissionCount = 0 cut_off_for_s = random.randint(1,100) cut_off_for_c = random.randint(1,100) if self.player.id_in_group == 1: yield collegeFirstPage, dict(cutOff=cut_off_for_s) elif self.player.id_in_group == 2: yield collegeFirstPage, dict(cutOff=cut_off_for_c) else: yield firstPage, dict(choseS=False) for p in self.group.get_players(): if p.examScore > cut_off_for_c: sumScore += p.examScore admissionCount += 1 if admissionCount == 0: print ("nobody is admitted") avgScore = 0 else: avgScore = round(sumScore/admissionCount) #print ("case 2 goes well") if avgScore != self.group.avgScoreForC: print ("something goes wrong case 2") if case == '9S9C': sumForS = 0 sumForC = 0 admitsS = 0 admitsC = 0 cut_off_for_s = random.randint(1,100) cut_off_for_c = random.randint(1,100) if self.player.id_in_group == 1: yield collegeFirstPage, dict(cutOff=cut_off_for_s) elif self.player.id_in_group == 2: yield collegeFirstPage, dict(cutOff=cut_off_for_c) elif self.player.id_in_group < 12: #print ("here are the scores fotr those choose S") #print( self.player.examScore) '''if self.player.examScore>30: sumForS += self.player.examScore admitsS += 1''' yield firstPage, dict(choseS=True) else: '''if self.player.examScore>50: sumForC += self.player.examScore admitsC +=1''' yield firstPage, dict(choseS=False) #print('case3 goes well') for p in self.group.get_players(): if p.id_in_group > 2: if p.choseS: if p.examScore > cut_off_for_s: sumForS += p.examScore admitsS +=1 else: if p.examScore > cut_off_for_c: sumForC += p.examScore admitsC += 1 if admitsS == 0: print('no one got into S') avgS = 0 else: avgS = round(sumForS/admitsS) if admitsC == 0: print('no one gets into C') avgC = 0 else: avgC = round(sumForC/admitsC) if avgC != self.group.avgScoreForC: print ("something goes wrong case 3 C") if avgS != self.group.avgScoreForS: print ("something goes wrong case 3 S") print (avgS) print (self.group.avgScoreForS) #verify results if case=='allS': sumScore = 0 admissionCount = 0 for p in self.group.get_players(): if p.examScore > cut_off_for_s: sumScore += p.examScore admissionCount += 1 if admissionCount == 0: print ("nobody is admitted") avgScore = 0 else: avgScore = round(sumScore/admissionCount) #print ("case 1 goes well") if avgScore != self.group.avgScoreForS: print ("something goes wrong case 1") print (avgScore) print (self.group.avgScoreForS) if self.player.id_in_group < 3: yield resultForColleges else: yield resultForStudents ''' if case == 'basic': for invalid_bid in [-1, 11]: yield SubmissionMustFail(Bid, dict(bid_amount=invalid_bid)) if case == 'p1_wins': if self.player.id_in_group == 1: bid_amount = 2 else: bid_amount = 1 elif case == 'all_0': bid_amount = 0 else: # case == 'all_max': bid_amount = C.BID_MAX yield Bid, dict(bid_amount=bid_amount) if case == 'p1_wins': if self.player.id_in_group == 1: expect('You won the auction', 'in', self.html) else: expect('You did not win', 'in', self.html) if self.player.id_in_group == 1: num_winners = sum([1 for p in self.group.get_players() if p.is_winner]) expect(num_winners, 1) for field in [ self.player.bid_amount, self.player.payoff, self.player.item_value_estimate, self.player.is_winner, ]: expect(field, '!=', None) yield Results'''