Skip to content

Instantly share code, notes, and snippets.

@drusepth
Last active December 14, 2016 14:59
Show Gist options
  • Save drusepth/ae8788d6417547209707b2299c680183 to your computer and use it in GitHub Desktop.
Save drusepth/ae8788d6417547209707b2299c680183 to your computer and use it in GitHub Desktop.
from hlt import *
from networking import *
my_id, game_map = getInit()
sendInit("Ankov")
def my_pieces():
pieces = []
for y in range(game_map.height):
for x in range(game_map.width):
piece = game_map.getSite(Location(x, y))
if piece.owner == my_id:
pieces.append((piece, {'x': x, 'y': y}))
return pieces
while True:
moves = []
game_map = getFrame()
pieces = my_pieces()
for piece, coordinates in pieces:
x = coordinates.get('x')
y = coordinates.get('y')
moved_piece = False
for direction in CARDINALS:
neighboring_target = game_map.getSite(Location(x, y), direction)
# If we can take an enemy or neutral piece with a move, do it
if neighboring_target.owner != my_id and piece.strength > neighboring_target.strength:
moves.append(Move(Location(x, y), direction))
moved_piece = True
break
# If we're getting relatively large, start moving around to capture more area
if piece.strength + neighboring_target.strength + neighboring_target.production >= 140:
# Alternate concerted movement between north and east
if direction == NORTH and len(pieces) % 2 == 0:
continue
moves.append(Move(Location(x, y), direction))
moved_piece = True
break
# If we don't move a piece, mark it STILL so it can get bigger
if not moved_piece:
moves.append(Move(Location(x, y), STILL))
sendFrame(moves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment