from otree.api import Currency as c, currency_range from . import pages from ._builtin import Bot from .models import Constants from otree.api import Submission from random import randint, choice ### GENERAL WITHOUT TIMEOUTS class PlayerBot(Bot): def play_round(self): # Decision page: depend on role yield Submission(pages.Initialisation, check_html=False) yield Submission(pages.StartExperiment, check_html=False) if self.player.role() == 'attacker': if not self.session.config['group']: yield pages.Decision1Attacker, dict(choice_a1 = choice([0,1])) if self.group.defenders_active >= 2: yield pages.Decision2Attacker, dict(choice_a2=choice([0,1])) if self.group.defenders_active >= 3: yield pages.Decision3Attacker, dict(choice_a3=choice([0,1])) if self.group.defenders_active == 4: yield pages.Decision4Attacker, dict(choice_a4=choice([0,1])) yield pages.Results else: yield pages.Decision1Attacker, dict(choice_a1=choice([0,1])) yield pages.Results elif self.player.role() == 'defender1' or self.player.role() == 'defender2' or \ self.player.role() == 'defender3' or self.player.role() == 'defender4': yield pages.DecisionDefender, dict(choice_d=choice([0,1])) yield Submission(pages.BeliefsEE, timeout_happened=True) #dict(ee=-99) #dict(ee=randint(0, 100)) yield pages.BeliefsPNB, dict(pnb=choice([0, 1])) yield Submission(pages.BeliefsNE, timeout_happened=True) #dict(ne=-99) #dict(ne=randint(0, 100)) # yield pages.AppropBEH_u, dict(beh_u=choice([1, 2, 3, 4])) # yield pages.AppropBEH_d, dict(beh_d=choice([1, 2, 3, 4])) yield pages.AppropPUN_u, dict(pun_u=choice([1, 2, 3, 4])) yield pages.AppropPUN_d, dict(pun_d=choice([1, 2, 3, 4])) if (self.session.config['reward'] or self.session.config['punishment']) and \ self.group.dsel_choice < 2 and self.group.get_player_by_role('attacker').choice_a1 == 1: print('SHOULD RUN REWPUN PAGES') # All defenders that are not selected defender: see choice buttons to reward/punish if self.group.attack_paid != self.player.defender_id: if self.session.config['reward']: yield pages.Results, dict(rewpun=1) if self.session.config['punishment']: yield pages.Results, dict(rewpun=2) print('One of other defenders', self.group.attack_paid, ' != ', self.player.defender_id) # Selected defender sees regular results screen / doesn't see reward/punish buttons else: yield pages.Results print('Selected defender', self.group.attack_paid, ' == ', self.player.defender_id) # If reward/punish was option they all see results screen yield pages.RewardPunishment else: # If reward/punish was not an option they see regular results screen yield pages.Results