Is there a way in this level for me to get information about my opponent? I want to get their gold, but I only see a self.gold. Or I want to get the list of all their built units, but I only see self.built. I know there’s something to get enemy units in range, I was hoping to straight up get all their units. Thanks.
That’s probably not possible, because of intended design?
since self is your own goliath, try reading the properties of the enemy goliath. I don’t know if you are allowed to read .gold or .built, though I was able to read .health.
Maybe you can, I haven’t tried those ones. Try it, let us know!
Yeah it actually worked when I read those properties. You also don’t have to be in range for any of this to work, you can get their goliath from > 60 and then check those properties.
A few things:
this.built returns a list of everything you’ve built. Including dead units. I don’t know what happens when you try to execute functions on a dead unit.
friends.findByType(“soldier”); isn’t legal because friends is an array of units. You need to issue that command to a unit directly. One trick is to iterate through the array.
However, if you are trying to get a list of your own soldiers, there’s no need to ask every unit you’ve built to do this. Just use your hero:
One thing that isn’t documented well is that the findByType() method can accept 2 arguments. The second argument is an array you want to base your search off of, so you can try this:
this.findByType(“soldier”, friends)
I now have another question about what seems like a bug. The code snippet is below:
enemyHero = self.findByType("goliath")[0]
if self.isReady("throw") and self.distanceTo(enemyHero) <= self.throwRange:
Sometimes it returns an error that enemyHero is null. Why does this happen? As long as the enemy hero exists, shouldn’t I get a valid value?
There is no goliath at the very beginning at the level. Anyway, it’s good policy to check for everything.
I’ve seen some accounts that don’t have a goliath. They replaced their goliath with Tharin. Totally throws a wrench in my new code when I make adjustments. Add a x===null check at the beginning of the if statement and that should help.
I wonder what happens if you write a cooperative AI to create a fortification and just fend off the ice yaks?
I haven’t figured out why some people get a default Tharin in there, but I hope to fix it so that they aren’t still like that (or are excluded) when doing the final rankings at the end of the tournament. (Do they ever do anything, or do they just sit there?)
If ice yaks don’t get you, the ties are broken by remaining hero health, current army strength, remaining gold, total gold collected, or, failing all that, a random number. So there can be no tie.
When I was getting that error, the enemy hero definitely existed (I could visually see him). That’s why I didn’t check at that point in my code, because the only way I expected it to fail was when the level was over anyways. For the time being, my code just checks there is an enemy hero, so that code just has:
if enemyHero and self.isReady("throw") and self.distanceTo(enemyHero) <= self.throwRange:
It’s easy enough to do, but my code doesn’t work as intended for any cycle this happens.
So when I input this into Ace of Coders, I get this error:
this.command(friends[i], "defend", {107,48});
Error: Must defend a target or an {x,y} position.
Probably an easy solution or I overlooked something, but I would appreciate help.
Almost got it–instead of {107, 48}
, use {x: 107, y: 48}
or new Vector(107, 48)
.
Thanks.
I put that in my code like this:
for (i = 0; i < 6; i++) {
if(i%1===0){
friend=friends[i];
this.command(friend, "defend", {x: 107, y: 48});
} else {
this.command(friends[i], "defend", {x: 64, y: 92});
}
However, it returns this error:
Hero Placeholder 1 needs something to command.
Any suggestions?
Once again, thanks for being such an active dev.
Your friends
array may not have 6
units, so with the loop you’ll want to compare with friends.length
instead. (You can’t command undefined
).
Also it’s best to use var
to declare variables, to prevent scope issues with functions (and other annoying bugs.)
Thanks.
And right above this code I put var i; to avoid any more errors.
I’m doing Ace of Coders in python and here’s a sector from my code.
points = self.getControlPoints()
shouldAttack = self.now() > 90
# Use your hero’s abilities to turn the tide.
# if shouldAttack: …
if shouldAttack:
pass
for j in enumerate(points):
if points[j] != self.team and self.isReady(“stomp”):
self.moveXY(points[j].pos.x, points[j].pos.y)
self.stomp()
It gives me the error:
Line 36: tmp363 is undefined
and it highlights in red the pos in points[j].pos.x.
Line 36 is:
self.moveXY(points[j].pos.x, points[j].pos.y)
Does anyone have ideas on why it does this?
Hello, Hyrdobolic. Please format your code according to the FAQ.
I’m pretty sure the API protection in CodeCombat doesn’t allow you to directly access points[j]
. You need to store it in a variable first.
for j in enumerate(points):
point = points[j]
if point != self.team:
# Do stuff
points[j] is an object about the control point, yet you are trying to compare it against self.team. This will always be false, so the code in your if statement will always run.
However, I don’t know if that’s actually causing your issues. Another question is: “What does ‘j’ hold”? Is it an integer from 0-6, or is it a string indicating the general position, or is j actually a control point?
Depending on the answer to what j is, that could explain the undefined values.
@Nick can you send me my submited code. I need that version of code. I cant retrive it now because I made some unecessary changes and the submited one is lost.
The Ace-of-Coders tournament is now officially over!
No new submissions can be accepted.
The result will be announced in a few days.
Thank you all for participating.
There are a lot of games to rank, but we should be done this weekend, and then I’ll work on getting a cool blog post ready to announce the winners next week. Thanks for playing, all! (I had fun actually trying to win myself this one, although of course I don’t count 'cause I know all the dirty tricks), so I’m doubly eager to see the results this time!