-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThing.java
More file actions
343 lines (295 loc) · 8.95 KB
/
Thing.java
File metadata and controls
343 lines (295 loc) · 8.95 KB
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
package foon;
import java.util.*;
public class Thing {
// An object or motion no matter what has a type which is used for reference to the string arrays made above.
private int identifier;
private List<Thing> list; // for adjacency list implementation
private String label;
public Thing(){
list = new ArrayList<Thing>();
label = "";
}
// constructor method for a Thing object
public Thing(int n)
{
identifier = n;
list = new ArrayList<Thing>();
label = "";
}
public void setLabel(String S){
label = S;
}
public String getLabel(){
return label;
}
// parse through list of neighbours to print neighbours
public void printNeighbours(){
if (list.isEmpty()){
System.out.println("Object has no neighbours!\n");
return;
}
System.out.print(" - Neighbours are: \t");
for (Thing t: list) {
if (t instanceof Object){
((Object)t).printObject();
}
else if (t instanceof Motion){
((Motion)t).printMotion();
}
else {
t.printThing();
}
System.out.print("\t\t\t");
}
System.out.println();
}
public String getNeighbours(){
String line = "";
if (list.isEmpty()){
return "Object has no neighbours!\n";
}
line += " - Neighbours are: \t";
for (Thing t: list) {
if (t instanceof Object){
line += ((Object)t).getObject();
}
else if (t instanceof Motion){
line += ((Motion)t).getMotion();
}
else {
line += t.getType();
}
line += "\n\t\t\t";
}
return line;
}
public int countNeighbours() {
// returns the number of degrees of a single node (i.e. the number of neighbours)
return list.size();
}
public List<Thing> getNeigbourList(){
return list;
}
public void addConnection(Thing t){
list.add(t);
}
public int getType(){
return identifier;
}
public void setType(int T){
identifier = T;
}
public boolean equals(Thing T){
return T.identifier == this.identifier;
}
public void printThing(){
if (this instanceof Object){
System.out.print(((Object)this).getObject());
}
else if (this instanceof Motion){
System.out.print(((Motion)this).getMotion());
}
else {
System.out.println("O" + this.getType() + "\t" + label);
}
}
static String[] objects = {
"bread", // 0
"cutting_board", // 1
"bread_knife", // 2
"bowl", // 3
"garlic", // 4
"butter", // 5
"parsley", // 6
"fork", // 7
"garlic_presser", // 8
"salt", // 9
"salt_grinder", // 10
"butter_knife", // 11
"baking_pan/tray", // 12
"plate", // 13
"garlic_salt", // 14
"oven", // 15
"spoon", // 16
"aluminum_foil", // 17
"pepper_shaker", // 18
"eggs", // 19
"cheese", // 20
"cup", // 21
"teacup", // 22
"tea_bag", // 23
"kettle", // 24
"stove", // 25
"saucepan", // 26
"paper_filter", // 27
"milk", // 28
"sugar", // 29
"jar", // 30
"teapot", // 31
"water_faucet", // 32
"water_filter" // 33
};
static String[][] states = {
new String[]{"whole", "half", "buttered", "baked"},
new String[]{""},
new String[]{""},
new String[]{"empty", "garlic", "butter", "parsley", "butter+garlic", "butter+garlic+parsley", "butter+garlic+parsley+salt", "mixed_butter"},
new String[]{"complete_clove", "chopped"},
new String[]{"80g_room_temperature", "mixed"},
new String[]{"finely chopped"},
new String[]{"clean", "dirty"},
new String[]{"clean", "open", "closed", "garlic", "empty"},
new String[]{""},
new String[]{""},
new String[]{"clean", "unclean"},
new String[]{""},
new String[]{""},
new String[]{""},
new String[]{"on", "off"},
new String[]{"clean", "dirty"},
new String[]{"flat", "folded", "unfolded"},
new String[]{""},
new String[]{"whole", "unshelled", "beaten"},
new String[]{"whole", "shredded", "melted"},
new String[]{"empty", "contains"},
new String[]{"empty", "sugar", "milk", "sugar+milk", "tea"},
new String[]{""},
new String[]{"empty", "room_temp_water", "hot_water"},
new String[]{"on", "off"},
new String[]{"water", "water+tea_leaves", "oil"},
new String[]{"clean", "with_leaves"},
new String[]{""},
new String[]{""},
new String[]{"open+teabag", "closed+teabag"},
new String[]{"empty+closed", "empty+open", "open+teabag", "closed+teabag", "open+teabag+water", "closed+teabag+water", "tea"},
new String[]{"on", "off"},
new String[]{""}
};
static String[] motions = {
"pick+place", //1 1
"cut", //2 1
"close tool", //3 rotate garlic presser ends to 0 degrees
"hold", //4 1
"brush off", //5 don't need it for simulation
"pour", //6 tilt object
"mix", //7 mix ingredients in bowl
"spread", //8 1
"scrape", //9 scrape off garlic from the garlic presser
"grind", //10
"scoop", //11 move knife with butter to the bread
"bake", //12
"cool/sit", //13
"wrap", //14
"unwrap", //15
"switch/turn_on", //16
"dip*", //17
"wait", //18
"open_tool/object", //19
"boil", //20
};
static String[] description = {
"<in motion>",
"<not in motion>",
"<assumed>"
};
}
class Object extends Thing {
// Each object has a type (from Thing property), a state, and a flag indicating if it is in motion.
private int objState;
private String stateLabel;
// constructor method for an Object object (lol)
public Object(int n, int S, String M, String L){
super(n);
objState = S;
setLabel(M);
setStateLabel(L);
}
public Object(int n, int S){
super(n);
objState = S;
}
public boolean equals(Object O){
return (O.getObjectType() == this.getObjectType() && O.getObjectState() == this.getObjectState());
}
public int getObjectType(){
return getType();
}
public String getStateLabel(){
return stateLabel;
}
public int getObjectState(){
return objState;
}
public void printObject(){
System.out.println("O" + this.getType() + "\t" + this.getLabel() + "\nS" + this.getObjectState() + "\t" + this.getStateLabel());
}
public String getObject(){
return ("O" + this.getType() + "\t"+this.getLabel()+ "\nS" + this.getObjectState() + "\t" + this.getStateLabel());
}
public void setObjectType(int T){
setType(T);
}
public void setObjectState(int S){
objState = S;
}
public void setStateLabel(String S){
stateLabel = S;
}
public int existsFU(){
// a functional unit begins with an object and ends with objects;
// therefore, we need to check if a motion exists and if the objects attached are the same.
for (int i = this.countNeighbours() - 1; i >= 0 ; i--){
for (int j = 0; j < this.countNeighbours() && i != j; j++){
if (((Motion)this.getNeigbourList().get(i)).equals(((Motion)this.getNeigbourList().get(j)))){
// there is a motion of the same type
if (((Motion)this.getNeigbourList().get(i)).countNeighbours() == ((Motion)this.getNeigbourList().get(j)).countNeighbours()){
// they have the same number of neighbours
int count = 0, total = ((Motion)this.getNeigbourList().get(j)).countNeighbours();
for (int x = 0; x < total; x++){
if (((Motion)this.getNeigbourList().get(i)).getNeigbourList().contains(((Motion)this.getNeigbourList().get(j)).getNeigbourList().get(x))){
count++;
}
}
if (count == total){
// if all objects have been found connected to that motion then we have that FU already!
return i;
}
}
}
}
}
return -1;
}
}
class Motion extends Thing {
// constructor method for a Motion object
public Motion(int n){
super(n);
}
public Motion(int n, String L){
super(n);
this.setLabel(L);
}
public int getMotionType(){
return getType();
}
public void printMotion(){
System.out.println("M"+this.getMotionType()+"\t"+this.getLabel()+"");
}
public String getMotion(){
return ("M"+this.getType()+"\t"+this.getLabel());
}
public boolean equals(Motion M){
return M.getType() == this.getType();
}
// Prints the motion name associated with the Motion object.
public void printMotionWithDescription()
{
System.out.println("[" + motions[getType() - 1] + "]");
}
public void setMotionType(int T){
setType(T);
}
public Motion(){
};
}