| 1 | import random |
| 2 | import string |
| 3 | |
| 1 | 4 | class Robot: |
| 5 | # Class variable to hold the pool of available names |
| 6 | _name_pool = set() |
| 7 | # Class variable to track all used names |
| 8 | _used_names = set() |
| 9 | |
| 2 | 10 | def __init__(self): |
| 3 | | pass |
| 4 | | |
| 11 | # Edge Case: Initialize the name pool if it's empty |
| 12 | if not Robot._name_pool: |
| 13 | self._generate_name_pool() |
| 14 | |
| 15 | # Edge Case: Handle the case where all possible names are used |
| 16 | if not Robot._name_pool: |
| 17 | raise RuntimeError("All possible robot names have been used.") |
| 18 | |
| 19 | self._name = None |
| 20 | self._assign_name() |
| 21 | |
| 5 | 22 | @property |
| 6 | 23 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 24 | return self._name |
| 25 | |
| 9 | 26 | def reset(self) -> None: |
| 10 | | pass |
| 27 | # Edge Case: Handle resetting a robot's name and returning it to the pool |
| 28 | if self._name: |
| 29 | Robot._used_names.discard(self._name) |
| 30 | Robot._name_pool.add(self._name) |
| 31 | self._assign_name() |
| 32 | |
| 33 | def _assign_name(self) -> None: |
| 34 | # Edge Case: Handle assignment of a new name from the pool |
| 35 | if not Robot._name_pool: |
| 36 | raise RuntimeError("All possible robot names have been used.") |
| 37 | |
| 38 | new_name = random.choice(list(Robot._name_pool)) |
| 39 | Robot._name_pool.discard(new_name) |
| 40 | Robot._used_names.add(new_name) |
| 41 | self._name = new_name |
| 42 | |
| 43 | @classmethod |
| 44 | def _generate_name_pool(cls) -> None: |
| 45 | # Edge Case: Generate all possible names exactly once |
| 46 | if cls._name_pool: |
| 47 | return |
| 48 | |
| 49 | for first_letter in string.ascii_uppercase: |
| 50 | for second_letter in string.ascii_uppercase: |
| 51 | for number in range(1000): |
| 52 | name = f"{first_letter}{second_letter}{number:03d}" |
| 53 | if name not in cls._used_names: |
| 54 | cls._name_pool.add(name) |
| 55 | |
| 56 | # Handled Edge Cases: Empty name pool initialization, all names used, name assignment, name reset, duplicate prevention |