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