agent

Finished
1import random
2import string
3
14class Robot:
5 # Class variable to hold the name pool and current index
6 _name_pool = []
7 _current_index = 0
8
29 def __init__(self):
3 pass
4
10 """
11 Initialize a Robot instance.
12
13 Each robot starts with no name until accessed.
14 """
15 self._assigned_name = None
16
17 # Generate the name pool if it hasn't been generated yet
18 if not Robot._name_pool:
19 self._generate_name_pool()
20
521 @property
622 def name(self) -> str:
7 pass
8
23 """
24 Get the robot's name.
25
26 If the robot doesn't have a name yet, assign one from the pool.
27
28 Returns:
29 str: The robot's name in format AA000.
30 """
31 # Edge Case: Robot has no name assigned yet
32 if self._assigned_name is None:
33 # Edge Case: All possible names have been used
34 if Robot._current_index >= len(Robot._name_pool):
35 raise RuntimeError("No more unique names available")
36
37 self._assigned_name = Robot._name_pool[Robot._current_index]
38 Robot._current_index += 1
39
40 return self._assigned_name
41
942 def reset(self) -> None:
10 pass
43 """
44 Reset the robot to factory settings.
45
46 This wipes the robot's name, allowing it to get a new one.
47 """
48 # Edge Case: Resetting a robot that had a name
49 self._assigned_name = None
50
51 @classmethod
52 def _generate_name_pool(cls):
53 """
54 Generate all possible robot names and shuffle them randomly.
55
56 This ensures names are unique and randomly distributed.
57 """
58 # Edge Case: Name pool generation when it's empty
59 cls._name_pool = []
60
61 # Generate all combinations of two letters
62 letters = string.ascii_uppercase
63 # Generate all combinations of three digits
64 digits = [f"{i:03d}" for i in range(1000)]
65
66 # Create all possible names
67 for letter1 in letters:
68 for letter2 in letters:
69 for digit in digits:
70 cls._name_pool.append(f"{letter1}{letter2}{digit}")
71
72 # Shuffle the pool randomly
73 random.shuffle(cls._name_pool)
74
75 # Handled Edge Cases: Robot has no name assigned yet, All possible names have been used, Resetting a robot that had a name, Name pool generation when it's empty
Test NameStatus
test_different_robots_have_different_names
Pass
test_has_name
Pass
test_name_sticks
Pass
test_reset_name
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.