| 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 | # Edge Case: Assign a name immediately upon creation |
| 17 | self._assign_name() |
| 18 | |
| 5 | 19 | @property |
| 6 | 20 | def name(self) -> str: |
| 7 | | pass |
| 8 | | |
| 21 | # Edge Case: Return the current name if it exists |
| 22 | return self._name |
| 23 | |
| 9 | 24 | def reset(self) -> None: |
| 10 | | pass |
| 25 | # Edge Case: Reset the robot's name to None and assign a new one |
| 26 | self._name = None |
| 27 | self._assign_name() |
| 28 | |
| 29 | def _assign_name(self) -> None: |
| 30 | # Edge Case: Check if there are names available in the pool |
| 31 | if Robot._current_index >= len(Robot._name_pool): |
| 32 | raise RuntimeError("No more names available") |
| 33 | |
| 34 | # Edge Case: Assign a name only if the robot doesn't have one |
| 35 | if self._name is None: |
| 36 | self._name = Robot._name_pool[Robot._current_index] |
| 37 | Robot._current_index += 1 |
| 38 | |
| 39 | @classmethod |
| 40 | def _generate_name_pool(cls) -> None: |
| 41 | # Generate all possible names in format: two uppercase letters + three digits |
| 42 | for first_letter in string.ascii_uppercase: |
| 43 | for second_letter in string.ascii_uppercase: |
| 44 | for number in range(1000): |
| 45 | name = f"{first_letter}{second_letter}{number:03d}" |
| 46 | cls._name_pool.append(name) |
| 47 | |
| 48 | # Handled Edge Cases: Empty name pool initialization, immediate name assignment upon creation, returning existing name, resetting name to None and assigning new one, checking name availability in pool, assigning name only when robot has none, generating all possible name combinations |