diff --git a/custom_routines/analytics.py b/custom_routines/analytics.py index c855804..d66a024 100644 --- a/custom_routines/analytics.py +++ b/custom_routines/analytics.py @@ -6,7 +6,7 @@ Class will hold different (dumb) analytic routines. """ -from hlt import Position, Direction +from hlt import Position, Direction, entity from . import seek_n_nav from . import myglobals as glo @@ -192,3 +192,39 @@ def avoid_collision_by_random_scoot(dest_dir, ship): else: # position was not taken return dest_dir + + +class Offense: + """ + Offensive analytics. + """ + + @staticmethod + def scan_for_enemy_shipyards(game): + # identify map data for Const storage and later retrieval + glo.Misc.loggit('preprocessing', 'info', "Scanning for enemy shipyards") + + # for x in range(0, game.game_map.width): + # glo.Misc.loggit('preprocessing', 'debug', " - scanning column: " + str(x)) + # for y in range(0, game.game_map.height): + # # check each map cell + # glo.Misc.loggit('preprocessing', 'debug', " - scanning cell: " + str(Position(x, y))) + # if game.game_map[Position(x, y)].has_structure: + # glo.Misc.loggit('preprocessing', 'debug', " -* _HAS_ structure") + # + # # NOTE: this only verifies that it's not our shipyard, as no drops would exist yet + # if game.game_map[Position(x, y)].structure_type is not None and \ + # game.me.shipyard.position != Position(x, y): + # # there is a structure that is not ours + # glo.Misc.loggit('preprocessing', 'debug', "Enemy shipyard at: " + str(Position(x, y))) + # + # glo.Const.Enemy_Drops.append(Position(x, y)) + + # this is a whole lot easier + for player in game.players.values(): + if player is not game.me: + glo.Misc.loggit('preprocessing', 'debug', " - found shipyard @ " + + str(player.shipyard) + " belonging to player: " + str(player.id)) + glo.Const.Enemy_Drops.append(player.shipyard.position) + + return diff --git a/custom_routines/core_processing.py b/custom_routines/core_processing.py index 642e565..52df502 100644 --- a/custom_routines/core_processing.py +++ b/custom_routines/core_processing.py @@ -15,7 +15,7 @@ import hlt from hlt import constants, Direction, Position -from . import seek_n_nav, mining, history +from . import seek_n_nav, mining, history, analytics from . import myglobals as glo @@ -39,6 +39,8 @@ def original_preprocessing(): glo.Misc.loggit('any', 'info', "Hatched and swimming! Player ID is {}.".format(game.my_id)) + analytics.Offense.scan_for_enemy_shipyards(game) + return game @staticmethod @@ -139,7 +141,11 @@ def primary_mission_mining(ship, game_map, me, turn): # get off the pot when you're done shitting, por dios elif ship.position == me.shipyard.position and ship.halite_amount == 0: - return ship.move(seek_n_nav.StartUp.get_initial_minimum_distance(ship, me, game_map, turn)) + c_queue_addition = ship.move(seek_n_nav.StartUp.get_initial_minimum_distance(ship, me, game_map, turn)) + glo.Misc.log_w_shid('core', 'debug', ship.id, " - get_initial_minimum_distance() returning: " + + str(c_queue_addition)) + + return c_queue_addition # not sure what happened just yet else: @@ -176,7 +182,9 @@ def scuttle_for_finish(me, game_map, turn): for ship in me.get_ships(): if glo.Variables.current_assignments[ship.id].primary_mission == glo.Missions.get_distance: - glo.Misc.loggit('scuttle', 'info', " - ship.id: " + str(ship.id) + " getting away from shipyard") + glo.Misc.loggit('scuttle', 'info', " - ship.id: " + str(ship.id) + " getting away from shipyard to " + + glo.Variables.current_assignments[ship.id].destination) + c_queue.append(ship.move(game_map.naive_navigate(ship, glo.Variables.current_assignments[ship.id]. destination))) @@ -187,9 +195,14 @@ def scuttle_for_finish(me, game_map, turn): # glo.Variables.current_assignments[ship.id].primary_mission != glo.Missions.get_distance: # get away from the drop - glo.Misc.loggit('scuttle', 'info', " - ship.id: " + str(ship.id) + " setting get_distance from " + - "shipyard") - glo.Variables.current_assignments[ship.id].primary_mission = glo.Missions.get_distance + # glo.Misc.loggit('scuttle', 'info', " - ship.id: " + str(ship.id) + " setting get_distance from " + + # "shipyard") + # glo.Variables.current_assignments[ship.id].primary_mission = glo.Missions.get_distance + + # go blockade + c_queue.append(seek_n_nav.Offense.blockade_enemy_drops(ship, game_map)) + + glo.Variables.current_assignments[ship.id].primary_mission = glo.Missions.blockade glo.Variables.current_assignments[ship.id].secondary_mission = glo.Missions.in_transit glo.Variables.current_assignments[ship.id].turnstamp = turn @@ -204,15 +217,12 @@ def scuttle_for_finish(me, game_map, turn): # destination))) # c_queue.append(ship.move(game_map.naive_navigate(ship, Position(0, 0)))) - if (turn % 2) == 1: - c_queue.append(ship.move(Direction.North)) - else: - c_queue.append(ship.move(Direction.East)) - - # trying out a less potentially profitable, but more sure-fire shipyard lane clearing method - # new_dir = random.choice([Direction.North, Direction.West, Direction.South]) - # - # c_queue.append(seek_n_nav.Nav.less_dumb_move(ship, new_dir, game_map)) + + # if (turn % 2) == 1: + # c_queue.append(ship.move(Direction.North)) + # else: + # c_queue.append(ship.move(Direction.East)) + elif glo.Variables.current_assignments[ship.id].primary_mission != glo.Missions.scuttle: glo.Misc.loggit('scuttle', 'info', " - ship.id: " + str(ship.id) + " heading back to drop") # head back to the drop, it's scuttle time diff --git a/custom_routines/myglobals.py b/custom_routines/myglobals.py index a94061a..4203f5e 100644 --- a/custom_routines/myglobals.py +++ b/custom_routines/myglobals.py @@ -19,13 +19,15 @@ class Const: global constants """ DEBUGGING = { + 'preprocessing': True, 'core': True, - 'seek': True, - 'locate_ore': True, + 'seek': False, + 'locate_ore': False, 'perimeter_search': False, # this will almost certainly be phased out - 'save_state': True, + 'save_state': False, 'pruning': False, 'scuttle': True, + 'blockade': True, } FEATURES = { @@ -42,6 +44,7 @@ class Const: # NOTE: the above will need to have the # of living ships * 2 added to it, # so that they can all get in to dropoff and get out of each others way, # so long as we're only dealing with the one shipyard & no dropoffs + Enemy_Drops = [] class Variables: @@ -65,6 +68,7 @@ class Missions(Enum): offense = 6 busy = 7 scuttle = 8 + blockade = 9 class Misc: diff --git a/custom_routines/seek_n_nav.py b/custom_routines/seek_n_nav.py index 9810962..8d83ff8 100644 --- a/custom_routines/seek_n_nav.py +++ b/custom_routines/seek_n_nav.py @@ -11,7 +11,7 @@ import random -from hlt import Direction +from hlt import Direction, Position from . import history, analytics from . import myglobals as glo @@ -123,6 +123,7 @@ def scoot(ship, game_map): :param game_map: :return: """ + glo.Misc.loggit('core', 'info', " - ship.id: " + str(ship.id) + " **scooting** to " + str(glo.Variables.current_assignments[ship.id].destination)) @@ -133,6 +134,43 @@ def scoot(ship, game_map): # destination), game_map) +class Offense: + @staticmethod + def blockade_enemy_drops(ship, game_map): + """ + Method will identify the enemy shipyard locations, determine which are + best for a timely blockade, and send ships that have completed their + dropoffs to the primary lanes entering such. + + TODO: don't use collision detection (ie naive_navigate) + TODO: if more than one ship is headed there, block each of the 4 lanes + + :param ship: + :param game_map: + :return: command_queue addition + """ + + glo.Misc.log_w_shid('blockade', 'info', ship.id, " - entered blockade_enemy_drops()") + + target_syard_pos = None + dist = game_map.width * 2 + 1 # ObDistanceBiggerThanGamesMaxDist + + # determine the closest shipyard + for enemy_syard_pos in glo.Const.Enemy_Drops: + if game_map.calculate_distance(ship.position, enemy_syard_pos) < dist: + glo.Misc.log_w_shid('blockade', 'info', ship.id, " -* found close(er) shipyard at: " + + str(enemy_syard_pos)) + dist = game_map.calculate_distance(ship.position, enemy_syard_pos) + target_syard_pos = enemy_syard_pos + + if target_syard_pos is not None: + return ship.move(game_map.naive_navigate(ship, target_syard_pos)) + else: + glo.Misc.log_w_shid('blockade', 'info', ship.id, " -* did not find enemy shipyard(s)") + + return ship.move(game_map.naive_navigate(ship, Position(1, 1))) + + class StartUp: @staticmethod def get_initial_minimum_distance(ship, me, game_map, turn): @@ -142,6 +180,7 @@ def get_initial_minimum_distance(ship, me, game_map, turn): :param ship: :param me: + :param game_map: :param turn: :return: """