from . import * from enum import Enum class Case(Enum): TIMEOUT_SUBTRACTION_PAGE = "subtraction Timeout SubtractionPage" SUBTRACTION_PAGE_ALL_CORRECT = "subtraction SubtractionPage all correct" SUBTRACTION_PAGE_SOME_CORRECT = "subtraction SubtractionPage some correct" SUBTRACTION_PAGE_NONE_CORRECT = "subtraction SubtractionPage none correct" TIMEOUT_NOTES = "subtraction Timeout Notes" NO_NOTES = "subtraction No Notes" class PlayerBot(Bot): cases = [case.value for case in [Case.TIMEOUT_SUBTRACTION_PAGE, Case.SUBTRACTION_PAGE_ALL_CORRECT, Case.SUBTRACTION_PAGE_SOME_CORRECT, Case.SUBTRACTION_PAGE_NONE_CORRECT, Case.TIMEOUT_NOTES, Case.NO_NOTES]] def play_round(self): if self.player.participant.timeout: print(f"Skipping case {self.case}") return print(f"Playing case {self.case}") print(f"Playing case '{self.case}'") # SubtractionPage if self.player.round_number == 1: expect("On the following pages you will be asked to make some subtractions", "in", self.html) else: expect("Now subtract 7 from your previous answer", "in", self.html) if self.case == Case.TIMEOUT_SUBTRACTION_PAGE.value: yield Submission( SubtractionPage, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return if self.case == Case.SUBTRACTION_PAGE_NONE_CORRECT.value: yield Submission(SubtractionPage, { "number": 300 }) expect(self.player.participant.nr_correct_answers_subtractions, 0) elif self.case == Case.SUBTRACTION_PAGE_SOME_CORRECT.value: if self.round_number == 1: yield Submission(SubtractionPage, { "number": 93 }) else: yield Submission(SubtractionPage, { "number": 65 }) if self.round_number < 5: expect(self.player.participant.nr_correct_answers_subtractions, 1) else: expect(self.player.participant.nr_correct_answers_subtractions, 2) else: # all correct yield Submission(SubtractionPage, { "number": {1: 93, 2: 86, 3: 79, 4: 72, 5: 65}.get(self.player.round_number) }) expect(self.player.participant.nr_correct_answers_subtractions, self.round_number) # Notes if self.player.round_number == 5: expect("Did you take notes", "in", self.html) if self.case == Case.TIMEOUT_NOTES.value: yield Submission( Notes, timeout_happened=True, ) expect("You ran out of time", "in", self.html) expect(self.player.participant.timeout, True) return if self.case == Case.NO_NOTES.value: yield Submission(Notes, { "notes": "No" }) expect(self.player.notes, "No") else: # Notes yield Submission(Notes, { "notes": "Yes" }) expect(self.player.notes, "Yes")