def stage(self) -> None: talk("What is displayed on the module?") scramble = ask.str_from_regex(r"[a-z]{6}") while set(scramble) not in [set(w) for w in self.words]: talk("Those letters don't correspond to a known word.") talk("What is displayed on the module?") scramble = ask.str_from_regex(r"[a-z]{6}") answer = [w for w in self.words if set(w) == set(scramble)][0] talk(f'Type in the word "{answer}".')
def stage(self) -> None: while True: possible_words: List[str] = list(self.valid_words) for column_index in range(5): talk(f"What letters are in column {column_index + 1}?") letters = ask.str_from_regex(r"[a-z]{6}") while len(set(letters)) != 6: #all letters should be unique talk("There should be 6 unique letters in the column.") talk(f"What letters are in column {column_index + 1}?") letters = ask.str_from_regex(r"[a-z]{6}") possible_words = [ word for word in possible_words if word[column_index] in letters ] #filter if len(possible_words) == 1: answer = possible_words[0].upper() talk(f'Enter the password "{answer}".') return if len(possible_words) == 0: break #no valid word or multiple valid words talk("Something went wrong. Let's start over.")
def stage(self) -> None: talk("What number is on the display?") display = int(ask.str_from_regex(r'[1-4]')) talk("What numbers are on the buttons, in reading order?") buttons = ask.str_from_regex(r'[1-4]{4}') while any(c not in buttons for c in '1234'): talk("There should be one of each number on the buttons.") talk("What numbers are on the buttons, in reading order?") buttons = ask.str_from_regex(r'[1-4]{4}') item: _MemoryItem if self.current_stage == 1: item = self._stage_1(display, buttons) elif self.current_stage == 2: item = self._stage_2(display, buttons) elif self.current_stage == 3: item = self._stage_3(display, buttons) elif self.current_stage == 4: item = self._stage_4(display, buttons) else: #self.current_stage == 5 item = self._stage_5(display, buttons) talk(f"Press the button labeled {item.label}.") self.presses.append(item)
def ask_coord(*, alpha: bool = True) -> Coord: """Get a coordinate point from the user. If alpha is set (the default), the expected form is like "A5", otherwise, row and column are asked separately.""" col: int row: int if alpha: talk('(Submit a coordinate like "B4", where the letter is the column') talk("and the number is the row.)") alpha_coord = ask.str_from_regex(r"[a-z][1-9][0-9]*") col = ascii_lowercase.index(alpha_coord[0]) + 1 row = int(alpha_coord[1:]) else: talk("Row number:") row = ask.positive_int() talk("Column number:") col = ask.positive_int() return Coord(row - 1, col - 1)
def stage(self) -> None: #pylint: disable=too-many-branches #can't help it talk("What color wires are on the module, from top to bottom?") talk( "Type R for red, Y for yellow, B for blue, W for white, and K for black." ) wirelist = ask.str_from_regex(r"[rybwk]{3,6}").lower() wire: str if len(wirelist) == 3: if 'r' not in wirelist: wire = "second" elif wirelist[-1] == 'w': wire = "last" elif wirelist.count('b') > 1: wire = "last blue" else: wire = "last" elif len(wirelist) == 4: if wirelist.count('r') > 1 and self.bomb.serial_odd: wire = "last red" elif wirelist[-1] == 'y' and 'r' not in wirelist: wire = "first" elif wirelist.count('b') == 1: wire = "first" elif wirelist.count('y') > 1: wire = "last" else: wire = "second" elif len(wirelist) == 5: if wirelist[-1] == 'k' and self.bomb.serial_odd: wire = "fourth" elif wirelist.count('r') == 1 and wirelist.count('y') > 1: wire = "first" elif 'k' not in wirelist: wire = "second" else: wire = "first" elif len(wirelist) == 6: if 'y' not in wirelist and self.bomb.serial_odd: wire = "third" elif wirelist.count('y') == 1 and wirelist.count('w') > 1: wire = "fourth" elif 'r' not in wirelist: wire = "last" else: wire = "fourth" talk(f"Cut the {wire} wire.")
def _get_batteries(self, batteries: Optional[int]) -> None: if batteries is not None and batteries >= 0: self.batteries = batteries elif EdgeFlag.BATTERIES in self._required_edgework_flag: talk("How many batteries are on the bomb?") self.batteries = int(ask.str_from_regex(r'[0-9]+'))