In the level Toil and Trouble, the goal is to make a targeting function that will return a specific enemy based on the type of friend submitted to the function. I attempted three strategies, some of which have the opposite outcome from which should be expected.
Strategy 1: all soldiers attack witch nearest to me, archers attack enemy nearest to them. Desired outcome: Success (failure acceptable) Actual outcome: Failure, most soldiers die before even reaching the witches
Strategy 2: all friends attack enemy nearest to them. Desired outcome: Failure. Actual Outcome: Success, about four friends remaining
Strategy 3: all soldiers attack witch nearest to them, archers attack any unit nearest to them. Desired outcome: Success Actual outcome: Success, about three friends remaining
I am mostly concerned with the success of Strategy 2. It seems contrary to the goals of the level, in that it does not require the player to use functions in the desired manner.
I also failled using a kind a strategy 1.
I just ask the soldier to attack witches[0]. It seems to me more efficient to have all soldiers attacking the same witch.
But it failled totaly.
I donât know why itâs more effective to split soldiers to attack both witches at the same time. Seems not logical to me.
I face another strange behavior. I was using this.findEnemies to have a list of target for archers. But this way, my archers were attacking only the enemies at the top of the screen. I change it to friend.findEnemies, and it worked better.
Donât know why my hero from the top of the hill could not see all enemies.
Other remark : we still donât know what are the functions available for our troops. I could be great to have it somewhere to know what we can use.
Last remark : the auto completion always want to add âthis.â in front of the method weâre looking for, even if we wrote an element before. It finish like this:
You have several things so Iâm numbering them to keep them separate.
soldiers vs witches
Iâd guess that has to do with witch AoE damage, with all your soldiers in one group both witches are attacking and hitting the same group of soldiers instead of hitting different groups, killing them faster. (Sometimes small difference can tip the balance from win to lose)
hero vs friend vision:
Assuming you can see everyone on the screen (which glasses?), if you are using friend.distanceTo to choose the closest target from the list then, Iâd agree that it shouldnât matter if it is your list or their list. If you arenât using friend distanceTo then they are attacking the first one on the list that matchesâŚ
code auto complete:
The auto complete does a simple/dumb match and replace: first it matches on findEnemies and then âreplacesâ what you are typing with this.findEnemies() (language specific). To make the change it would need to replace check against â*.findEnemies()â and at the same time know what the default replacement is for your language âthis.â if there isnât a leading âblah.â (know that âthis/self/(/etcâ is replace-checked with a â*â instead of the actual characters). Handle the different languages and future ones, when/if any come along.
Regarding all soldiers attacking the same witch: From what I can tell each witch, if not being attacked, will heal its friend. This makes the divide and conquer strategy more important so that they wonât heal one another.
let all archers attack their nearest enemy and let attack soldiers the nearest enemy to you. But the best working is the opposite, anyway no solution leads to a win in my case. I had to use a heal cast tto win it ;). And i tried all solutions
The rebalance seems to work. It makes the other strategies fail.
On another note, the witchâs splash damage gives me an idea for a new level with a new(?) strategy:
You have a bunch of soldiers standing in a group on one side of the field.
Your character is standing on a cliff and cannot do anything except command troops.
On the other side of the field there are a few witches (standing close together) and a shaman behind them (for high damage against single targets).
You need to command your soldiers to spread out (not move in tightly packed groups) in order to reach the enemies alive and defeat them.
A little bit confusing that you need friend.findNearest() and friend.findEnemies() but thereâs only self.findByType(), no method for my units. Thatâs should probably go in the Help-box when you add it.
Generally speaking you can see farther than your minions, so you can do the heavy sight lifting of all the different units then let them decide which ones are closest to themâŚ
loop:
friends = self.findFriends()
for friend in friends:
target = ChooseTarget(friend)
self.say(âfriend isâ + friend +" and target is" + target)
self.command(friend, âattackâ, target)
I have tried all kinds of strategies, some of which involved upwards of 50 lines of code.
Could anyone who has beaten this level give me some advice both on the code and strategy level?
Do I need to avoid the Ogres and go straight for the witches? If so, how do I keep the soldiers spread out so as to avoid splash damage?
Before you continue reading, please read the FAQ on how to properly format your code.
Donât overthink the problem. All chooseTarget() should do is return the nearest witch to a soldier, or the nearest enemy to an archer. Not sure why you are trying to target the throwers specifically until they are all dead.
If for some reason your hero canât see some of the enemies, then you can do this inside chooseTarget():
def chooseTarget(friend):
enemies = friend.findEnemies() # friends have a visual range of 9001 meters
witches = self.findByType("witch", enemies)
# return a target!
The top and bottom lanes cut through the throwers, then the ogres, kill the ogres but then get mowed down by the witches. So it isnât working. I must be missing something incredibly simple but I have no idea what it is.
Line 10, time 0.0. Cannot read property âtypeâ of undefined
I donât understand why I am getting this error as I only call the function in a for loop where I am iterating over the variables I am passing to the function (friend)