def main(): global max_production own_id, game_map = hlt.get_init() hlt.send_init("MyMLBot") solver = Solver(own_id, game_map) while True: game_map.get_frame() if max_production is None: max_production = solver.get_max_production() moves = solver.process_frame() hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random, math myID, game_map = hlt.get_init() hlt.send_init("jiseokcube") CARDINALS = (NORTH, EAST, SOUTH, WEST) def find_nearest_enemy_direction(square): direction = NORTH max_distance = min(game_map.width, game_map.height) / 2 for d in CARDINALS: distance = 0 current = square while current.owner == myID and distance < max_distance: distance += 1 current = game_map.get_target(current, d) if distance < max_distance: direction = d max_distance = distance return direction def heuristic(square): if square.owner == 0 and square.strength > 0: return square.production / square.strength else: return sum(neighbor.strength for neighbor in game_map.neighbors(square) if neighbor.owner not in (0, myID)) def assign_move(square): target, direction = max(((neighbor, direction) for direction, neighbor in enumerate(game_map.neighbors(square)) if neighbor.owner != myID), default = (None, None),
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("RandomBot") while True: game_map.get_frame() moves = [Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL))) for square in game_map if square.owner == myID] hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, CARDINALS, Move, Square, Run myID, gameMap = hlt.get_init() width = gameMap.width width2 = width // 2 height = gameMap.height height2 = height // 2 max_size = max(width, height) // 1.5 hlt.send_init("Virus2_shy") def highest_production(strength, tiles, min_production=0): # pick highest production tile we can conquer and we're not already attacking, or stay still to resist for who in sorted(tiles, key=lambda who: who[0].production, reverse=True): them = who[0] if them not in attacking: if them.strength < strength: if them.production >= min_production: return who return (None, STILL) def nearest_straight_edge(square, heading, lives): if square in edge_runs: return edge_runs[square][0] if square in straight_runs: return straight_runs[square] if lives < 0: return max_size
#from pandas.hashtable import na_sentinel import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random import logging from collections import namedtuple myID, game_map, targetCoord = hlt.get_init() hlt.send_init("SneakyBevster") logging.basicConfig(filename=str(myID) + '.log', level=logging.DEBUG) def find_nearest_enemy_direction(square): direction = NORTH max_distance = min(game_map.width, game_map.height) / 2 for d in (NORTH, EAST, SOUTH, WEST): distance = 0 current = square while (current.owner == myID or current.owner==0) and distance < max_distance: distance += 1 current = game_map.get_target(current, d) if distance < max_distance: direction = d max_distance = distance return direction def heuristic(square): if square.owner == 0 and square.strength > 0: return square.production / square.strength
action='store_true', default=True, help='Enables strategic stilling behavior.') parser.add_argument('--enable_red_green', action='store_true', default=True, help='Enables red-green trees for timing mining moves.') args = parser.parse_args() combat_hold_until = args.hold_until logging.basicConfig(filename=args.name + '.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.debug(str(args)) myID, game_map = hlt.get_init() hlt.send_init(args.name) def assign_move(square): available_moves = sorted((degrade_potential(*pf_map[neighbor]) \ + 10000 * max(destinations[neighbor] + square.strength - 255, 0) \ + (1e7 if mining_remains and neighbor in wall else 0), random.random(), direction, neighbor) for direction, neighbor in enumerate(game_map.neighbors(square))) # the random number breaks ties randomly potential, _, best_d, target = available_moves.pop(0) if square in greenlight: logging.debug( str(turn) + ' :: GREENlight: ' + str(square) + ' went ' + str(best_d) + ', root ' + str(rootlookup[square])) return Move(square, best_d)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("PythonBot") def assign_move(square): for direction, neighbor in enumerate(game_map.neighbors(square)): if neighbor.owner != myID and neighbor.strength < square.strength: return Move(square, direction) if square.strength < 5 * square.production: return Move(square, STILL) else: return Move(square, random.choice((WEST, NORTH))) while True: game_map.get_frame() moves = [assign_move(square) for square in game_map if square.owner == myID] hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myId, game_map = hlt.get_init() hlt.send_init("ProductionBot") def findNearestEnemyDirection(square): nearestEnemyDirection = NORTH maxDistance = min(game_map.height, game_map.width) / 2 for neighborDirection, neighbor in enumerate(game_map.neighbors(square)): current = neighbor distance = 0 while (current.owner == myId and distance < maxDistance): distance = distance + 1 current = game_map.get_target(current, neighborDirection) if distance < maxDistance: maxDistance = distance nearestEnemyDirection = neighborDirection return nearestEnemyDirection def notMe(square): return square[1].owner != myId def assign_move(square):
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random import pprint myID, game_map = hlt.get_init() hlt.send_init("BFS") # Square class # x, y # owner # strength # production directions = (NORTH, EAST, SOUTH, WEST) maxStrength = 255 offSet = 150 def closestFrontier(square, frontiers): closestF = 0 shortestDistance = 100000 for i in range(0, 4): if (i < 2): distance = abs(square.x - frontiers[i]) else: distance = abs(square.y - frontiers[i]) if distance < shortestDistance: shortestDistance = distance closestF = i return closestF
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("PatientBot") def get_move(square): _, direction = next( ((neighbor.strength, direction) for direction, neighbor in enumerate(game_map.neighbors(square)) if neighbor.owner != myID and neighbor.strength < square.strength), (None, None)) if direction is not None: return Move(square, direction) elif square.strength < square.production * 5: return Move(square, STILL) border = any(neighbor.owner != myID for neighbor in game_map.neighbors(square)) if not border: return Move(square, NORTH if random.random() > 0.5 else WEST) else: #wait until we are strong enough to attack return Move(square, STILL) while True: game_map.get_frame() moves = [get_move(square) for square in game_map if square.owner == myID]
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("OverkillBot") def find_nearest_enemy_direction(square): direction = NORTH max_distance = min(game_map.width, game_map.height) / 2 for d in (NORTH, EAST, SOUTH, WEST): distance = 0 current = square while current.owner == myID and distance < max_distance: distance += 1 current = game_map.get_target(current, d) if distance < max_distance: direction = d max_distance = distance return direction def heuristic(square): if square.owner == 0 and square.strength > 0: return square.production / square.strength else: # return total potential damage caused by overkill when attacking this square return sum(neighbor.strength for neighbor in game_map.neighbors(square) if neighbor.owner not in (0, myID))
# ...if strong enough to capture it if gmap.strn[nx, ny] > gmap.strn[x, y]: return Move(x, y, 0) else: return Move(x, y, ni + 1) # Stay if not at least 5x stronger than the production value if gmap.strn[x, y] < (gmap.prod[x, y] * 5): return Move(x, y, 0) # Else find the closest border square dist_to_brdr = np.zeros_like(gmap.prod) dist_to_brdr.fill(BIGINT) dist_to_brdr[np.nonzero(gmap.border)] = \ gmap.dists[x, y][np.nonzero(gmap.border)] # ..and move towards it tx, ty = np.unravel_index(dist_to_brdr.argmin(), dist_to_brdr.shape) direction = gmap.path_towards(x, y, tx, ty) return Move(x, y, direction) game_map = ImprovedGameMap() hlt.send_init("OverkillNumpyBot") while True: game_map.get_frame() game_map.update() moves = [get_move(x, y, game_map) for (x, y) in game_map.owned_locs] hlt.send_frame(moves)
import random import logging from collections import namedtuple # prodWeight= random.randint(1,10) # squareWeight= random.randint(1,10) # stayStill = random.randint(1,10) # gameStyle = random.randint(0,1) stayStill = 5 gameStyle = 0 #myID, game_map, targetCoord,totalStrength,totalProd,areaStrength,d1,d2 = hlt.get_init(1,2) myID, game_map, targetCoord,totalStrength,totalProd,areaStrength,ts,tp,sd = hlt.get_init(1,2) hlt.send_init("CuriousBevster") #logging.basicConfig(filename=str("game_in") + '.log', level=logging.DEBUG) def find_best_direction(square): direction = NORTH max_distance = min(game_map.width, game_map.height) / 2 max_unoccup = min(game_map.width, game_map.height) / 2 for d in (NORTH, EAST, SOUTH, WEST): distance = 0 current = square unoccup_count = 0 while (current.owner==myID or current.owner==0) and distance < max_distance: distance += 1 if current.owner==0:
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("Best Bot") def assign_move(square): for direction, neighbor in enumerate(game_map.neighbors(square)): if neighbor.owner != myID and neighbor.strength < square.strength and neighbor.production > square.production: return Move(square, direction) if neighbor.owner != myID and neighbor.strength < square.strength: return Move(square, direction) if neighbor.owner != myID and neighbor.strength < square.strength + square.production: return Move(square, STILL) if square.strength < 5 * square.production: return Move(square, STILL) elif square.strength == 255: return Move(square, EAST) else: return Move(square, random.choice((NORTH, STILL))) while True: game_map.get_frame() moves = [ assign_move(square) for square in game_map if square.owner == myID ] hlt.send_frame(moves)
import os import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import logging import time from HaliteBotCode import * import cProfile myID, gameMap = hlt.get_init() haliteBot = HaliteBotCode(gameMap, myID) hlt.send_init("byronwall-halite-6") if not os.path.isdir("logs"): os.mkdir("logs") if not os.path.isdir("profiles"): os.mkdir("profiles") SHOULD_PROFILE = False LOG_FILENAME = str(int(time.time())) + "-" + str(myID) + '.log' logging.basicConfig(filename="logs/" + LOG_FILENAME, level=logging.DEBUG) #disbale logging when running on the server user_name = os.environ.get("USER") if user_name != "byronwall": logging.disable(logging.CRITICAL) else:
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square directions = [NORTH, EAST, SOUTH, WEST] import random import math f = open("debug.txt", "w") myID, game_map = hlt.get_init() hlt.send_init("Offensive Tony's Bot") #Get the weakest enemy (called when not surrounded by own territory preferably) #Return still when not surrounded by (takable) enemy def fwe(square): mins = square.strength d = STILL for direction, neighbor in enumerate(game_map.neighbors(square)): if neighbor.strength < mins and neighbor.owner != myID: mins = neighbor.strength d = direction return d #Find nearest enemy. Returns 12 if no enemy within half map size. def fne(square): d = 12 maxD = game_map.width current = square for direction, neighbor in enumerate(game_map.neighbors(square)): cd = direction current = neighbor
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random import logging logging.basicConfig(filename='example.log',level=logging.INFO) logging.info('Start log ---------------------') myID, game_map = hlt.get_init() hlt.send_init("Attack best prodratio") def populate_lists(game_map): logging.info('****populate_lists****') my_squares = [] empty_squares =[] enemies =[] enemy_size = [] enemy_squares = [] for square in game_map: if(square.owner == 0): #logging.info('adding empty') empty_squares.append(square) elif(square.owner == myID): #logging.info('adding owned') my_squares.append(square) else: if square.owner not in enemies: #logging.info('adding enemy') enemies.append(square.owner) enemy_squares.append([]) #logging.info('adding enemy square') enemy_squares[enemies.index(square.owner)].append(square) #logging.info("MySquares " + str(len(my_squares)))
import MyBotFunctions as FUNC import MyBotManage as MG import MyBotExpand as EXP import MyBotAttack as ATK import MyBotEvade as EV import MyBotDirections as DIR import MyBotInit as INIT if __name__ == '__main__': myID, game_map = hlt.get_init() GLOBALVARS = D.GlobalParameters(game_map) logging.basicConfig(filename='1example.log', level=logging.DEBUG) #INIT.initialize(GLOBALVARS,myID) hlt.send_init("En3rG_v2.46") while True: GLOBALVARS.game_map.get_frame() moves = [] PARAMS = D.Parameters(myID, GLOBALVARS.maxturns) D.updateParamsPerMap(PARAMS, GLOBALVARS) GD.getSquaresInfo(PARAMS, GLOBALVARS) FUNC.setRequestHelpPriority(PARAMS, GLOBALVARS) GD.getNeutralSquaresDetectedEnemy(PARAMS, GLOBALVARS)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, CARDINALS, Move, Square, Run myID, gameMap = hlt.get_init() last_count = 0 hlt.send_init("Virus3") def highest_production(strength, tiles, min_production=0) -> int: "pick highest production tile we can conquer, or stay still to resist" target, direction = max((tile for tile in tiles if tile[0].strength < strength and tile[0].production >= min_production), default=(None, STILL), key=lambda t: t[0].production) return direction def move(square: Square) -> int: strength = square.strength if strength == 0: # no point trying to move a 0 piece return STILL blank = [] enemy = [] me = [] danger = False for d in CARDINALS: them = gameMap.get_target(square, d)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random, math myID, game_map = hlt.get_init() hlt.send_init("ImprovedBot") def assign_move(square): border = False for direction, neighbor in enumerate(game_map.neighbors(square)): if neighbor.owner != myID: border = True if neighbor.strength < square.strength: return Move(square, direction) if square.strength < 5 * square.production: return Move(square, STILL) elif (not border): return Move(square, random.choice((NORTH, WEST))) else: return Move(square, STILL) while True: game_map.get_frame() moves = [assign_move(square) for square in game_map if square.owner == myID] hlt.send_frame(moves)
if is_neutral(neighbor) and neighbor.production > 0] if len(immediate_neutral_neighbors) > 0: return expand_move(square, immediate_neutral_neighbors) close_range_neutral_neighbors = [neighbor for neighbor in game_map.neighbors(square, n=7) if is_neutral(neighbor)] if len(close_range_neutral_neighbors) > 0 and is_mature_for_close_range_conquer(strength): best_neighbor = choose_best_neutral(close_range_neutral_neighbors, square) return Move(square, direction_from_to_square(game_map, square, best_neighbor)) return Move(square, STILL) my_id, game_map = get_init() send_init("Better bot") origin_square = None while True: game_map.get_frame() my_squares = [square for square in game_map if is_my(square)] if origin_square is None: origin_square = my_squares[0] moves = [make_move(square) for square in my_squares] send_frame(moves) # def test(): # FakeMap = namedtuple('FakeMap', ['width', 'height']) # FakeSquare = namedtuple('FakeSquare', ['x', 'y']) # fake_map = FakeMap(width=10, height=10)
my_col = np.where(np.any(frame[:, :, 1] > 0, axis=0))[0] center = frame.shape[0] // 2, frame.shape[1] // 2 row_shift = int(center[0] - my_row) col_shift = int(center[1] - my_col) if row_shift < 0: row_shift = frame.shape[0] + row_shift if col_shift < 0: col_shift = frame.shape[1] + col_shift late_game = False hlt.send_init("nmalaguti_mimic") while True: moves = [] orig_frame = gameMap.get_frame() old_shape = orig_frame.shape frame = np.roll(orig_frame, row_shift, axis=0) frame = np.roll(frame, col_shift, axis=1) frame = np.expand_dims(frame, axis=0) frame, padding = hlt.pad_replay(frame, dims)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("Ran9domPythonBot") while True: game_map.get_frame() moves = [ Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL))) for square in game_map if square.owner == myID] hlt.send_frame(moves)
"""The MyBot.py file that executes the TrainedBot.py""" import os import sys sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) try: from public.models.bot.TrainedBot import TrainedBot from networking.hlt_networking import HLT except: raise mode = 'server' if (len(sys.argv) == 1) else 'local' if mode == 'server' or sys.argv[1] == 'slave': # 'server' mode import hlt else: # 'local' mode port = int(sys.argv[1]) if len(sys.argv) > 1 else 2000 hlt = HLT(port=port) bot = TrainedBot() while True: my_id, game_map = hlt.get_init() hlt.send_init("MyBot") bot.set_id(my_id) while mode == 'server' or hlt.get_string() == 'Get map and play!': game_map.get_frame(hlt.get_string()) moves = bot.compute_moves(game_map) hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("cscazorla") def assign_move(square): for direction, neighbor in enumerate(game_map.neighbors(square)): if neighbor.owner != myID and neighbor.strength < square.strength: return Move(square, direction) return Move(square, STILL) # if square.strength < 5 * square.production: # return Move(square, STILL) # else: # return Move(square, random.choice((NORTH, WEST))) while True: game_map.get_frame() moves = [ assign_move(square) for square in game_map if square.owner == myID ] hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, CARDINALS, Move, Square myID, gameMap = hlt.get_init() last_count = 0 hlt.send_init("Virus4_1") def move(square: Square) -> int: strength = square.strength if strength == 0: # no point trying to move a 0 piece return STILL blank = [] enemy = [] me = [] danger = False for d in CARDINALS: them = gameMap.get_target(square, d) owner = them.owner if owner == myID: me.append((them, d)) else: if strength > them.strength: if owner == 0: blank.append((them, d)) else: danger = True enemy.append((them, d))
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random myID, game_map = hlt.get_init() hlt.send_init("Ran9domPythonBot") while True: game_map.get_frame() moves = [ Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL))) for square in game_map if square.owner == myID ] hlt.send_frame(moves)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, CARDINALS, Move, Square myID, gameMap = hlt.get_init() last_count = 0 hlt.send_init("Virus4") def move(square:Square) -> int: strength = square.strength if strength == 0: # no point trying to move a 0 piece return STILL blank = [] enemy = [] me = [] danger = False for d in CARDINALS: them = gameMap.get_target(square, d) owner = them.owner if owner == myID: me.append((them, d)) else: if strength > them.strength: if owner == 0: blank.append((them, d)) else: danger = True enemy.append((them, d))
if min([ gamemap.get_distance(close_square, reviewed_square) for reviewed_square in reviewed ] or [float("inf")]) < 3: continue # already reviewed a neighbor d_map = dijkstra(gamemap, close_square, available=closest_squares) attack_path = find_path(d_map, start_square, close_square) t, s, p = run_game(gamemap, attack_path, simulate_game=True, num_moves=num_sim_moves) if p > best_production: best = close_square best_production = p reviewed.append(close_square) time_per_sim = max(time_per_sim, time.time() - sim_time_start) # End simulations if best is not None: d_map = dijkstra(gamemap, best, start_square, available=closest_squares) attack_path = find_path(d_map, start_square, best) else: attack_path = None hlt.send_init("NewBot_v28") run_game(gamemap, attack_path)
def __init__(self, name='Bot'): self.my_id, self.game = hlt.get_init() hlt.send_init(name)
import hlt import random import numpy as np game_map = hlt.GameMap() hlt.send_init("RandomNumpyBot") while True: game_map.get_frame() owned_locs = np.transpose(np.where(game_map.owners == game_map.my_id)) moves = [hlt.Move(x, y, random.choice(range(5))) for (x, y) in owned_locs] hlt.send_frame(moves)
import logging import csv from collections import namedtuple # prodWeight= random.randint(1,10) # squareWeight= random.randint(1,10) # stayStill = random.randint(3,7) # gameStyle = random.randint(0,1) stayStill = 5 gameStyle = 1 beingAttacked = False myID, game_map, targetCoord,totalStrength,totalProd,areaStrength,ts,tp,gameStyle = hlt.get_init(1,2) hlt.send_init("PrecisionBevster3") logging.basicConfig(filename=str("tagets") + '.log', level=logging.DEBUG) def get_adjas(direction): if direction==0: adjas = [1,3] elif direction==1: adjas = [0,2] elif direction==2: adjas = [1,3] elif direction==3: adjas = [0,2] else: adjas = [4,4]
return Move(square, direction_from_to_square(game_map, square, close_range_enemy_neighbors[0])) close_range_neutral_neighbors = [neighbor for neighbor in game_map.neighbors(square, n=5) if is_neutral(neighbor)] if len(close_range_neutral_neighbors) > 0 and is_mature_for_close_range_conquer(strength): best_neighbor = choose_best_neutral(close_range_neutral_neighbors, square) return Move(square, direction_from_to_square(game_map, square, best_neighbor)) # Go Radially from origin location if enough if is_mature_to_start_moving_radially_out(strength): return Move(square, direction_from_to_square(game_map, origin_square, square)) return Move(square, STILL) my_id, game_map = get_init() send_init("Worse bot") origin_square = None while True: game_map.get_frame() my_squares = [square for square in game_map if is_my(square)] if origin_square is None: origin_square = my_squares[0] moves = [make_move(square) for square in my_squares] send_frame(moves) # def test(): # FakeMap = namedtuple('FakeMap', ['width', 'height']) # FakeSquare = namedtuple('FakeSquare', ['x', 'y']) # fake_map = FakeMap(width=10, height=10)
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random, math myID, game_map = hlt.get_init() hlt.send_init("DiscerningBot") def nearest_enemy_direction(square): min_direction = WEST max_dist = min(game_map.width, game_map.height) / 2 for direction, neighbor in enumerate(game_map.neighbors(square)): distance = 0 current = neighbor while current.owner == myID and distance < max_dist: distance += 1 current = game_map.get_target(current, direction) if distance < max_dist: min_direction = direction max_dist = distance return min_direction def heuristic(square): if square.strength: return square.production / square.strength else: return square.production
import hlt from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square import random, math myID, game_map = hlt.get_init() hlt.send_init("MyPythonBot") def nearest_enemy_direction(square): min_direction = WEST # min2_direction = NORTH max_dist = min(game_map.width, game_map.height) / 2 for direction, neighbor in enumerate(game_map.neighbors(square)): distance = 0 current = neighbor while current.owner == myID and distance < max_dist: distance += 1 current = game_map.get_target(current, direction) if distance < max_dist: # min2_direction = min_direction min_direction = direction max_dist = distance # nearest_square = game_map.get_target(current,min_direction) # if (nearest_square.strength + square.strength) >= 255: # return min2_direction return min_direction
def get_move(square): if square.strength < 5 * square.production + 1: return hlt.Move(square, hlt.STILL) def desirability_key(target): return desirability(square, target) neighbors = get_neighbors(square) if len(neighbors) > 0: target = max(neighbors, key=desirability_key) if can_take(square, target): return move_toward(square, target) else: return hlt.Move(square, hlt.STILL) else: target = max(border_list, key=desirability_key) return move_toward(square, target) if __name__ == '__main__': myID, game_map = hlt.get_init() hlt.send_init("BorderExpander") while True: game_map.get_frame() border_list = get_new_border() moves = [get_move(s) for s in game_map if s.owner == myID] hlt.send_frame(moves)
if args["logging"]: if not os.path.isdir("logs"): os.mkdir("logs") LOG_FILENAME = str(int(time.time())) + "-" + '.log' logging.basicConfig(filename="logs/" + LOG_FILENAME, level=logging.DEBUG) else: logging.disable(logging.CRITICAL) myID, gameMap = hlt.get_init() haliteBot = HaliteBotCode(gameMap, myID, args) # do the init steps haliteBot.do_init() bot_name = "byronwall-ga1" if args["name"] is None else args["name"] hlt.send_init(bot_name) # decide if profiling should happen SHOULD_PROFILE = args["profile"] if SHOULD_PROFILE: if not os.path.isdir("profiles"): os.mkdir("profiles") frame = 0 TIME_MAX = 0.8 if args["TIME_MAX"] is None else args["TIME_MAX"] start_time = time.time() while True: gameMap.get_frame()
import random import logging import csv from collections import namedtuple # prodWeight= random.randint(1,10) # squareWeight= random.randint(1,10) # stayStill = random.randint(3,7) # gameStyle = random.randint(0,1) stayStill = 5 gameStyle = 1 beingAttacked = False myID, game_map, targetCoord,totalStrength,totalProd,areaStrength,ts,tp,sd = hlt.get_init(1,2) hlt.send_init("ProductionBevster") #logging.basicConfig(filename=str("game_in") + '.log', level=logging.DEBUG) def find_best_direction(square): direction = NORTH direction2 = NORTH max_distance = min(game_map.width, game_map.height) / 2 max_unoccup = min(game_map.width, game_map.height) / 2 max_prod = 0 for d in (NORTH, EAST, SOUTH, WEST): distance = 0 current = square unoccup_count = 0 prod_sum = 0