Help With Capturing Control Points

Hi, I was playing around with burning ices, and I want a better way to capture control points.
You can command scouts.
What I want to do:
Make the scout defend the nearest point that hasn’t been captured.
Actual Outcome:
The scout finds the nearest unoccupied point, but unfortunately, when the scout captures the point, the captured point joins my team, and then the scout runs off, and now the point uncaptured, so he just runs back and forth.
Here is my code.
I am at wits end for what to do.

def commandScout():
    es = hero.findByType("goliath", hero.findEnemies())
    friends = hero.findFriends()
    e = hero.findNearest(es)
    points = hero.getControlPoints()
    
    targets = []
    if e:
        for point in points:
            if point.team <> e.team and point.team <> hero.team:
                targets.append(point)
    
    for friend in friends:
        if friend.type == 'scout':
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "defend", target.pos)

Tried using a while loop to make the scout defend, but it’s an infinite loop.

def commandScout():
    es = hero.findByType("goliath", hero.findEnemies())
    friends = hero.findFriends()
    e = hero.findNearest(es)
    points = hero.getControlPoints()
    
    targets = []
    if e:
        for point in points:
            if point.team <> e.team and point.team <> hero.team:
                targets.append(point)
    
    for friend in friends:
        if friend.type == 'scout':
            target = friend.findNearest(targets)
            while friend.health > 0 and target:
                hero.command(friend, "defend", target.pos)

I also tried checking the amount of people next to a point, but I get an error.

def commandScout():
    es = hero.findByType("goliath", hero.findEnemies())
    friends = hero.findFriends()
    e = hero.findNearest(es)
    points = hero.getControlPoints()
    defenders = []
    
    targets = []
    if e:
        for point in points:
            if point.team <> e.team:
                targets.append(point)
    for target in targets:
        for friend in friends:
            if friend.distanceTo(target) < 11:
                defenders.append(friend)
    for friend in friends:
        if friend.type == 'scout':
            target = friend.findNearest(targets)
            if target and len(defenders) <= 1:
                hero.command(friend, "defend", target.pos)

Line 132:
ArgumentError:
Find the distance to a target unit.
Also tried hardcoding it.

def commandSoldier():
    es = hero.findByType("goliath", hero.findEnemies())
    friends = hero.findFriends()
    e = hero.findNearest(es)
    points = hero.getControlPoints()
    targets = []
    if e:
        for point in points:
            if point.team <> hero.team:
                targets.append(point)
    for friend in friends:
        if friend.type == 'scout' or friend.type == 'a-soldier':
            target = friend.findNearest(targets)
            if target:
                if target.team == 'humans':
                    hero.command(friend, "defend", target.pos)
                elif target:
                    hero.command(friend, "defend", target.pos)

Please help me!!!

It’s partially because you are only commanding the scout to capture “uncaptured” points, and never actually staying on them. If I were you, I would check if a scout is “occupied” on a capture point, and if not, then command it capture another empty point, and set “occupied” to True.

2 Likes

Actually, I tried doing what you suggested, with this code.

def commandScout():
    friends = hero.findFriends()
    points = hero.getControlPoints()
    targets = []
    captures = []
    for point in points:
        if point.team != hero.team:
            targets.append(point)
    for friend in friends:
        if friend.type == 'scout':
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "defend", target)
                captures.append(target)
                c = friend.findNearest(captures)
                if c:
                    hero.command(friend, "defend", c)

@Chaboi_3000
Returned an error.
UnhandledError:
defend takes no arguments.
Must defend a target or a xy position
So I did this instead.

def commandScout():
    friends = hero.findFriends()
    points = hero.getControlPoints()
    targets = []
    captures = []
    for point in points:
        if point.team != hero.team:
            targets.append(point)
    for friend in friends:
        if friend.type == 'scout':
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "defend", target.pos)
            captures.append(target)
            c = friend.findNearest(captures)
            if c:
                hero.command(friend, "defend", c.pos)

They are still going back and forth

@nick can you please help me??? Pleaseeeeee
This happened in burning ices.

I also tried something similar, and it gave me an error in ace of coders.

def commandArmy():
    friends = hero.findFriends()
    points = hero.getControlPoints()
    targets = []
    captures = []
    for point in points:
        if point.team != hero.team:
            targets.append(point)
    for friend in friends:
        if friend.type == 'soldier':
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "defend", target)
                captures.append(target)
                c = friend.findNearest(captures)
                if c:
                    hero.command(friend, "defend", c)

UnhandledError.
Console log:
|Izanagi’s Pam| Non-UserCodeError: defend takes no arguments.
Must defend a target or an {x,y} position
ArgumentError: Must defend a target or an {x,y} position
at d.Attacks.updateDefend (eval at World.loadClassFromCode (https://codecombat.com/javascripts/world.js:1:329239), :288:13)
at d.Attacks.update (eval at World.loadClassFromCode (https://codecombat.com/javascripts/world.js:1:329239), :267:19)
at d.t.exports.d.callChainedMethod (https://codecombat.com/javascripts/world.js:1:259270)
at d [as update] (https://codecombat.com/javascripts/aether.js:6:43105)
at Existence.update (eval at World.loadClassFromCode (https://codecombat.com/javascripts/world.js:1:329239), :93:15)
at C.t.exports.C.getNextFrame (https://codecombat.com/javascripts/world.js:1:278329)
at World.getFrame (https://codecombat.com/javascripts/world.js:1:321297)
at World.loadFrames (https://codecombat.com/javascripts/world.js:1:323588)
at s (https://codecombat.com/javascripts/world.js:1:322541)
ladder-015aef00c71e72290cc3.bundle.js:132 |Izanagi’s Pam| Modern javascript detected, aw yeah!
ladder-015aef00c71e72290cc3.bundle.js:132 |Izanagi’s Pam| Worker initialized after 519ms
PLEASE HELP!!!
@Hydrobolic
@Bryukh
PLEASE A PYTHON GURU

Also, why can’t I use distanceTo on a point?
if friend.distanceTo(point) < 11:

Find the distance to a target unit.

@Chaboi_3000 can you please tell me how you do that?
Like some example code

Please don’t ping Bryukh. He is busy with making awesome content.

1 Like