-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
119 lines (109 loc) · 5.19 KB
/
run.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
import battlecode as bc
import sys
import traceback
import Units
import Factory
import Globals
import Healer
import Ranger
import Research
import Rocket
import Worker
import Mage
import Knight
from Radar import Radar
import Navigation
import time
import MapStrat
# Pre-Game #
gc = bc.GameController() #Creates a game controller to connect to a running game
Globals.us = gc.team()#Stores our teams color
if Globals.us == bc.Team.Red: #Assigns a value to the enemy team
Globals.them = bc.Team.Blue
else:
Globals.them = bc.Team.Red
earth_map = gc.starting_map(bc.Planet.Earth)
mars_map = gc.starting_map(bc.Planet.Mars)
Research.fill_research_queue(gc) # Fills the research queue
Globals.radar = Radar(gc.starting_map(bc.Planet.Earth), gc.starting_map(bc.Planet.Mars))
Globals.earth_enemy_center = Globals.radar.get_enemy_center(bc.Planet.Earth) # The center of starting enemy units on Earth
Globals.asteroid_pattern = gc.asteroid_pattern()
# Globals.pathsToKarb = MapStrat.get_paths_to_karb(earth_map)
Globals.mars_initial_karb = MapStrat.get_paths_to_karb(mars_map)
Globals.pathToEnemy = Navigation.BFS(earth_map, Globals.radar.get_enemy_center(bc.Planet.Earth), gc)
Globals.pathToEnemyMars = Navigation.BFS(mars_map, Globals.radar.get_enemy_center(bc.Planet.Mars), gc)
Globals.INITIAL_DISTANCE = MapStrat.initial_distance()
while True:
# Start of Turn Updates #
print("Round: ", gc.round())
# print("Karbonite: ", gc.karbonite())
try:
# Globals.radar.update_mars_karb(gc)
# Unit Controls #
round = gc.round()
if round % 10 == 0:
if Globals.radar.our_num_mars_rockets > 0:
Globals.updatePathMars = Navigation.BFS(mars_map, Globals.radar.get_enemy_center(bc.Planet.Mars), gc)
if Globals.radar.our_num_earth_rangers > 0:
Globals.updatePath = Navigation.BFS(earth_map, Globals.radar.get_enemy_center(bc.Planet.Earth), gc)
# print(Globals.pathToEnemy)
asteroid = None
if (round > 250 and Globals.radar.our_num_earth_rockets < 1) or round > 600:
Globals.factory_hold = True
else:
Globals.factory_hold = False
if Globals.asteroid_pattern.has_asteroid(round):
asteroid = Globals.asteroid_pattern.asteroid(round)
if asteroid is not None:
Globals.radar.update_karb_amount(gc, asteroid.location, asteroid.karbonite)
if Globals.radar.our_num_mars_workers > 0:
Worker.get_closest_workers(gc, asteroid.location, Globals.pathsToKarbMars)
for unit in gc.my_units():
Globals.radar.update_location(unit)
if Units.try_go_to_rocket(gc, unit):
continue
if unit.location.is_on_map():
if Globals.radar.check_if_enemies_gone(gc, unit):
Globals.everyone_to_mars = True
if unit.location.map_location().planet == bc.Planet.Mars and Globals.on_mars is False:
Globals.on_mars = True
Navigation.BFS(gc.starting_map(bc.Planet.Mars), Globals.radar.get_enemy_center(bc.Planet.Mars), gc)
if unit.unit_type == bc.UnitType.Worker:
s = time.time()
Worker.manage_worker(gc, unit)
Globals.wtime += (time.time() - s)
elif unit.unit_type == bc.UnitType.Rocket:
Rocket.manage_rockets(gc, unit)
elif unit.unit_type == bc.UnitType.Healer:
Healer.manage_healers(gc, unit)
elif unit.unit_type == bc.UnitType.Knight:
Knight.turn(gc, unit)
# Knight.manage_knights(gc, unit, Globals.earth_enemy_center, earth_enemy_map, eneGlobals.us)
elif unit.unit_type == bc.UnitType.Mage:
Mage.manage_mages(gc, unit)
# Mage.manage_mages(gc, unit, Globals.earth_enemy_center, earth_enemy_map, Globals.us)
elif unit.unit_type == bc.UnitType.Ranger:
s = time.time()
Ranger.turn(gc, unit)
Globals.rtime += (time.time() - s)
elif unit.unit_type == bc.UnitType.Factory:
Factory.factory_manager(gc, unit)
print("Workers: ", Globals.wtime, "Rangers: ", Globals.rtime, "Find Karb: ", Globals.ftime)
Globals.radar.remove_dead_units()
Globals.radar.clear_being_shot_at_cache(bc.Planet.Earth)
Globals.radar.clear_being_shot_at_cache(bc.Planet.Mars)
Globals.radar.enemies_killed_this_turn = {}
Globals.radar.enemy_center = None
Globals.radar.enemy_center_found = -1
# Globals.income = gc.karbonite() - Globals.prev_karb_amount
# Globals.prev_karb_amount = gc.karbonite()
print("----------------")
# Allows us to locate errors in the code
except Exception as e:
print('Error:', e)
traceback.print_exc()
# Send the actions we have performed and wait for the next turn
gc.next_turn()
# Write all actions to the manager
sys.stdout.flush()
sys.stderr.flush()