from . import * from enum import Enum class Case(Enum): TIMEOUT_AUDIO_A_CHECK = "audiotest Timeout AudioAcheck" ATTENTION_CHECK_CORRECT = "audiotest Attention Check Correct" ATTENTION_CHECK_WRONG = "audiotest Attention Check Wrong" TIMEOUT_AUDIO_TEST = "audiotest Timeout AudioTest" TIMEOUT_ANSWERS = "audiotest Timeout Answers" ANSWERS_ALL_CORRECT = "audiotest Answers all correct" ANSWERS_SOME_CORRECT = "audiotest Answers some correct" ANSWERS_NONE_CORRECT = "audiotest Answers none correct" class PlayerBot(Bot): cases = [case.value for case in [Case.TIMEOUT_AUDIO_A_CHECK, Case.ATTENTION_CHECK_CORRECT, Case.ATTENTION_CHECK_WRONG, Case.TIMEOUT_AUDIO_TEST, Case.TIMEOUT_ANSWERS, Case.ANSWERS_ALL_CORRECT, Case.ANSWERS_SOME_CORRECT, Case.ANSWERS_NONE_CORRECT]] def play_round(self): if self.player.participant.timeout: print(f"Skipping case {self.case}") return print(f"Playing case {self.case}") # AudioAcheck expect("For the next task you will need to listen to some sounds.", "in", self.html) if self.case == Case.TIMEOUT_AUDIO_A_CHECK.value: yield Submission( AudioAcheck, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return if self.case == Case.ATTENTION_CHECK_WRONG.value: yield Submission(AudioAcheck, { "audiocheck_answer": 3 }) expect(self.player.participant.audiocheck_answer, 3) expect(self.player.participant.attention_check_failed, True) else: # Attention Check Correct previous = self.player.participant.attention_check_failed yield Submission(AudioAcheck, { "audiocheck_answer": 4 }) expect(self.player.participant.audiocheck_answer, 4) if not previous: expect(self.player.participant.attention_check_failed, False) # AudioTest expect("When you click on the button below, the computer", "in", self.html) if self.case == Case.TIMEOUT_AUDIO_TEST.value: yield Submission( AudioTest, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return yield Submission(AudioTest) # Answers expect("Please enter every word that you remember from the audio", "in", self.html) if self.case == Case.TIMEOUT_ANSWERS.value: yield Submission( Answers, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return if self.case == Case.ANSWERS_NONE_CORRECT.value: yield Submission(Answers, { "a1": "blue", "a2": "green", "a3": "yellow", }) expect(self.player.participant.num_correct_words, 0) elif self.case == Case.ANSWERS_SOME_CORRECT.value: yield Submission(Answers, { "a1": "Book", # correct "a2": "RIVER", # correct "a3": "yellow", "a4": "Market", # correct "a5": "no", "a6": "nope", "a8": "apple gold river hotel king", "a9": "king", # correct "a10": "king" # already given }) expect(self.player.participant.num_correct_words, 4) else: # All correct yield Submission(Answers, { "a1": "Book", "a2": "RIVER", "a3": "HOTEL", "a4": "Market", "a5": "TREE", "a6": "SKIN", "a7": "gold", "a8": "Paper", "a9": "king", "a10": "Child" }) expect(self.player.participant.num_correct_words, 10)