def move_toward(s0, s1): # shift position of s1 to wrap around board edges s1 = closest_dist_version(s0, s1) if abs(s1.y - s0.y) >= abs(s1.x - s0.x): if s1.y >= s0.y: return hlt.Move(s0, hlt.SOUTH) else: return hlt.Move(s0, hlt.NORTH) else: if s1.x >= s0.x: return hlt.Move(s0, hlt.EAST) else: return hlt.Move(s0, hlt.WEST)
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)
def successors(gameMap, myID): units = gameMap.units(myID) for dirs in itertools.product(hlt.DIRECTIONS, repeat=len(units)): moves = [ hlt.Move(location, direction) for (location, _), direction in zip(units, dirs) ] yield moves, gameMap.enactMoves(myID, moves)
def main(): state = { 'seen_combat': False, } myID, gameMap = networking.getInit() networking.sendInit("Orez[Miner]") while True: gameMap = networking.getFrame() moves = [ hlt.Move( hlt.Location(x, y), direction, ) for (x, y), direction in turn(gameMap, myID, state) ] networking.sendFrame(moves)
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)
actions = np.argmax(actions, axis=2) if not has_padding: if not late_game: actions = dont_overconfidence(frame[0], actions) r1 = r_start - padding[0][0] r2 = dims - r_end + padding[0][1] r3 = c_start - padding[1][0] r4 = dims - c_end + padding[1][1] actions = np.pad(actions, ((r_start, dims - r_end), (c_start, dims - c_end)), mode='constant', constant_values=0) actions = actions[padding[0][0]:-padding[0][1], padding[1][0]:-padding[1][1]] actions = np.roll(actions, actions.shape[0] - (row_shift), axis=0) actions = np.roll(actions, actions.shape[1] - (col_shift), axis=1) my_squares = orig_frame[:, :, 1] > 0 for y in range(gameMap.height): for x in range(gameMap.width): if my_squares[y, x]: move = hlt.Square(x, y, myID, None, None) moves.append(hlt.Move(move, actions[y][x])) hlt.send_frame2(moves)