-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_builder.py
344 lines (248 loc) · 7.96 KB
/
robot_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
"""
Build Robot
"""
from abc import abstractmethod, ABC
class Robot:
"""
Characteristics of Robot
"""
def __init__(self, robot_name: str) -> None:
self.label: str = robot_name
self.is_bi_pedal: bool = False
self.is_quad_pedal: bool = False
self.is_wheeled: bool = False
self.is_humanoid: bool = False
self.is_military: bool = False
self.is_acoustic: bool = False
self.can_fly: bool = False
self.body: list = []
self.intelligence_systems: list = []
def __fetch_representation(self) -> str:
"""__fetch_representation: String representation of characteristics and
installed body systems
Returns:
str: _description_
"""
__robot_info: str = f"Name: {self.label}"
__robot_info += "\n------------------------\n"
__robot_info += "Characteristics:"
__robot_info += "\n------------------------\n"
__counter = 1
if self.is_wheeled:
__robot_info += f"{__counter}: Wheeled\n"
__counter += 1
if self.is_bi_pedal:
__robot_info += f"{__counter}: Bi-Pedal\n"
__counter += 1
if self.is_quad_pedal:
__robot_info += f"{__counter}: Quad-Pedal\n"
__counter += 1
if self.is_humanoid:
__robot_info += f"{__counter}: Humanoid\n"
__counter += 1
if self.is_military:
__robot_info += f"{__counter}: Intended for Military\n"
__counter += 1
if self.is_acoustic:
__robot_info += f"{__counter}: Can Speak\n"
__counter += 1
if self.can_fly:
__robot_info += f"{__counter}: Can Fly\n"
__robot_info += "\n------------------------\n"
__robot_info += "Body:"
__robot_info += "\n------------------------\n"
for part_id, part_name in enumerate(self.body):
__robot_info += f"{part_id}: {part_name}\n"
__robot_info += "\n------------------------\n"
__robot_info += "Intelligence Systems:"
__robot_info += "\n------------------------\n"
for sys_id, sys_name in enumerate(self.intelligence_systems):
__robot_info += f"{sys_id}: {sys_name}\n"
return __robot_info
def __str__(self) -> str:
return self.__fetch_representation()
class BiPedal:
"""
Adds BiPedal to Body
"""
def __str__(self) -> str:
return "Two Legs"
class QuadPedal:
"""Adds QuadPedal to Body
"""
def __str__(self) -> str:
return "Four Legs"
class Wheels:
"""Add Wheels
"""
def __init__(self, wheel_count: int=2) -> None:
self.wheel_count: int = wheel_count
def __str__(self) -> str:
return f"{self.wheel_count} Wheels"
class Arms:
"""
Adds Arms
"""
def __init__(self, arm_count: int=2) -> None:
self.arms = arm_count
def __str__(self) -> str:
return f"{self.arms} Arms"
class Face:
"""Add Face Shape
"""
def __init__(self, face_shape: str) -> None:
self.face_shape = face_shape
def __str__(self) -> str:
return f"{self.face_shape}"
class Wings:
"""Add Wings
"""
def __init__(self, wing_count: 2) -> None:
self.wings: int = wing_count
def __str__(self) -> str:
return f"{self.wings} Wings"
class Voice:
"""Add Voice
"""
def __init__(self, gender: str=None) -> None:
self.voice_type = "Female"
if gender is not None:
self.voice_type = gender
def __str__(self) -> str:
return f"{self.voice_type} Voice"
class InfraRedSensor:
"""Add Infrared sensor
"""
def __str__(self) -> str:
return "Infrared Sensor"
class Weapon:
"""Add weapons
"""
def __init__(self, weapon_type: str=None) -> None:
self.weapon_type: str = "Pistol"
if weapon_type is not None:
self.weapon_type = weapon_type
def __str__(self) -> str:
return f"Weapon Type: {self.weapon_type}"
class HandGestures:
"""Add HandGestures
"""
def __str__(self) -> str:
return "Hand Gestures"
class ObstacleDetection:
"""Add Obstacle Detection
"""
def __str__(self) -> str:
return "Obstacle Detection"
class RobotBuilder(ABC):
"""RobotBuilder: Interaface for building Robot
"""
@abstractmethod
def build_body(self):
"""build_body: Build body
"""
raise NotImplementedError
@abstractmethod
def build_intelligence(self):
"""build_intelligence: Add Intelligence
"""
@abstractmethod
def display_specs(self):
"""display_specs: Display Robot Specs
"""
class MilitaryBot(RobotBuilder):
"""Create Military Robot
"""
def __init__(self, bot_name: str) -> None:
self.robot = Robot(robot_name=bot_name)
def build_body(self):
"""build_body: Build Military Standard body
"""
self.robot.is_military = True
self.robot.is_wheeled = True
self.robot.is_acoustic = True
self.robot.can_fly = True
square_face = Face(face_shape="Square")
two_arms = Arms()
male_voice = Voice(gender="Male")
machine_gun = Weapon(weapon_type="Machine Gun")
two_wings = Wings(wing_count=2)
body_info = [square_face, two_arms, male_voice, machine_gun, two_wings]
self.robot.body.extend(body_info)
def build_intelligence(self):
"""build_intelligence: Add intelligence to military robot
"""
self.robot.intelligence_systems.append(
InfraRedSensor()
)
self.robot.intelligence_systems.append(
ObstacleDetection()
)
def display_specs(self) -> str:
"""display_specs: Display Military Bot Specs
Returns:
str: String representation of specifications added
"""
return self.robot
class Humanoid(RobotBuilder):
"""Create Human assistant robot
"""
def __init__(self, bot_name: str) -> None:
self.robot = Robot(robot_name=bot_name)
def build_body(self):
"""build_body: Create body
"""
self.robot.is_acoustic = True
self.robot.is_bi_pedal = True
oval_face = Face(face_shape="Oval")
two_arms = Arms(arm_count=4)
female_voice = Voice(gender="Female")
body_info = [oval_face, two_arms, female_voice]
self.robot.body.extend(body_info)
def build_intelligence(self):
"""build_intelligence: Add intelligence
"""
self.robot.intelligence_systems.append(
HandGestures()
)
self.robot.intelligence_systems.append(
ObstacleDetection()
)
def display_specs(self) -> str:
"""display_specs: Display Humanoid Specs
Returns:
str: String representation of specifications added
"""
return self.robot
class Maker:
"""
Robot Maker
"""
def make_military_bot(self, builder: MilitaryBot) -> str:
"""make_robot: Create Military Robot
Args:
builder (object): Create robot with Military specification
"""
builder.build_body()
builder.build_intelligence()
return builder.display_specs()
def make_humanoid(self, builder: Humanoid) -> str:
"""make_humanoid: Create Humanoid
Args:
builder (Humanoid): Create robot with Humanoid specification
"""
builder.build_body()
builder.build_intelligence()
return builder.display_specs()
def main():
"""main: Create robots
"""
robot_maker = Maker()
military_builder = MilitaryBot(bot_name="Killer")
humanoid_builder = Humanoid(bot_name="Tesla")
military_specs = robot_maker.make_military_bot(builder=military_builder)
print(military_specs)
humanoid_specs = robot_maker.make_humanoid(builder=humanoid_builder)
print(humanoid_specs)
if __name__ == "__main__":
main()