Exemple #1
0
from game_files import hlt
from game_files.hlt import NORTH, EAST, SOUTH, WEST, STILL, Move

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))

Exemple #2
0
from game_files import hlt
from game_files.hlt import NORTH, EAST, SOUTH, WEST, STILL, Move

myID, game_map = hlt.get_init()
hlt.send_init("DiscerningBot")


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):
    return square.production / square.strength if square.strength else square.production


def get_move(square):
    target, direction = max(
        (
            (neighbor, direction)
            for direction, neighbor
Exemple #3
0
import math
import sys

import game_files.hlt as hlt
from game_files.hlt import NORTH, EAST, SOUTH, WEST, STILL, Move

myID, game_map = hlt.get_init()
hlt.send_init("BoundaryBot")


def get_direction(s1, s2):
    angle = game_map.getAngle(s1, s2) * (180 / math.pi)
    if angle < 0.0:
        angle += 360.0

    direction = EAST
    if 45 < angle <= 135:
        direction = SOUTH
    elif 135 < angle <= 225:
        direction = WEST
    elif 225 < angle <= 315:
        direction = NORTH

    return direction


def initialise_boundary_enemies():
    global boundary_enemies
    boundary_enemies = [
        enemy for enemy in game_map if
        any([neighbour.owner == myID for neighbour in game_map.neighbors(enemy)])
Exemple #4
0
from game_files import hlt
from game_files.hlt import NORTH, EAST, SOUTH, WEST, STILL, Move

myID, game_map = hlt.get_init()
hlt.send_init("ProductionBot")


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 get_move(square):
    target, direction = max(
        (
            (neighbor, direction)
            for direction, neighbor
            in enumerate(game_map.neighbors(square))
            if neighbor.owner != myID and neighbor.strength < square.strength
        ),
        default=(None, None),
Exemple #5
0
from game_files import hlt
from game_files.hlt import NORTH, EAST, SOUTH, WEST, STILL, Move

myID, game_map = hlt.get_init()
hlt.send_init("AmbiturnerBot")


def find_nearest_enemy(square):
    direction = NORTH
    max_distance = min(game_map.width, game_map.height) / 2

    for d in (NORTH, EAST, SOUTH, WEST):
        distance = 0
        current_square = square

        while current_square.owner == myID and distance < max_distance:
            distance += 1
            current_square = game_map.get_target(current_square, d)

        if distance < max_distance:
            direction = d
            max_distance = distance

    return direction


def get_move(square):
    _, direction = next(
        (
            (neighbor.strength, direction)
            for direction, neighbor