Ejemplo n.º 1
0
def knightLogic():
    #TODO: movement and attack logic
    if unit.location.is_on_map():
        nearby = gc.sense_nearby_units(unit.location.map_location(),
                                       unit.vision_range)
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        knightsNearby = 0
        for other in nearby:
            if other.unit_type == unit.unit_type and other.team == unit.team:
                knightsNearby += 1
            if other.team != unit.team and gc.is_attack_ready(
                    unit.id) and gc.can_attack(unit.id, other.id):
                gc.attack(unit.id, other.id)
            if other.team != unit.team:
                me = unit.location.map_location()
                them = other.location.map_location()
                directionToThem = me.direction_to(them)
                if gc.is_move_ready(unit.id) and gc.can_move(
                        unit.id, directionToThem):
                    gc.move_robot(unit.id, directionToThem)
        #print(myDirections)
        for d in myDirections:
            if gc.is_move_ready(unit.id) and gc.can_move(unit.id, d):
                #print(d)
                gc.move_robot(unit.id, d)
    return
Ejemplo n.º 2
0
def rocketLogic():
    if unit.location.is_on_planet(bc.Planet.Mars):
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        for d in myDirections:
            if gc.can_unload(unit.id, d):
                gc.unload(unit.id, d)
    elif unit.location.is_on_planet(bc.Planet.Earth):
        #TODO:wait until has someone in before launch
        garrison = len(unit.structure_garrison())
        #print("waitin on friends")
        if garrison > 0:
            if len(landingZones) > 0:
                myx = landingZones[0][0]
                myy = landingZones[0][1]
                print("im going where im told")
            else:
                myx = unit.location.map_location().x
                myy = unit.location.map_location().y
                print("we lazy")
            destination = bc.MapLocation(bc.Planet.Mars, myx, myy)
            print("we takin off boys")
            #TODO:make sure destination is a valid landing zone, currently keeps x,y from earth
            if gc.can_launch_rocket(unit.id, destination):
                del landingZones[0]
                gc.launch_rocket(unit.id, destination)
    return
Ejemplo n.º 3
0
def rangerLogic():
    #TODO: movement and attack logic
    #print("i'm alive")
    #TODO: dont move into my minimum range
    if unit.location.is_on_map():
        nearby = gc.sense_nearby_units(unit.location.map_location(),
                                       unit.vision_range)
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        rangersNearby = 0
        for other in nearby:
            if other.unit_type == unit.unit_type and other.team == unit.team:
                rangersNearby += 1
            if other.team != unit.team and gc.is_attack_ready(
                    unit.id) and gc.can_attack(unit.id, other.id):
                gc.attack(unit.id, other.id)
            if other.team != unit.team:
                distanceTo = unit.location.map_location().distance_squared_to(
                    other.location.map_location())
                myRange = unit.attack_range()
                if distanceTo < myRange:
                    #move away
                    for d in reversed(myDirections):
                        if gc.is_move_ready(unit.id) and gc.can_move(
                                unit.id, d):
                            gc.move_robot(unit.id, d)
                else:
                    me = unit.location.map_location()
                    them = other.location.map_location()
                    directionToThem = me.direction_to(them)
                    if gc.is_move_ready(unit.id) and gc.can_move(
                            unit.id, directionToThem):
                        gc.move_robot(unit.id, directionToThem)
                #outside range, inside view range, move closer
        #print(myDirections)
        for d in myDirections:
            if gc.is_move_ready(unit.id) and gc.can_move(unit.id, d):
                #print(d)
                gc.move_robot(unit.id, d)
        #since I have moved, check again if there is anything to shoot
        for other in nearby:
            if other.team != unit.team and gc.is_attack_ready(
                    unit.id) and gc.can_attack(unit.id, other.id):
                gc.attack(unit.id, other.id)
    #TODO: wait for friends
    #TODO: once i dont have enemies, full map search
    #if there are 3? other rangers nearme, then move toward target
    return
Ejemplo n.º 4
0
def factoryLogic():
    #TODO: build order/rations ect
    if gc.can_produce_robot(unit.id, bc.UnitType.Ranger) and numRangers < (
            5 * numHealers + 5):  #make this a ratio
        gc.produce_robot(unit.id, bc.UnitType.Ranger)
    if gc.can_produce_robot(
            unit.id, bc.UnitType.Healer) and numRangers * 5 > numHealers:
        gc.produce_robot(unit.id, bc.UnitType.Healer)
    if len(unit.structure_garrison()) > 0:
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        for d in myDirections:
            if gc.can_unload(unit.id, d):
                gc.unload(unit.id, d)
    return
Ejemplo n.º 5
0
def mageLogic():
    #TODO: movement and attack logic
    if unit.location.is_on_map():
        nearby = gc.sense_nearby_units(unit.location.map_location(),
                                       unit.vision_range)
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        magesNearby = 0
        for other in nearby:
            if other.unit_type == unit.unit_type and other.team == unit.team:
                magesNearby += 1
            if other.team != unit.team and gc.is_attack_ready(
                    unit.id) and gc.can_attack(unit.id, other.id):
                gc.attack(unit.id, other.id)
            if other.team != unit.team:
                distanceTo = unit.location.map_location().distance_squared_to(
                    other.location.map_location())
                myRange = unit.attack_range()
                if distanceTo < myRange:
                    #move away
                    for d in reversed(myDirections):
                        if gc.is_move_ready(unit.id) and gc.can_move(
                                unit.id, d):
                            gc.move_robot(unit.id, d)
                else:
                    me = unit.location.map_location()
                    them = other.location.map_location()
                    directionToThem = me.direction_to(them)
                    if gc.is_move_ready(unit.id) and gc.can_move(
                            unit.id, directionToThem):
                        gc.move_robot(unit.id, directionToThem)
                #outside range, inside view range, move closer
        #print(myDirections)
        for d in myDirections:
            if gc.is_move_ready(unit.id) and gc.can_move(unit.id, d):
                #print(d)
                gc.move_robot(unit.id, d)
    return
Ejemplo n.º 6
0
def workerLogic():
    #If i am on a map
    if unit.location.is_on_map(
    ):  #TODO: testing rockets and maps things, remove False
        #get valid directions around me
        myDirections = pathFinding.whereShouldIGo(
            myMap,
            unit.location.map_location().x,
            unit.location.map_location().y)
        #find out what else is near me
        nearby = gc.sense_nearby_units(unit.location.map_location(), 50)
        nearbyWorkers = 0
        for other in nearby:
            if gc.can_build(
                    unit.id,
                    other.id):  #if its something I can build, then I should
                gc.build(unit.id, other.id)
                continue
            if other.unit_type == unit.unit_type and other.team == unit.team:  #note, this unit shows up here, so +1
                nearbyWorkers += 1  #we cound the number of other workers we can see
            if other.unit_type == bc.UnitType.Rocket and other.team == unit.team:
                print(len(other.structure_garrison()))
                if len(other.structure_garrison()) == 0:
                    #distanceTo = unit.location.map_location().distance_squared_to(other.location.map_location())
                    #print(distanceTo)
                    if gc.can_load(other.id, unit.id):
                        gc.load(other.id, unit.id)
                    else:
                        me = unit.location.map_location()
                        them = other.location.map_location()
                        directionToThem = me.direction_to(them)
                        if gc.is_move_ready(unit.id) and gc.can_move(
                                unit.id, directionToThem):
                            gc.move_robot(unit.id, directionToThem)
        if numWorkers < 5:  #if there arent enough, we build more workers
            for d in reversed(
                    myDirections
            ):  #we want to buid the worker as far from the enemy as possible without moving
                if gc.can_replicate(unit.id, d):
                    gc.replicate(unit.id, d)
        #TODO:factories on again
        """
        if numFactories < 5:#if their arent many factories reporting in
                if gc.karbonite() > bc.UnitType.Factory.blueprint_cost():#can we afford it
                    for d in myDirections:#furthest from the enemy again
                        if gc.can_blueprint(unit.id, bc.UnitType.Factory, d):#if the direction is valid for building
                            print("built factory")
                            gc.blueprint(unit.id, bc.UnitType.Factory, d)
        """
        #if numFactories > 3 and numWorkers > 5:
        if numWorkers > 5:
            if gc.karbonite() > bc.UnitType.Rocket.blueprint_cost(
            ) and gc.research_info().get_level(bc.UnitType.Rocket) > 0:
                for d in reversed(myDirections):
                    if gc.can_blueprint(unit.id, bc.UnitType.Rocket, d):
                        gc.blueprint(unit.id, bc.UnitType.Rocket, d)
        #next we want to harvest all the kryponite, we also want to track if we have harvested any
        #TODO: harvest and/or move at all
        haveHarvested = 0

        for direction in myDirections:
            if gc.can_harvest(unit.id, direction):
                haveHarvested = 1
                #print("found dirt")
                gc.harvest(unit.id, direction)
        #TODO:spread out to make sure we harvest all kryptonite on the map
        if haveHarvested == 0:
            #print("no dirt")
            for d in reversed(myDirections):
                if gc.is_move_ready(unit.id) and gc.can_move(unit.id, d):
                    #print(d)
                    gc.move_robot(unit.id, d)

        #basicly do a fill, if i cant see another worker, make one, gather any kryponite i can see, then move slowly out from my corner
    """
    #TODO: be picky about building placement

    if unit.location.is_on_map(): # and unit.location.is_on_planet(bc.Planet.Earth):
        nearby = gc.sense_nearby_units(unit.location.map_location(), 2)
        for other in nearby:
            if gc.can_build(unit.id, other.id):
                gc.build(unit.id, other.id)
                continue
            if gc.can_load(other.id, unit.id):
                gc.load(other.id, unit.id)
    else:
        if numRockets < 1:
            if gc.karbonite() > bc.UnitType.Rocket.blueprint_cost() and gc.can_blueprint(unit.id, bc.UnitType.Rocket, d) and gc.research_info().get_level(bc.UnitType.Rocket) > 0:
                #numRockets+=1#because we just built one, saves us making many at a time#makes numRockets local, breaks functionality
                print("built rocket")
                gc.blueprint(unit.id, bc.UnitType.Rocket, d)
        if numFactories < 5:
            if gc.karbonite() > bc.UnitType.Factory.blueprint_cost() and gc.can_blueprint(unit.id, bc.UnitType.Factory, d):
                print("built factory")
                gc.blueprint(unit.id, bc.UnitType.Factory, d)
    """
    return