-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField.py
384 lines (341 loc) · 16.9 KB
/
Field.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import random
import array
from Vault import Vault
from Robots import Robots
from Scale import Scale
from Switch import Switch
from Alliance import Alliance
from Points import Points
from Output import Output
class Field:
def __init__(self):
#print("init")
# Game things
self.red_vault = Vault(True, self)
self.blue_vault = Vault(False, self)
self.my_switch = Switch(True)
self.their_switch = Switch(False)
self.scale = Scale(True)
self.time = 0
self.queue = []
#output
self.output = Output()
self.red_own_switch_control = 0
self.red_opposite_switch_control = 0
self.blue_own_switch_control = 0
self.blue_opposite_switch_control = 0
self.red_scale_control = 0
self.blue_scale_control = 0
self.red_vault_cubes = 0
self.blue_vault_cubes = 0
self.red_baseline = 0
self.blue_baseline = 0
# Robots
self.red_alliance = Alliance(self, True)#self.red_alliance.points to edits
self.blue_alliance = Alliance(self, False)
self.alliances = [self.blue_alliance.robots, self.red_alliance.robots]
self.set_output_skills()
def tick(self, time):
self.time = time
#print(f"Boost|Force|Lev : {self.red_vault.boost_cubes}|{self.red_vault.force_cubes}|{self.red_vault.lev_cubes}")
#print(f"My Red Cubes|Blue Cubes : {self.my_switch.red_cubes}|{self.my_switch.blue_cubes}")
#print(f"Their Red Cubes|Blue Cubes : {self.their_switch.red_cubes}|{self.their_switch.blue_cubes}")
#print(f"Red Scale Cubes|Blue Scale Cubes : {self.scale.red_cubes1}|{self.scale.blue_cubes1}")
for alliance in self.alliances:
for team in alliance:
team.tick(time)
self.my_switch_points()
self.their_switch_points()
self.scale_points()
# print(f"Red Alliance Score : {self.red_alliance.points}")
# print(f"Blue Alliance Score : {self.blue_alliance.points}")
self.red_power_tick(time)
self.blue_power_tick(time)
self.power_queue()
self.red_vault.lev_check()
self.blue_vault.lev_check()
def red_power_tick(self, time):
if self.red_vault.power_time > 0:
self.red_vault.power_time -= 1
elif self.red_vault.power_time == 0:
if len(self.queue) > 0:
self.queue.remove(self.queue[0])
elif random.randint(1,60) > 59:
self.red_vault.powerup()
else:
if random.randint(1,60) > 59:
self.red_vault.powerup()
def blue_power_tick(self, time):
if self.blue_vault.power_time > 0:
self.blue_vault.power_time -= 1
elif self.blue_vault.power_time == 0:
if len(self.queue) > 0:
self.queue.remove(self.queue[0])
elif random.randint(1,60) > 59:
self.blue_vault.powerup()
else:
if random.randint(1,60) > 59:
self.blue_vault.powerup()
# 1 is Red Alliance Boost
# 2 is Red Alliance Force
# 3 is Blue Alliance Boost
# 4 is Blue Alliance Force
#make sure you set both red and blue "can use" to false
def power_queue(self):
if len(self.queue) > 0:
if self.queue[0] == 1:
self.red_vault.boost = True
self.red_vault.boost_used = self.time
self.red_vault.boost_used_cubes = self.red_vault.boost_cubes
elif self.queue[0] == 2:
self.red_vault.force = True
self.red_vault.force_used = self.time
self.red_vault.force_used_cubes = self.red_vault.force_cubes
elif self.queue[0] == 3:
self.blue_vault.boost = True
self.blue_vault.boost_used = self.time
self.blue_vault.boost_used_cubes = self.blue_vault.boost_cubes
elif self.queue[0] == 4:
self.blue_vault.force = True
self.blue_vault.force_used = self.time
self.blue_vault.force_used_cubes = self.blue_vault.force_cubes
else:
pass
def auto_tick(self, time):
self.time = time
for alliance in self.alliances:
for team in alliance:
team.tick(time)
team.baseline()
self.auto_my_switch_points()
self.auto_their_switch_points()
self.auto_scale_points()
def add_random_vault_cube(self, is_red_alliance):
if is_red_alliance:
self.red_vault.add_random_cube()
else:
self.blue_vault.add_random_cube()
def add_my_switch_cube(self, is_red_alliance):
if is_red_alliance:
self.my_switch.add_switch_cube(is_red_alliance)
else:
self.their_switch.add_switch_cube(is_red_alliance)
def add_their_switch_cube(self, is_red_alliance):
if is_red_alliance:
self.their_switch.add_switch_cube(is_red_alliance)
else:
self.my_switch.add_switch_cube(is_red_alliance)
def add_scale_cube(self, is_red_alliance):
self.scale.add_scale_cube(is_red_alliance)
def checkIfWin(self):
#print(f"Red Alliance Score : {self.red_alliance.points}")
#print(f"Blue Alliance Score : {self.blue_alliance.points}")
if self.red_alliance.points > self.blue_alliance.points:
print(f"The Red Alliance won!")
elif self.blue_alliance.points > self.red_alliance.points:
print(f"The Blue Alliance won!")
else:
print("Its a tie!")
def my_switch_points(self):
if self.my_switch.red_cubes > self.my_switch.blue_cubes:
self.red_own_switch_control += 1
if self.red_vault.boost and (self.red_vault.boost_cubes == 1 or self.red_vault.boost_cubes == 3):
self.red_alliance.points += 2
else:
self.red_alliance.points += 1
elif self.red_vault.force and (self.red_vault.force_cubes == 1 or self.red_vault.force_cubes == 3):
self.red_own_switch_control += 1
self.red_alliance.points += 1
elif self.my_switch.blue_cubes > self.my_switch.red_cubes:
self.blue_opposite_switch_control += 1
def their_switch_points(self):
if self.their_switch.blue_cubes > self.their_switch.red_cubes:
if self.blue_vault.boost and (self.blue_vault.boost_cubes == 1 or self.blue_vault.boost_cubes == 3):
self.blue_alliance.points += 2
self.blue_own_switch_control += 1
else:
self.blue_alliance.points += 1
self.blue_own_switch_control += 1
elif self.blue_vault. force and (self.blue_vault.force_cubes == 1 or self.blue_vault.force_cubes == 3):
self.blue_alliance.points += 1
self.blue_own_switch_control += 1
elif self.their_switch.red_cubes > self.their_switch.blue_cubes:
self.red_opposite_switch_control += 1
def scale_points(self):
if self.red_vault.force and (self.red_vault.force_cubes == 2 and self.red_vault.force_cubes == 3):
self.red_alliance.points += 1
self.red_scale_control += 1
elif self.blue_vault.force and (self.blue_vault.force_cubes == 2 and self.blue_vault.force_cubes == 3):
self.blue_alliance.points += 1
self.blue_scale_control += 1
elif self.scale.red_cubes1 > self.scale.blue_cubes1:
if self.red_vault.boost and (self.red_vault.boost_cubes == 2 and self.red_vault.boost_cubes == 3):
self.red_alliance.points += 2
self.red_scale_control += 1
else:
self.red_alliance.points += 1
self.red_scale_control += 1
elif self.scale.blue_cubes1 > self.scale.red_cubes1:
if self.blue_vault.boost and (self.blue_vault.boost_cubes == 2 and self.blue_vault.boost_cubes == 3):
self.blue_alliance.points += 1
self.blue_scale_control += 1
else:
self.red_alliance.points += 1
self.blue_scale_control += 1
def endgame_scoring(self):
self.red_park_counter = 0
self.red_climb_counter = 0
self.blue_park_counter = 0
self.blue_climb_counter = 0
for alliance in self.alliances:
for team in alliance:
print(f"{team.name} {team.climb} {team.platform}")
if team.climb == True and team.is_red_alliance:
self.red_alliance.points += 30
self.red_climb_counter += 1
elif team.climb == True and team.is_red_alliance == False:
self.blue_alliance.points += 30
self.blue_climb_counter += 1
elif team.platform == True and team.is_red_alliance:
self.red_alliance.points += 5
self.red_park_counter += 1
elif team.platform == True and team.is_red_alliance == False:
self.blue_alliance.points += 5
self.blue_park_counter += 1
if self.red_vault.lev and self.red_climb_counter < 3:
if self.red_climb_counter + self.red_park_counter < 3:
self.red_alliance.points += 30
else:
self.red_alliance.points += 25
elif self.blue_vault.lev and self.blue_climb_counter < 3:
if self.blue_climb_counter + self.blue_park_counter < 3:
self.blue_alliance.points += 30
else:
self.blue_alliance.points += 25
def auto_my_switch_points(self):
if self.my_switch.red_cubes > self.my_switch.blue_cubes:
self.red_alliance.points += 2
self.red_own_switch_control += 1
elif self.my_switch.blue_cubes > self.my_switch.red_cubes:
self.blue_alliance.points += 2
self.blue_opposite_switch_control += 1
def auto_their_switch_points(self):
if self.their_switch.red_cubes > self.their_switch.blue_cubes:
self.red_alliance.points += 2
self.red_opposite_switch_control += 1
elif self.their_switch.blue_cubes > self.their_switch.red_cubes:
self.blue_alliance.points += 2
self.blue_own_switch_control += 1
def auto_scale_points(self):
if self.scale.red_cubes1 > self.scale.blue_cubes1:
self.red_alliance.points += 2
self.red_scale_control += 1
elif self.scale.blue_cubes1 > self.scale.red_cubes1:
self.blue_alliance.points += 2
self.blue_scale_control += 1
def baseline_points(self):
for alliance in self.alliances:
for team in alliance:
if team.is_red_alliance and team.auto_run == True:
print(f"Red did baseline: {team.name}")
self.red_alliance.points += 5
self.red_baseline += 1
elif team.is_red_alliance == False and team.auto_run == True:
print(f"Blue did baseline: {team.name}")
self.blue_alliance.points += 5
self.blue_baseline += 1
#OUTPUTS
#created a method to check when the alliance used levitation
#would give it a new value every second - so make another variable
def last_time_lev_used(self, is_red_alliance):
if self.red_vault.lev_method_used == 0 and self.red_vault.lev == True:
self.output.red_lev_time = self.time
self.red_vault.lev_method_used += 1
elif self.blue_vault.lev_method_used == 0 and self.blue_vault.lev == True:
self.output.blue_lev_time = self.time
self.blue_vault.lev_method_used += 1
def powerup_output(self):
#When it was played
#create a variable that is set equal to the time when powerup is used?
#Number of cubes when it was played
#Was lev used Y/N
#time
#Red Alliance
self.output.red_boost = self.red_vault.boost
self.output.red_boost_time = self.red_vault.boost_used
self.output.red_force_time = self.red_vault.force_used
self.output.red_lev_time = self.red_vault.lev_used
self.output.red_boost_cubes_used = self.red_vault.boost_used_cubes
self.output.red_force_cubes_used = self.red_vault.force_used_cubes
self.output.red_lev_used = self.red_vault.lev
#Blue Alliance
self.output.blue_boost_time = self.blue_vault.boost_used
self.output.blue_force_time = self.blue_vault.force_used
self.output.blue_lev_time = self.blue_vault.lev_used
self.output.blue_boost_cubes_used = self.blue_vault.boost_used_cubes
self.output.blue_force_cubes_used = self.blue_vault.force_used_cubes
self.output.blue_lev_used = self.blue_vault.lev
def set_output_skills(self):
self.output.red_one_skill = self.red_alliance.robots[0].skillRating
self.output.red_two_skill = self.red_alliance.robots[1].skillRating
self.output.red_three_skill = self.red_alliance.robots[2].skillRating
self.output.blue_one_skill = self.blue_alliance.robots[0].skillRating
self.output.blue_two_skill = self.blue_alliance.robots[1].skillRating
self.output.blue_three_skill = self.blue_alliance.robots[2].skillRating
def time_controlled_output(self):
self.output.red_own_switch_control = self.red_own_switch_control
self.output.red_opposite_switch_control = self.red_opposite_switch_control
self.output.blue_own_switch_control = self.blue_own_switch_control
self.output.blue_opposite_switch_control = self.blue_opposite_switch_control
self.output.red_scale_control = self.red_scale_control
self.output.blue_scale_control = self.blue_scale_control
def auto_time_controlled_output(self):
self.auto_red_own_switch_control = self.red_own_switch_control
self.auto_red_opposite_switch_control = self.red_opposite_switch_control
self.auto_blue_own_switch_control = self.blue_own_switch_control
self.auto_blue_opposite_switch_control = self.blue_opposite_switch_control
self.auto_red_scale_control = self.red_scale_control
self.auto_blue_scale_control = self.blue_scale_control
def vault_output(self):
self.output.red_lev_cubes = self.red_vault.lev_cubes
self.output.red_boost_cubes = self.red_vault.boost_cubes
self.output.red_force_cubes = self.red_vault.lev_cubes
self.output.red_overflow_cubes = self.red_vault.overflow_cubes
self.output.blue_lev_cubes = self.blue_vault.lev_cubes
self.output.blue_boost_cubes = self.blue_vault.boost_cubes
self.output.blue_force_cubes = self.blue_vault.force_cubes
self.output.blue_overflow_cubes = self.blue_vault.overflow_cubes
def auto_vault_output(self):
self.output.auto_red_lev_cubes = self.red_vault.lev_cubes
self.output.auto_red_boost_cubes = self.red_vault.boost_cubes
self.output.auto_red_force_cubes = self.red_vault.lev_cubes
self.output.auto_red_overflow_cubes = self.red_vault.overflow_cubes
self.output.auto_blue_lev_cubes = self.blue_vault.lev_cubes
self.output.auto_blue_boost_cubes = self.blue_vault.boost_cubes
self.output.auto_blue_force_cubes = self.blue_vault.force_cubes
self.output.auto_blue_overflow_cubes = self.blue_vault.overflow_cubes
def endgame_output(self):
self.output.red_num_parked = self.red_park_counter
self.output.red_num_climbed = self.red_climb_counter
self.output.blue_num_climbed = self.blue_climb_counter
self.output.blue_num_parked = self.blue_park_counter
def total_points(self):
self.output.red_alliance_total = self.red_alliance.points
self.output.blue_alliance_total = self.blue_alliance.points
def cube_tracking_output(self):
self.output.red_own_switch_cubes = self.my_switch.red_cubes
self.output.blue_own_switch_cubes = self.their_switch.blue_cubes
self.output.red_opposite_switch_cubes = self.their_switch.red_cubes
self.output.blue_opposite_switch_cubes = self.my_switch.blue_cubes
self.output.red_scale_cubes = self.scale.red_cubes1
self.output.blue_scale_cubes = self.scale.blue_cubes1
def auto_cube_tracking_output(self):
self.output.auto_red_own_switch_cubes = self.my_switch.red_cubes
self.output.auto_blue_own_switch_cubes = self.their_switch.blue_cubes
self.output.auto_red_opposite_switch_cubes = self.their_switch.red_cubes
self.output.auto_blue_opposite_switch_cubes = self.my_switch.blue_cubes
self.output.auto_red_scale_cubes = self.scale.red_cubes1
self.output.auto_blue_scale_cubes = self.scale.blue_cubes1
print(f"Red: {self.red_baseline}, Blue: {self.blue_baseline}")
self.output.red_baseline = self.red_baseline
self.output.blue_baseline = self.blue_baseline