| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | # Class variable to hold all possible 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 | self.reset() |
| 15 | |
| 5 | 16 | @property |
| 6 | 17 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 18 | # Edge Case: Return the current name if it exists |
| 19 | if self._name is None: |
| 20 | raise ValueError("Robot name has not been set") |
| 21 | return self._name |
| 22 | |
| 9 | 23 | def reset(self) -> None: |
| 10 | | pass |
| 24 | # Edge Case: Return the name to the pool if it exists |
| 25 | if self._name: |
| 26 | Robot._used_names.discard(self._name) |
| 27 | |
| 28 | # Edge Case: Check if there are available names |
| 29 | if len(Robot._used_names) >= len(Robot._name_pool): |
| 30 | raise RuntimeError("No more unique names available") |
| 31 | |
| 32 | # Get a new name from the pool |
| 33 | while True: |
| 34 | candidate = Robot._name_pool.pop() |
| 35 | if candidate not in Robot._used_names: |
| 36 | self._name = candidate |
| 37 | Robot._used_names.add(self._name) |
| 38 | break |
| 39 | |
| 40 | @classmethod |
| 41 | def _generate_name_pool(cls): |
| 42 | # Generate all possible names in format: two uppercase letters + three digits |
| 43 | for first_letter in string.ascii_uppercase: |
| 44 | for second_letter in string.ascii_uppercase: |
| 45 | for number in range(1000): |
| 46 | name = f"{first_letter}{second_letter}{number:03d}" |
| 47 | cls._name_pool.append(name) |
| 48 | # Shuffle the pool to ensure randomness |
| 49 | random.shuffle(cls._name_pool) |
| 50 | |
| 51 | # Handled Edge Cases: Empty name pool initialization, None name access, returning names to pool, no available names |