aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2021-06-05 15:30:41 +0000
committerAnthony Wang2021-06-05 15:30:41 +0000
commita1ac06dfd141fe3b83ad4a9fdb7ca6e18520998f (patch)
tree7b19a09b4a1b707fc46eae750de099aee5dccb20
parent93510b51eef1127708f367543ffbbb50baf2b412 (diff)
Add more sophisticated spawning strategy
-rw-r--r--python-algo/algo_strategy.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/python-algo/algo_strategy.py b/python-algo/algo_strategy.py
index 756bcd6..e16de1b 100644
--- a/python-algo/algo_strategy.py
+++ b/python-algo/algo_strategy.py
@@ -19,7 +19,7 @@ Advanced strategy tips:
the actual current map state.
"""
-class AlgoStrategy(gamelib.AlgoCore):
+class AlgoStrategy(gamelib.AlgoCore):
def __init__(self):
super().__init__()
seed = random.randrange(maxsize)
@@ -41,7 +41,11 @@ class AlgoStrategy(gamelib.AlgoCore):
INTERCEPTOR = config["unitInformation"][5]["shorthand"]
MP = 1
SP = 0
+
# This is a good place to do initial setup
+ global damage
+ damage = {SCOUT: 0, DEMOLISHER: 0, INTERCEPTOR: 0}
+
self.scored_on_locations = []
def on_turn(self, turn_state):
@@ -79,10 +83,30 @@ class AlgoStrategy(gamelib.AlgoCore):
# Now build reactive defenses based on where the enemy scored
self.build_reactive_defense(game_state)
- if game_state.turn_number % 4 == 0:
- game_state.attempt_spawn(SCOUT, [14, 0], game_state.number_affordable(SCOUT))
- elif game_state.turn_number % 4 == 2:
- game_state.attempt_spawn(INTERCEPTOR, [14, 0], game_state.number_affordable(INTERCEPTOR))
+ if game_state.turn_number % 2 == 0:
+ return
+
+ spawn = None
+ if game_state.turn_number < 6:
+ if game_state.turn_number == 1: spawn = SCOUT
+ elif game_state.turn_number == 3: spawn = INTERCEPTOR
+ elif game_state.turn_number == 5: spawn = DEMOLISHER
+ else:
+ total = damage[SCOUT]+damage[INTERCEPTOR]+damage[INTERCEPTOR]
+ if total == 0:
+ r = random.randint(0, 1)
+ if r == 0: spawn = SCOUT
+ else: spawn = INTERCEPTOR
+ else:
+ r = random.randint(0, total-1)
+ if r < damage[SCOUT]: spawn = SCOUT
+ elif r < damage[SCOUT]+damage[INTERCEPTOR]: spawn = INTERCEPTOR
+ else: spawn = DEMOLISHER
+
+ damage[spawn] += game_state.enemy_health
+ game_state.attempt_spawn(spawn, [14, 0], game_state.number_affordable(spawn))
+ damage[spawn] -= game_state.enemy_health
+
'''
# If the turn is less than 5, stall with interceptors and wait to see enemy's base