| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | # Class variable to hold the name pool and track used names |
| 6 | _name_pool = [] |
| 7 | _used_names = set() |
| 8 | |
| 2 | 9 | def __init__(self): |
| 3 | | pass |
| 4 | | |
| 10 | # Edge Case: Initialize the name pool if it's empty |
| 11 | if not Robot._name_pool: |
| 12 | self._generate_name_pool() |
| 13 | self._name = None |
| 14 | # Edge Case: Handle the case where all possible names are used |
| 15 | if len(Robot._used_names) >= len(Robot._name_pool): |
| 16 | raise RuntimeError("All possible names have been used") |
| 17 | self._assign_name() |
| 18 | |
| 5 | 19 | @property |
| 6 | 20 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 21 | return self._name |
| 22 | |
| 9 | 23 | def reset(self) -> None: |
| 10 | | pass |
| 24 | # Edge Case: Handle resetting a robot's name and making the old name available again |
| 25 | if self._name: |
| 26 | Robot._used_names.discard(self._name) |
| 27 | # Edge Case: Handle the case where all possible names are used |
| 28 | if len(Robot._used_names) >= len(Robot._name_pool): |
| 29 | raise RuntimeError("All possible names have been used") |
| 30 | self._assign_name() |
| 31 | |
| 32 | def _assign_name(self) -> None: |
| 33 | # Edge Case: Handle assignment of a new name from the pool |
| 34 | while True: |
| 35 | candidate_name = Robot._name_pool.pop() |
| 36 | if candidate_name not in Robot._used_names: |
| 37 | self._name = candidate_name |
| 38 | Robot._used_names.add(self._name) |
| 39 | break |
| 40 | |
| 41 | @classmethod |
| 42 | def _generate_name_pool(cls) -> None: |
| 43 | # Edge Case: Generate all possible names and shuffle them |
| 44 | letters = string.ascii_uppercase |
| 45 | digits = string.digits |
| 46 | |
| 47 | for first_letter in letters: |
| 48 | for second_letter in letters: |
| 49 | for digit1 in digits: |
| 50 | for digit2 in digits: |
| 51 | for digit3 in digits: |
| 52 | cls._name_pool.append(first_letter + second_letter + digit1 + digit2 + digit3) |
| 53 | |
| 54 | random.shuffle(cls._name_pool) |
| 55 | |
| 56 | # Handled Edge Cases: Empty name pool initialization, all names used, name reset with reuse, name assignment from pool, name pool generation with shuffling |