Skip to content

Commit

Permalink
Merge pull request #38 from dgets/develop
Browse files Browse the repository at this point in the history
Develop; blockade is good, but doesn't target every shipyard in every case.  Implement a modulus operation on the `ship.id` to ensure each other player's shipyard gets targeted at some point in the future.
  • Loading branch information
dgets authored Nov 21, 2018
2 parents d5ea9a7 + 2201b7d commit fa8fa8f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 20 deletions.
38 changes: 37 additions & 1 deletion custom_routines/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
40 changes: 25 additions & 15 deletions custom_routines/core_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)))
Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions custom_routines/myglobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand All @@ -65,6 +68,7 @@ class Missions(Enum):
offense = 6
busy = 7
scuttle = 8
blockade = 9


class Misc:
Expand Down
41 changes: 40 additions & 1 deletion custom_routines/seek_n_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import random

from hlt import Direction
from hlt import Direction, Position

from . import history, analytics
from . import myglobals as glo
Expand Down Expand Up @@ -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))

Expand All @@ -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):
Expand All @@ -142,6 +180,7 @@ def get_initial_minimum_distance(ship, me, game_map, turn):
:param ship:
:param me:
:param game_map:
:param turn:
:return:
"""
Expand Down

0 comments on commit fa8fa8f

Please sign in to comment.