Explorar el Código

better estimation of next objective

olinox hace 6 años
padre
commit
ea25289b4e
Se han modificado 1 ficheros con 29 adiciones y 30 borrados
  1. 29 30
      carribean/script.py

+ 29 - 30
carribean/script.py

@@ -8,12 +8,14 @@ import sys
 
 # TODO:
 # * add an esquive manoeuvre / try to avoid cannonballs
-# * consider firing at rum barrels if an ennemy is nearer
 # * compute first and second target instead of only one to anticipate the next move
 # * if an enemy is near a mine, shoot the mine instead of the ship
 # * compute the probabilities of presence of an ennemy on different coords at next turn
 # * find a way to change direction without slowing down if possible
 # * avoid getting blocked by a side-by-side with an ennemy
+# * priorize targetting blocked ennemies
+
+# * Fix shooting_spot() method
 
 debug = True
 
@@ -886,36 +888,16 @@ while True:
         except IndexError:
             break
         
-    # after_that objective
-    for s in grid.owned_ships:
-        if not s.objective: 
-            continue
-        if grid.manhattan(s.pos, s.objective.target.pos) > 5:
-            continue
-        after_that = ObjectivesQueue()
-        for b in [o.target for o in s.objectives.items]:
-            obj = GetBarrel(b)
-            obj.eval(s.objective.target.pos, s.orientation)
-            after_that.put(obj)
-        if after_that:
-            s.objective_next = after_that.get()
-    
     # targetted ennemy
     for s in grid.owned_ships:
         s.target_ennemy = s.ennemies.get()
         
-    for ship in grid.owned_ships:
-        log(f"Ship {ship.id}: obj: {ship.objective}; next: {ship.objective_next}; target: {ship.target_ennemy}")
-    
     ### Plan
     log("# Planning")
     
     for ship in grid.owned_ships:
         
-        log(f"---- ship {ship.id} ---")
-        log(f"ship: {ship}")
-        
-        if ship.objective or (ship.target_ennemy and ship.target_ennemy.interest < 0):
+        if ship.objective:
             ship.goto = ship.objective.target.pos
         elif ship.target_ennemy:
             ship.goto = grid.shooting_spot(ship, ship.target_ennemy.target)
@@ -923,18 +905,35 @@ while True:
             log("ERROR: No target")
             continue
         
-        log(f"goto: {ship.goto}")
         ship.path = grid.path(ship.next_pos, ship.orientation, ship.goto, ship._moving_costs, limit=6000 // len(grid.owned_ships))
         
-        if ship.objective_next and ship.path:
-            ship.path += grid.path(ship.goto, 
-                                   ship.path[-1].orientation, 
-                                   ship.objective_next.target.pos, 
-                                   ship._moving_costs,
-                                   limit=6000 // len(grid.owned_ships)) or []
-        
+        if ship.objective and ship.path and len(ship.path) <= 5:
+            # what to do next
+            after_that = ObjectivesQueue()
+            for b in [o.target for o in s.objectives.items]:
+                obj = GetBarrel(b)
+                obj.eval(ship.path[-1], ship.path[-1].orientation)
+                after_that.put(obj)
+                
+            if after_that:
+                s.objective_next = after_that.get()
+            
+                ship.path += grid.path(ship.goto, 
+                                       ship.path[-1].orientation, 
+                                       ship.objective_next.target.pos, 
+                                       ship._moving_costs,
+                                       limit=6000 // len(grid.owned_ships)) or []
+ 
+ 
+    for ship in grid.owned_ships:
+        log(f"---- ship {ship.id} ---")
+        log(f"ship: {ship}")
+        log(f"obj: {ship.objective}; next: {ship.objective_next}; target: {ship.target_ennemy}")
+        log(f"goto: {ship.goto}")
         log(f"path: {ship.path}")
         
+        
+        
     ### special: avoid cannonballs
     danger = [c.pos for c in grid.cannonballs if c.countdown <= 1]