-
Notifications
You must be signed in to change notification settings - Fork 0
/
swarmbrain_launch.py
2682 lines (2342 loc) · 128 KB
/
swarmbrain_launch.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import asyncio
import random
from typing import Union
from datetime import datetime
from sc2 import maps
from sc2.bot_ai import BotAI
from sc2.constants import *
from sc2.data import Race, Difficulty, ActionResult
from sc2.main import run_game
from sc2.player import Bot, Computer, Human
from sc2.unit import Unit
from sc2.position import Point2, Point3
from sc2.units import Units
from swarmbrain import *
class SwarmBrain(BotAI):
def __init__(self, command_first, early_values, mid_values, late_values, drone_attack, counterattack):
super().__init__()
# print("early_values", early_values)
# print("mid_values", mid_values)
# print("late_values", late_values)
self.early_zergling_num, self.early_baneling_num, self.early_roach_num, self.early_ravager_num, self.early_hydralisk_num, self.early_infestor_num, self.early_swarm_host_num, self.early_mutalisk_num, self.early_corruptor_num, self.early_viper_num, self.early_ultralisk_num, self.early_brood_lord_num = early_values
self.mid_zergling_num, self.mid_baneling_num, self.mid_roach_num, self.mid_ravager_num, self.mid_hydralisk_num, self.mid_infestor_num, self.mid_swarm_host_num, self.mid_mutalisk_num, self.mid_corruptor_num, self.mid_viper_num, self.mid_ultralisk_num, self.mid_brood_lord_num = mid_values
self.late_zergling_num, self.late_baneling_num, self.late_roach_num, self.late_ravager_num, self.late_hydralisk_num, self.late_infestor_num, self.late_swarm_host_num, self.late_mutalisk_num, self.late_corruptor_num, self.late_viper_num, self.late_ultralisk_num, self.late_brood_lord_num = late_values
# print("self.early_hydralisk_num", self.early_hydralisk_num)
# print("self.mid_hydralisk_num", self.mid_hydralisk_num)
# print("self.late_hydralisk_num", self.late_hydralisk_num)
self.start_location_label = None
self.parsed_commands = []
self.command_list = command_first
self.building_tasks = []
self.attack_tasks = []
self.mineral_location_labels = {
(29.5, 65.5): "A1",
(35.5, 34.5): "A2",
(56.5, 65.5): "A3",
(63.5, 26.5): "A4",
(80.5, 66.5): "A5",
(98.5, 26.5): "A6",
(129.5, 28.5): "A7",
(33.5, 105.5): "A8",
(154.5, 114.5): "B1",
(148.5, 145.5): "B2",
(127.5, 114.5): "B3",
(120.5, 153.5): "B4",
(103.5, 113.5): "B5",
(85.5, 153.5): "B6",
(54.5, 151.5): "B7",
(150.5, 74.5): "B8"
}
self.mineral_location_labels_reverse = {
"A1": (29.5, 65.5),
"A2": (35.5, 34.5),
"A3": (56.5, 65.5),
"A4": (63.5, 26.5),
"A5": (80.5, 66.5),
"A6": (98.5, 26.5),
"A7": (129.5, 28.5),
"A8": (33.5, 105.5),
"B1": (154.5, 114.5),
"B2": (148.5, 145.5),
"B3": (127.5, 114.5),
"B4": (120.5, 153.5),
"B5": (103.5, 113.5),
"B6": (85.5, 153.5),
"B7": (54.5, 151.5),
"B8": (150.5, 74.5)
}
self.existing_hatchery_locations = []
self.worker_aggressive = drone_attack
self.counterattack = counterattack
self.hatchery_queen_pairs = {}
self.waiting_for_hatchery = True
self.is_attack_command_issued = False
self.previous_enemy_units = {}
self.previous_enemy_units_attack = {}
self.previous_enemy_damage = 0
self.previous_enemy_buildings = {}
self.previous_commands = []
self.base_being_attacked = False
self.defence = False
self.spread_distance = 13
self.game_stage = 0
self.attack_wave = 0
self.fight_back = False
self.queen_spread_progress = {}
async def on_start(self):
# # self.client.game_step = 2
# # await self.client.debug_show_map()
start_location_key = tuple(self.start_location)
# print("start_location_key ", start_location_key)
self.start_location_label = self.mineral_location_labels.get(start_location_key)
if self.start_location_label:
print(f"Our starting location is at {self.start_location_label}")
else:
print("Could not determine the start location label.")
self.command_list = self.filter_commands(self.command_list,
['Queen', 'Gather minerals', 'Extractor', 'Mineral', 'Overlord',
'Move', 'Zergling', 'Creep'])
if self.start_location_label == "A1":
Overmind_commands = self.command_list
new_command_list = []
if self.start_location_label == "B1":
for command in self.command_list:
def replace(match):
char, num = match.group(1), match.group(2)
return 'B' + num if char == 'A' else 'A' + num
command = re.sub(r'(A|B)(\d+)', replace, command)
new_command_list.append(command)
Overmind_commands = new_command_list
pattern = re.compile(r'\(([^)]+)\)')
for command in Overmind_commands:
parts = pattern.findall(command)
self.parsed_commands.append(parts)
# print("self.parsed_commands:", self.parsed_commands)
def get_units_distribution(self):
distribution = {}
for mineral_position, location_label in self.mineral_location_labels.items():
units_near_townhall = self.units.closer_than(20, mineral_position)
larvas_near_townhall = units_near_townhall.of_type({UnitTypeId.LARVA})
drones_near_townhall = units_near_townhall.of_type({UnitTypeId.DRONE})
overlords_near_townhall = units_near_townhall.of_type({UnitTypeId.OVERLORD})
queens_near_townhall = units_near_townhall.of_type({UnitTypeId.QUEEN})
zerglings_near_townhall = units_near_townhall.of_type({UnitTypeId.ZERGLING})
overseers_near_townhall = units_near_townhall.of_type({UnitTypeId.OVERSEER})
roaches_near_townhall = units_near_townhall.of_type({UnitTypeId.ROACH})
ravagers_near_townhall = units_near_townhall.of_type({UnitTypeId.RAVAGER})
banelings_near_townhall = units_near_townhall.of_type({UnitTypeId.BANELING})
hydralisks_near_townhall = units_near_townhall.of_type({UnitTypeId.HYDRALISK})
infestors_near_townhall = units_near_townhall.of_type({UnitTypeId.INFESTOR})
swarmhosts_near_townhall = units_near_townhall.of_type({UnitTypeId.SWARMHOSTMP})
mutalisks_near_townhall = units_near_townhall.of_type({UnitTypeId.MUTALISK})
corruptors_near_townhall = units_near_townhall.of_type({UnitTypeId.CORRUPTOR})
vipers_near_townhall = units_near_townhall.of_type({UnitTypeId.VIPER})
ultralisks_near_townhall = units_near_townhall.of_type({UnitTypeId.ULTRALISK})
broodlord_near_townhall = units_near_townhall.of_type({UnitTypeId.BROODLORD})
# Now collect the summary for this point
unit_summary = f""
if larvas_near_townhall.amount > 0:
unit_summary += f"{larvas_near_townhall.amount} Larvas are idling"
if drones_near_townhall.amount > 0:
unit_summary += f", {drones_near_townhall.amount} Drones are gathering mineral and gas in Hatchery"
if overlords_near_townhall.amount > 0:
unit_summary += f", {overlords_near_townhall.amount} Overlords are idling"
if queens_near_townhall.amount > 0:
unit_summary += f", {queens_near_townhall.amount} Queens are idling"
if zerglings_near_townhall.amount > 0:
unit_summary += f", {zerglings_near_townhall.amount} Zerglings are idling"
if overseers_near_townhall.amount > 0:
unit_summary += f", {overseers_near_townhall.amount} Overseers are idling"
if roaches_near_townhall.amount > 0:
unit_summary += f", {roaches_near_townhall.amount} Roaches are idling"
if ravagers_near_townhall.amount > 0:
unit_summary += f", {ravagers_near_townhall.amount} Ravagers are idling"
if banelings_near_townhall.amount > 0:
unit_summary += f", {banelings_near_townhall.amount} Banelings are idling"
if hydralisks_near_townhall.amount > 0:
unit_summary += f", {hydralisks_near_townhall.amount} Hydralisks are idling"
if infestors_near_townhall.amount > 0:
unit_summary += f", {infestors_near_townhall.amount} Infestors are idling"
if swarmhosts_near_townhall.amount > 0:
unit_summary += f", {swarmhosts_near_townhall.amount} Swarm Hosts are idling"
if mutalisks_near_townhall.amount > 0:
unit_summary += f", {mutalisks_near_townhall.amount} Mutalisks are idling"
if corruptors_near_townhall.amount > 0:
unit_summary += f", {corruptors_near_townhall.amount} Corruptors are idling"
if vipers_near_townhall.amount > 0:
unit_summary += f", {vipers_near_townhall.amount} Vipers are idling"
if ultralisks_near_townhall.amount > 0:
unit_summary += f", {ultralisks_near_townhall.amount} Ultralisks are idling"
if broodlord_near_townhall.amount > 0:
unit_summary += f", {broodlord_near_townhall.amount} Brood Lords are idling"
if unit_summary == "":
continue
# Assign the summary to the distribution dict
distribution[location_label] = unit_summary
return distribution
def get_units_all(self):
drones = self.units(UnitTypeId.DRONE).amount
overlords = self.units(UnitTypeId.OVERLORD).amount
queens = self.units(UnitTypeId.QUEEN).amount
zerglings = self.units(UnitTypeId.ZERGLING).amount
overseers = self.units(UnitTypeId.OVERSEER).amount
roaches = self.units(UnitTypeId.ROACH).amount
ravagers = self.units(UnitTypeId.RAVAGER).amount
banelings = self.units(UnitTypeId.BANELING).amount
hydralisks = self.units(UnitTypeId.HYDRALISK).amount
infestors = self.units(UnitTypeId.INFESTOR).amount
swarmhosts = self.units(UnitTypeId.SWARMHOSTMP).amount
mutalisks = self.units(UnitTypeId.MUTALISK).amount
corruptors = self.units(UnitTypeId.CORRUPTOR).amount
vipers = self.units(UnitTypeId.VIPER).amount
ultralisks = self.units(UnitTypeId.ULTRALISK).amount
broodlords = self.units(UnitTypeId.BROODLORD).amount
summary = f""
if drones > 0:
summary += f"{drones} Drones"
if overlords > 0:
if summary:
summary += f", {overlords} Overlords"
else:
summary += f"{overlords} Overlords"
if queens > 0:
if summary:
summary += f", {queens} Queens"
else:
summary += f"{queens} Queens"
if zerglings > 0:
if summary:
summary += f", {zerglings} Zerglings"
else:
summary += f"{zerglings} Zerglings"
if overseers > 0:
if summary:
summary += f", {overseers} Overseers"
else:
summary += f"{overseers} Overseers"
if roaches > 0:
if summary:
summary += f", {roaches} Roaches"
else:
summary += f"{roaches} Roaches"
if ravagers > 0:
if summary:
summary += f", {ravagers} Ravagers"
else:
summary += f"{ravagers} Ravagers"
if banelings > 0:
if summary:
summary += f", {banelings} Banelings"
else:
summary += f"{banelings} Banelings"
if hydralisks > 0:
if summary:
summary += f", {hydralisks} Hydralisks"
else:
summary += f"{hydralisks} Hydralisks"
if infestors > 0:
if summary:
summary += f", {infestors} Infestors"
else:
summary += f"{infestors} Infestors"
if swarmhosts > 0:
if summary:
summary += f", {swarmhosts} Swarm Hosts"
else:
summary += f"{swarmhosts} Swarm Hosts"
if mutalisks > 0:
if summary:
summary += f", {mutalisks} Mutalisks"
else:
summary += f"{mutalisks} Mutalisks"
if corruptors > 0:
if summary:
summary += f", {corruptors} Corruptors"
else:
summary += f"{corruptors} Corruptors"
if vipers > 0:
if summary:
summary += f", {vipers} Vipers"
else:
summary += f"{vipers} Vipers"
if ultralisks > 0:
if summary:
summary += f", {ultralisks} Ultralisks"
else:
summary += f"{ultralisks} Ultralisks"
if broodlords > 0:
if summary:
summary += f", {broodlords} Brood Lords"
else:
summary += f"{broodlords} Brood Lords"
return summary
def get_units_all_attack(self):
zerglings = self.units(UnitTypeId.ZERGLING).amount
roaches = self.units(UnitTypeId.ROACH).amount
ravagers = self.units(UnitTypeId.RAVAGER).amount
banelings = self.units(UnitTypeId.BANELING).amount
hydralisks = self.units(UnitTypeId.HYDRALISK).amount
infestors = self.units(UnitTypeId.INFESTOR).amount
swarmhosts = self.units(UnitTypeId.SWARMHOSTMP).amount
mutalisks = self.units(UnitTypeId.MUTALISK).amount
corruptors = self.units(UnitTypeId.CORRUPTOR).amount
vipers = self.units(UnitTypeId.VIPER).amount
ultralisks = self.units(UnitTypeId.ULTRALISK).amount
broodlords = self.units(UnitTypeId.BROODLORD).amount
army_damage = zerglings * 5 + roaches * 16 + ravagers * 16 + banelings * 16 + hydralisks * 12 + mutalisks * 9 + corruptors * 14 + ultralisks * 35 + broodlords * 20
summary = f""
if zerglings > 0:
summary += f"{zerglings} Zerglings"
if roaches > 0:
if summary:
summary += f", {roaches} Roaches"
else:
summary += f"{roaches} Roaches"
if ravagers > 0:
if summary:
summary += f", {ravagers} Ravagers"
else:
summary += f"{ravagers} Ravagers"
if banelings > 0:
if summary:
summary += f", {banelings} Banelings"
else:
summary += f"{banelings} Banelings"
if hydralisks > 0:
if summary:
summary += f", {hydralisks} Hydralisks"
else:
summary += f"{hydralisks} Hydralisks"
if infestors > 0:
if summary:
summary += f", {infestors} Infestors"
else:
summary += f"{infestors} Infestors"
if swarmhosts > 0:
if summary:
summary += f", {swarmhosts} Swarm Hosts"
else:
summary += f"{swarmhosts} Swarm Hosts"
if mutalisks > 0:
if summary:
summary += f", {mutalisks} Mutalisks"
else:
summary += f"{mutalisks} Mutalisks"
if corruptors > 0:
if summary:
summary += f", {corruptors} Corruptors"
else:
summary += f"{corruptors} Corruptors"
if vipers > 0:
if summary:
summary += f", {vipers} Vipers"
else:
summary += f"{vipers} Vipers"
if ultralisks > 0:
if summary:
summary += f", {ultralisks} Ultralisks"
else:
summary += f"{ultralisks} Ultralisks"
if broodlords > 0:
if summary:
summary += f", {broodlords} Brood Lords"
else:
summary += f"{broodlords} Brood Lords"
return summary, army_damage
def get_buildings_distribution(self):
distribution = {}
for townhall in self.townhalls.ready:
townhall_location_label = self.mineral_location_labels.get(townhall.position)
buildings_near_townhall = self.structures.closer_than(20, townhall.position)
extractor_near_townhall = buildings_near_townhall.of_type({UnitTypeId.EXTRACTOR})
spawningpool_near_townhall = buildings_near_townhall.of_type({UnitTypeId.SPAWNINGPOOL})
evolutionchamber_near_townhall = buildings_near_townhall.of_type({UnitTypeId.EVOLUTIONCHAMBER})
roachwarren_near_townhall = buildings_near_townhall.of_type({UnitTypeId.ROACHWARREN})
banelingnest_near_townhall = buildings_near_townhall.of_type({UnitTypeId.BANELINGNEST})
spinecrawler_near_townhall = buildings_near_townhall.of_type({UnitTypeId.SPINECRAWLER})
sporecrawler_near_townhall = buildings_near_townhall.of_type({UnitTypeId.SPORECRAWLER})
hydraliskden_near_townhall = buildings_near_townhall.of_type({UnitTypeId.HYDRALISKDEN})
infestationpit_near_townhall = buildings_near_townhall.of_type({UnitTypeId.INFESTATIONPIT})
spire_near_townhall = buildings_near_townhall.of_type({UnitTypeId.SPIRE})
nydusnetwork_near_townhall = buildings_near_townhall.of_type({UnitTypeId.NYDUSNETWORK})
ultraliskcavern_near_townhall = buildings_near_townhall.of_type({UnitTypeId.ULTRALISKCAVERN})
greaterspire_near_townhall = buildings_near_townhall.of_type({UnitTypeId.GREATERSPIRE})
unit_summary = f"1 {townhall.name.lower()}"
if extractor_near_townhall.amount > 0:
unit_summary += f", {extractor_near_townhall.amount} Extractor"
if spawningpool_near_townhall.amount > 0:
unit_summary += f", {spawningpool_near_townhall.amount} Spawning Pool"
if evolutionchamber_near_townhall.amount > 0:
unit_summary += f", {evolutionchamber_near_townhall.amount} Evolution Chamber"
if roachwarren_near_townhall.amount > 0:
unit_summary += f", {roachwarren_near_townhall.amount} Roach Warren"
if banelingnest_near_townhall.amount > 0:
unit_summary += f", {banelingnest_near_townhall.amount} Baneling Nest"
if spinecrawler_near_townhall.amount > 0:
unit_summary += f", {spinecrawler_near_townhall.amount} Spine Crawler"
if sporecrawler_near_townhall.amount > 0:
unit_summary += f", {sporecrawler_near_townhall.amount} Spore Crawler"
if hydraliskden_near_townhall.amount > 0:
unit_summary += f", {hydraliskden_near_townhall.amount} Hydralisk Den"
if infestationpit_near_townhall.amount > 0:
unit_summary += f", {infestationpit_near_townhall.amount} Infestation Pit"
if spire_near_townhall.amount > 0:
unit_summary += f", {spire_near_townhall.amount} Spire"
if nydusnetwork_near_townhall.amount > 0:
unit_summary += f", {nydusnetwork_near_townhall.amount} Nydus Network"
if ultraliskcavern_near_townhall.amount > 0:
unit_summary += f", {ultraliskcavern_near_townhall.amount} Ultralisk Cavern"
if greaterspire_near_townhall.amount > 0:
unit_summary += f", {greaterspire_near_townhall.amount} Greater Spire"
distribution[townhall_location_label] = unit_summary
return distribution
def get_buildings_all(self):
hatchery = self.structures(UnitTypeId.HATCHERY).amount
lair = self.structures(UnitTypeId.LAIR).amount
hive = self.structures(UnitTypeId.HIVE).amount
extractor = self.structures(UnitTypeId.EXTRACTOR).amount
spawningpool = self.structures(UnitTypeId.SPAWNINGPOOL).amount
evolutionchamber = self.structures(UnitTypeId.EVOLUTIONCHAMBER).amount
roachwarren = self.structures(UnitTypeId.ROACHWARREN).amount
banelingnest = self.structures(UnitTypeId.BANELINGNEST).amount
spinecrawler = self.structures(UnitTypeId.SPINECRAWLER).amount
sporecrawler = self.structures(UnitTypeId.SPORECRAWLER).amount
hydraliskden = self.structures(UnitTypeId.HYDRALISKDEN).amount
infestationpit = self.structures(UnitTypeId.INFESTATIONPIT).amount
spire = self.structures(UnitTypeId.SPIRE).amount
nydusnetwork = self.structures(UnitTypeId.NYDUSNETWORK).amount
ultraliskcavern = self.structures(UnitTypeId.ULTRALISKCAVERN).amount
greaterspire = self.structures(UnitTypeId.GREATERSPIRE).amount
summary = f""
if hatchery > 0:
summary += f"{hatchery} Hatchery"
if lair > 0:
summary += f", {lair} Lair"
if hive > 0:
summary += f", {hive} Hive"
if extractor > 0:
summary += f", {extractor} Extractor"
if spawningpool > 0:
summary += f", {spawningpool} Spawningpool"
if evolutionchamber > 0:
summary += f", {evolutionchamber} Evolution Chamber"
if roachwarren > 0:
summary += f", {roachwarren} Roach Warren"
if banelingnest > 0:
summary += f", {banelingnest} Baneling Nest"
if spinecrawler > 0:
summary += f", {spinecrawler} Spine Crawler"
if sporecrawler > 0:
summary += f", {sporecrawler} Spore Crawler"
if hydraliskden > 0:
summary += f", {hydraliskden} Hydralisk Den"
if infestationpit > 0:
summary += f", {infestationpit} Infestation Pit"
if spire > 0:
summary += f", {spire} Spire"
if nydusnetwork > 0:
summary += f", {nydusnetwork} Nydus Network"
if ultraliskcavern > 0:
summary += f", {ultraliskcavern} Ultralisk Cavern"
if greaterspire > 0:
summary += f", {greaterspire} Greater Spire"
return summary
def get_tech(self):
tech_info = []
for upgrade in self.state.upgrades:
upgrade_name = upgrade.name
tech_info.append(upgrade_name)
return tech_info
def get_enemy_units(self):
if len(self.enemy_units) == 0:
return {}
distribution = {}
for mineral_position, location_label in self.mineral_location_labels.items():
units_near_mineral = self.enemy_units.closer_than(25, mineral_position)
scv_near_mineral = units_near_mineral.of_type({UnitTypeId.SCV})
marine_near_mineral = units_near_mineral.of_type({UnitTypeId.MARINE})
reaper_near_mineral = units_near_mineral.of_type({UnitTypeId.REAPER})
marauder_near_mineral = units_near_mineral.of_type({UnitTypeId.MARAUDER})
ghost_near_mineral = units_near_mineral.of_type({UnitTypeId.GHOST})
hellion_near_mineral = units_near_mineral.of_type({UnitTypeId.HELLION})
widowmine_near_mineral = units_near_mineral.of_type({UnitTypeId.WIDOWMINE})
cyclone_near_mineral = units_near_mineral.of_type({UnitTypeId.CYCLONE})
siegetank_near_mineral = units_near_mineral.of_type({UnitTypeId.SIEGETANK})
hellbat_near_mineral = units_near_mineral.of_type({UnitTypeId.HELLBATACGLUESCREENDUMMY})
thor_near_mineral = units_near_mineral.of_type({UnitTypeId.THOR})
viking_near_mineral = units_near_mineral.of_type({UnitTypeId.VIKING})
medivac_near_mineral = units_near_mineral.of_type({UnitTypeId.MEDIVAC})
liberator_near_mineral = units_near_mineral.of_type({UnitTypeId.LIBERATOR})
raven_near_mineral = units_near_mineral.of_type({UnitTypeId.RAVEN})
banshee_near_mineral = units_near_mineral.of_type({UnitTypeId.BANSHEE})
battlecruiser_near_mineral = units_near_mineral.of_type({UnitTypeId.BATTLECRUISER})
unit_summary = f""
if scv_near_mineral.amount > 0:
unit_summary += f"{scv_near_mineral.amount} SCVs"
if marine_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {marine_near_mineral.amount} Marines"
else:
unit_summary += f"{marine_near_mineral.amount} Marines"
if reaper_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {reaper_near_mineral.amount} Reapers"
else:
unit_summary += f"{reaper_near_mineral.amount} Reapers"
if marauder_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {marauder_near_mineral.amount} Marauders"
else:
unit_summary += f"{marauder_near_mineral.amount} Marauders"
if ghost_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {ghost_near_mineral.amount} Ghosts"
else:
unit_summary += f"{ghost_near_mineral.amount} Ghosts"
if hellion_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {hellion_near_mineral.amount} Hellions"
else:
unit_summary += f"{hellion_near_mineral.amount} Hellions"
if widowmine_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {widowmine_near_mineral.amount} Widow Mines"
else:
unit_summary += f"{widowmine_near_mineral.amount} Widow Mines"
if cyclone_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {cyclone_near_mineral.amount} Cyclones"
else:
unit_summary += f"{cyclone_near_mineral.amount} Cyclones"
if siegetank_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {siegetank_near_mineral.amount} Siege Tanks"
else:
unit_summary += f"{siegetank_near_mineral.amount} Siege Tanks"
if hellbat_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {hellbat_near_mineral.amount} Hellbats"
else:
unit_summary += f"{hellbat_near_mineral.amount} Hellbats"
if thor_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {thor_near_mineral.amount} Thors"
else:
unit_summary += f"{thor_near_mineral.amount} Thors"
if viking_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {viking_near_mineral.amount} Vikings"
else:
unit_summary += f"{viking_near_mineral.amount} Vikings"
if medivac_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {medivac_near_mineral.amount} Medivacs"
else:
unit_summary += f"{medivac_near_mineral.amount} Medivacs"
if liberator_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {liberator_near_mineral.amount} Liberators"
else:
unit_summary += f"{liberator_near_mineral.amount} Liberators"
if raven_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {raven_near_mineral.amount} Ravens"
else:
unit_summary += f"{raven_near_mineral.amount} Ravens"
if banshee_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {banshee_near_mineral.amount} Banshees"
else:
unit_summary += f"{banshee_near_mineral.amount} Banshees"
if battlecruiser_near_mineral.amount > 0:
if unit_summary:
unit_summary += f", {battlecruiser_near_mineral.amount} Battle Cruisers"
else:
unit_summary += f"{battlecruiser_near_mineral.amount} Battle Cruisers"
if unit_summary == "":
continue
distribution[location_label] = unit_summary
return distribution
def get_enemy_units_all(self):
marines = self.enemy_units(UnitTypeId.MARINE).amount
reapers = self.enemy_units(UnitTypeId.REAPER).amount
marauders = self.enemy_units(UnitTypeId.MARAUDER).amount
ghosts = self.enemy_units(UnitTypeId.GHOST).amount
hellions = self.enemy_units(UnitTypeId.HELLION).amount
widowmines = self.enemy_units(UnitTypeId.WIDOWMINE).amount
cyclones = self.enemy_units(UnitTypeId.CYCLONE).amount
siegetanks = self.enemy_units(UnitTypeId.SIEGETANK).amount
hellbats = self.enemy_units(UnitTypeId.HELLBATACGLUESCREENDUMMY).amount
thors = self.enemy_units(UnitTypeId.THOR).amount
vikings = self.enemy_units(UnitTypeId.VIKING).amount
medivacs = self.enemy_units(UnitTypeId.MEDIVAC).amount
liberators = self.enemy_units(UnitTypeId.LIBERATOR).amount
ravens = self.enemy_units(UnitTypeId.RAVEN).amount
banshees = self.enemy_units(UnitTypeId.BANSHEE).amount
battlecruisers = self.enemy_units(UnitTypeId.BATTLECRUISER).amount
enemy_damage = marines * 6 + reapers * 4 + marauders * 10 + ghosts * 10 + hellions * 8 + widowmines * 125 + cyclones * 11 + siegetanks * 40 + hellbats * 18 + thors * 30 + vikings * 12 + liberators * 5 + banshees * 12 + battlecruisers * 8
summary = f""
if marines > 0:
summary += f"{marines} Marines"
if reapers > 0:
if summary:
summary += f", {reapers} Reapers"
else:
summary += f", {reapers} Reapers"
if marauders > 0:
if summary:
summary += f", {marauders} Marauders"
else:
summary += f"{marauders} Marauders"
if ghosts > 0:
if summary:
summary += f", {ghosts} Ghosts"
else:
summary += f"{ghosts} Ghosts"
if hellions > 0:
if summary:
summary += f", {hellions} Hellions"
else:
summary += f"{hellions} Hellions"
if widowmines > 0:
if summary:
summary += f", {widowmines} Widow Mines"
else:
summary += f", {widowmines} Widow Mines"
if cyclones > 0:
if summary:
summary += f", {cyclones} Cyclones"
else:
summary += f"{cyclones} Cyclones"
if siegetanks > 0:
if summary:
summary += f", {siegetanks} Siege Tanks"
else:
summary += f"{siegetanks} Siege Tanks"
if hellbats > 0:
if summary:
summary += f", {hellbats} Hellbats"
else:
summary += f"{hellbats} Hellbats"
if thors > 0:
if summary:
summary += f", {thors} Thors"
else:
summary += f"{thors} Thors"
if vikings > 0:
if summary:
summary += f", {vikings} Vikings"
else:
summary += f"{vikings} Vikings"
if medivacs > 0:
if summary:
summary += f", {medivacs} Medivacs"
else:
summary += f"{medivacs} Medivacs"
if liberators > 0:
if summary:
summary += f", {liberators} Liberators"
else:
summary += f"{liberators} Liberators"
if ravens > 0:
if summary:
summary += f", {ravens} Ravens"
else:
summary += f"{ravens} Ravens"
if banshees > 0:
if summary:
summary += f", {banshees} Banshees"
else:
summary += f"{banshees} Banshees"
if battlecruisers > 0:
if summary:
summary += f", {battlecruisers} Battlecruisers"
else:
summary += f"{battlecruisers} Battlecruisers"
return summary, enemy_damage
def get_enemy_buildings(self):
if len(self.enemy_structures) == 0:
return {}
distribution = {}
for mineral_position, location_label in self.mineral_location_labels.items():
units_near_mineral = self.enemy_structures.closer_than(25, mineral_position)
commandcenter_near_townhall = units_near_mineral.of_type({UnitTypeId.COMMANDCENTER})
refinery_near_townhall = units_near_mineral.of_type({UnitTypeId.REFINERY})
supplydepot_near_townhall = units_near_mineral.of_type({UnitTypeId.SUPPLYDEPOT})
engineeringbay_near_townhall = units_near_mineral.of_type({UnitTypeId.ENGINEERINGBAY})
missileturret_near_townhall = units_near_mineral.of_type({UnitTypeId.MISSILETURRET})
sensortower_near_townhall = units_near_mineral.of_type({UnitTypeId.SENSORTOWER})
planetaryfortress_near_townhall = units_near_mineral.of_type({UnitTypeId.PLANETARYFORTRESS})
barracks_near_townhall = units_near_mineral.of_type({UnitTypeId.BARRACKS})
bunker_near_townhall = units_near_mineral.of_type({UnitTypeId.BUNKER})
ghostacademy_near_townhall = units_near_mineral.of_type({UnitTypeId.GHOSTACADEMY})
factory_near_townhall = units_near_mineral.of_type({UnitTypeId.FACTORY})
orbitalcommand_near_townhall = units_near_mineral.of_type({UnitTypeId.ORBITALCOMMAND})
armory_near_townhall = units_near_mineral.of_type({UnitTypeId.ARMORY})
starport_near_townhall = units_near_mineral.of_type({UnitTypeId.STARPORT})
fusioncore_near_townhall = units_near_mineral.of_type({UnitTypeId.FUSIONCORE})
unit_summary = f""
if commandcenter_near_townhall.amount > 0:
unit_summary += f"{commandcenter_near_townhall.amount} Command Center"
if refinery_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {refinery_near_townhall.amount} Refinery"
else:
unit_summary += f"{refinery_near_townhall.amount} Refinery"
if supplydepot_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {supplydepot_near_townhall.amount} Supply Depot"
else:
unit_summary += f"{supplydepot_near_townhall.amount} Supply Depot"
if engineeringbay_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {engineeringbay_near_townhall.amount} Engineering Bay"
else:
unit_summary += f"{engineeringbay_near_townhall.amount} Engineering Bay"
if missileturret_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {missileturret_near_townhall.amount} Missile Turret"
else:
unit_summary += f"{missileturret_near_townhall.amount} Missile Turret"
if sensortower_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {sensortower_near_townhall.amount} Sensor Tower"
else:
unit_summary += f"{sensortower_near_townhall.amount} Sensor Tower"
if planetaryfortress_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {planetaryfortress_near_townhall.amount} Planetary Fortress"
else:
unit_summary += f"{planetaryfortress_near_townhall.amount} Planetary Fortress"
if barracks_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {barracks_near_townhall.amount} Barracks"
else:
unit_summary += f"{barracks_near_townhall.amount} Barracks"
if bunker_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {bunker_near_townhall.amount} Bunker"
else:
unit_summary += f"{bunker_near_townhall.amount} Bunker"
if ghostacademy_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {ghostacademy_near_townhall.amount} Ghost Academy"
else:
unit_summary += f"{ghostacademy_near_townhall.amount} Ghost Academy"
if factory_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {factory_near_townhall.amount} Factory"
else:
unit_summary += f"{factory_near_townhall.amount} Factory"
if orbitalcommand_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {orbitalcommand_near_townhall.amount} Orbital Command"
else:
unit_summary += f"{orbitalcommand_near_townhall.amount} Orbital Command"
if armory_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {armory_near_townhall.amount} Armory"
else:
unit_summary += f", {armory_near_townhall.amount} Armory"
if starport_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {starport_near_townhall.amount} Starport"
else:
unit_summary += f"{starport_near_townhall.amount} Starport"
if fusioncore_near_townhall.amount > 0:
if unit_summary:
unit_summary += f", {fusioncore_near_townhall.amount} Fusion Core"
else:
unit_summary += f"{fusioncore_near_townhall.amount} Fusion Core"
if unit_summary == "":
continue
distribution[location_label] = unit_summary
return distribution
def filter_commands(self, commands, target_objects):
filtered_commands = [cmd for cmd in commands if not any(obj in cmd for obj in target_objects)]
return filtered_commands
def id_game_stage(self):
if self.supply_cap <= 60:
return 0 # early
elif self.supply_cap > 60:
return 1 # mid
elif self.supply_cap > 100:
return 2 # late
def detect_stage(self, text):
if 'early' in text and 'mid' not in text:
return 0
elif 'early' in text and 'mid' in text:
return 1
elif 'late' in text:
return 2
return self.id_game_stage()
async def overmindbrain_iter(self):
game_time = self.time_formatted
tmp_current_units = []
current_units = self.get_units_distribution()
print("our units:")
for location, units_summary in current_units.items():
if self.start_location_label == "B1":
location = location.replace('B', 'A')
print(f"At point {location}, there are: {units_summary}")
tmp_current_units.append(f"At point {location}, there are: {units_summary}")
tmp_current_buildings = []
current_buildings = self.get_buildings_distribution()
print("our buildings:")
for location, units_summary in current_buildings.items():
if self.start_location_label == "B1":
location = location.replace('B', 'A')
print(f"At point {location}, there are: {units_summary}")
tmp_current_buildings.append(f"At point {location}, there are: {units_summary}")
current_tech = self.get_tech()
print("our tech:")
print("current_tech:", current_tech)
tmp_current_enemy_units = []
current_enemy_units = self.get_enemy_units()
if current_enemy_units == "":
current_enemy_units = self.previous_enemy_units
self.previous_enemy_units = current_enemy_units
for location, units_summary in current_enemy_units.items():
if self.start_location_label == "B1":
location = location.replace('A', 'B')
print(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_units.append(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_buildings = []
current_enemy_buildings = self.get_enemy_buildings()
if current_enemy_buildings == "":
current_enemy_buildings = self.previous_enemy_buildings
self.previous_enemy_buildings = current_enemy_buildings
print("enemy buildings:")
for location, units_summary in current_enemy_buildings.items():
if self.start_location_label == "B1":
location = location.replace('A', 'B')
print(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_buildings.append(f"At point {location}, there are: {units_summary}")
output = await overmind_brain_iter(game_time, tmp_current_units, tmp_current_buildings, current_tech,
tmp_current_enemy_units,
tmp_current_enemy_buildings, self.previous_commands)
print(output)
# self.game_stage = self.detect_stage(output)
matches = re.findall(r'\(.*?\)->\(.*?\)->\(.*?\)', output)
temp_commands = []
for match in matches:
temp_commands.append(match)
self.previous_commands = temp_commands
temp_commands = self.filter_commands(temp_commands,
['Queen', 'Gather minerals', 'Extractor', 'Mineral', 'Overlord', 'Move',
'Zergling', 'Creep'])
temp_commands_reverse = []
if self.start_location_label == "A1":
temp_commands_reverse = temp_commands
elif self.start_location_label == "B1":
for command in temp_commands:
def replace(match):
char, num = match.group(1), match.group(2)
return 'B' + num if char == 'A' else 'A' + num
command = re.sub(r'(A|B)(\d+)', replace, command)
temp_commands_reverse.append(command)
pattern = re.compile(r'\(([^)]+)\)')
for command in temp_commands_reverse:
parts = pattern.findall(command)
self.parsed_commands.append(parts)
print("self.parsed_commands:", self.parsed_commands)
async def overmind_building_iter(self):
game_time = self.time_formatted
current_units = self.get_units_all()
print("[Building] our units:", current_units)
current_buildings = self.get_buildings_all()
print("[Building] our buildings:", current_buildings)
tmp_current_enemy_units = []
current_enemy_units = self.get_enemy_units()
if current_enemy_units == "":
current_enemy_units = self.previous_enemy_units
self.previous_enemy_units = current_enemy_units
for location, units_summary in current_enemy_units.items():
if self.start_location_label == "B1":
location = location.replace('A', 'B')
print(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_units.append(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_buildings = []
current_enemy_buildings = self.get_enemy_buildings()
if current_enemy_buildings == "":
current_enemy_buildings = self.previous_enemy_buildings
self.previous_enemy_buildings = current_enemy_buildings
print("enemy buildings:")
for location, units_summary in current_enemy_buildings.items():
if self.start_location_label == "B1":
location = location.replace('A', 'B')
print(f"At point {location}, there are: {units_summary}")
tmp_current_enemy_buildings.append(f"At point {location}, there are: {units_summary}")
print("[Building] previous_commands:", self.previous_commands)
output = await overmind_building_iter(game_time, current_units, current_buildings,
tmp_current_enemy_units,
tmp_current_enemy_buildings, self.previous_commands)
print(output)
# self.game_stage = self.detect_stage(output)
matches = re.findall(r'\(.*?\)->\(.*?\)->\(.*?\)', output)
temp_commands = []
for match in matches:
temp_commands.append(match)
self.previous_commands = temp_commands
temp_commands = self.filter_commands(temp_commands,
['Queen', 'Gather minerals', 'Extractor', 'Mineral', 'Overlord', 'Move',
'Zergling', 'Creep'])
temp_commands_reverse = []
if self.start_location_label == "A1":
temp_commands_reverse = temp_commands
elif self.start_location_label == "B1":
for command in temp_commands:
def replace(match):
char, num = match.group(1), match.group(2)
return 'B' + num if char == 'A' else 'A' + num
command = re.sub(r'(A|B)(\d+)', replace, command)
temp_commands_reverse.append(command)
pattern = re.compile(r'\(([^)]+)\)')
for command in temp_commands_reverse:
parts = pattern.findall(command)
self.parsed_commands.append(parts)