forked from erciitb/Project-Robotic-Arm-LLM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_oops.py
152 lines (102 loc) · 3.08 KB
/
python_oops.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
# -*- coding: utf-8 -*-
"""Python OOPS
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1OCUzywJdL9tStlZsIqm_fezii_imZLBX
"""
class Rover:
rovgeo = [10, 10, 10]
def __init__(self, swarmid, roverid, rovloc):
self.swarmid = swarmid
self.roverid = roverid
self.rovloc = rovloc
def location(self):
print("Rover's location: ", self.rovloc)
print('Swarm ID: ', self.swarmid)
print('Rover ID: ', self.roverid)
def move(self, disp):
self.rovloc = self.rovloc + disp
print("Rover's location: ", self.rovloc)
def verify(self, swarmid, roverid, disp):
if swarmid == self.swarmid and roverid == self.roverid:
self.move(disp)
else:
print('Wrong rover')
class Daughter(Rover):
def __init__(self, swarmid, roverid, rovloc):
super().__init__(swarmid, roverid, rovloc)
rovgeo = [x/2 for x in Rover.rovgeo]
def move(self, disp):
return super().move(disp/2)
class User(Daughter):
ids = [[]]
def __init__(self, userid):
self.userid = userid
class Manager(User):
def __init__(self, userid):
super().__init__(userid)
def add_new(self, rover):
boolean = False
for i in range(len(self.ids)):
if self.ids[i] == (rover.swarmid, rover.roverid):
boolean = True
if boolean == False:
(self.ids).append((rover.swarmid, rover.roverid))
else:
print('Already there')
def remove(self, rover):
boolean = False
for i in range(len(self.ids)):
if self.ids[i] == (rover.swarmid, rover.roverid):
boolean = True
if boolean == True:
(self.ids).remove((rover.swarmid, rover.roverid))
else:
print('Not there')
class Scientist(User):
def __init__(self, userid):
super().__init__(userid)
def view(self, rover):
boolean = False
for i in range(len(self.ids)):
if self.ids[i] == (rover.swarmid, rover.roverid):
rover.location()
boolean = True
if boolean == False:
print('Not there')
class Operator(User):
def __init__(self, userid):
super().__init__(userid)
def control(self, rover, disp):
boolean = False
for i in range(len(self.ids)):
if self.ids[i] == (rover.swarmid, rover.roverid):
rover.move(disp)
boolean = True
if boolean == False:
print('Not there')
def find(self, rover1, rover2):
boolean1 = False
boolean2 = False
for i in range(len(self.ids)):
if self.ids[i] == (rover1.swarmid, rover1.roverid):
boolean1 = True
for j in range(len(self.ids)):
if self.ids[j] == (rover2.swarmid, rover2.roverid):
boolean2 = True
rover1.rovloc = rover2.rovloc
if boolean1 == False and boolean2 == False:
print('Not there')
rover1 = Rover(1, 1, 1)
rover2 = Rover(2, 2, 2)
manager1 = Manager(1)
scientist1 = Scientist(2)
manager1.add_new(rover2)
scientist1.view(rover2)
scientist1.view(rover1)
operator1 = Operator(3)
operator1.control(rover2, 5)
manager1.add_new(rover1)
operator1.find(rover1, rover2)
scientist1.view(rover2)
scientist1.view(rover1)