| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | # Class variable to hold the name pool and current index |
| 6 | _name_pool = [] |
| 7 | _current_index = 0 |
| 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 | random.shuffle(Robot._name_pool) |
| 14 | |
| 15 | self._name = None |
| 16 | self._assign_name() |
| 17 | |
| 5 | 18 | @property |
| 6 | 19 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 20 | return self._name |
| 21 | |
| 9 | 22 | def reset(self) -> None: |
| 10 | | pass |
| 23 | # Edge Case: Reset the robot's name to None and assign a new one |
| 24 | self._name = None |
| 25 | self._assign_name() |
| 26 | |
| 27 | def _assign_name(self) -> None: |
| 28 | # Edge Case: Check if all names have been used |
| 29 | if Robot._current_index >= len(Robot._name_pool): |
| 30 | raise RuntimeError("No more unique names available") |
| 31 | |
| 32 | # Edge Case: Assign a name only if the robot doesn't have one |
| 33 | if self._name is None: |
| 34 | self._name = Robot._name_pool[Robot._current_index] |
| 35 | Robot._current_index += 1 |
| 36 | |
| 37 | @classmethod |
| 38 | def _generate_name_pool(cls) -> None: |
| 39 | # Generate all possible names in format: two uppercase letters + three digits |
| 40 | for first_letter in string.ascii_uppercase: |
| 41 | for second_letter in string.ascii_uppercase: |
| 42 | for number in range(1000): |
| 43 | cls._name_pool.append(f"{first_letter}{second_letter}{number:03d}") |
| 44 | |
| 45 | # Handled Edge Cases: Empty name pool initialization, all names used, assigning name to robot without one |