# Need help with giant's gate

I need help finding the number of enemies in a radius, and If it is higher than 3, I cast a fireball at a group. How do I do this?

2 Likes

Please don’t make multiple threads of the same topic, this would be spam and would make things harder to solve. We can help you on your original topic

4 Likes

Simple geometry, not sure only “in a radius” of what? For example for some point –
(It’s not real code, more like a pseudocode)

``````let R =
let X =
let Y =
enemies = hero.findNearestEnemy()
enemiesInCircle = enemies.filter(e => e.distanceTo({x: X, y: Y}) < R)
``````

what does r x and y need to be

I think you can guess I gave a hint, not a solution.

Maybe try `if enemies.pos.x == x and enemies.pos.y == y and enemies.pos.x == x and enemies.pos.y == y and enemies.pos.x == x and enemies.pos.y == y: `
then do this

``````hero.cast("fireball", x,y)
``````

x and y are not inbuilt variables lol

hey please be respectful to the community or it could result in punishment such as a small suspension, complete suspension, or a mute

2 Likes

Soooo… You suggest if there are 3 units and they are all in the same point, then… Put your x and y that you need. Maybe it’s better to play other codecombat levels to understand better basic concepts?

AILeague arenas can be played with basic coding skills, however for the better results you can “practice” in usual codecombat levels.

So I tried this.

``````counter = 0
enemies = hero.findEnemies()
def thingy():
enemies = hero.findEnemies()
if enemies[0+counter].x == enemies[1+counter].x and enemies[0+counter].x == enemies[2 +counter].x:
if enemies[0 + counter].y ==enemies[1+counter].y and enemies[0+counter].y == enemies[2+counter].y:
hero.cast('fireball', enemies[0+counter].x, enemies[0+counter].y)
counter = 0
else:
counter = counter + 1
``````

it said this but why does it say enemies are undefined? It is a variable earlier.

to clarify, line 10 is

``````if enemies[0+counter].x == enemies[1+counter].x and enemies[0+counter].x == enemies[2 +counter].x:
``````

Again, do you think it’s possible that several units are in the same exact position? Also do you check if a `enemies[someNumber]` exists and no undefined?

1 Like

so i ended up with this

``````    enemy=hero.findNearestEnemy()
enemies = hero.findEnemies()
if enemy:
if enemies[0+counter].x == enemies[1+counter].x and enemies[0+counter].x == enemies[2 +counter].x:
if enemies[0 + counter].y ==enemies[1+counter].y and enemies[0+counter].y == enemies[2+counter].y:
hero.cast('fireball', enemies[0+counter].x, enemies[0+counter].y)
counter = 0
else:
counter = counter + 1

``````

and it still says it is undefined. And yes, Ik it is impossible for enemies to be in the exact same place, but I will take care of that later Are you talking to me?

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.