[Adventurer] Aggressive Mimicry


#1

Mountain level Aggressive Mimicry is ready for testing.

It’s a demo level about the special case of the string search problem – startsWith function.


#2

I didn’t encounter any problems running this level.


#3

I am having problems, can’t get my guy to attack anyone, unless I remove the part of the code that deals with startsWith. I’m using python.


#4

Not sure that I got you. Could you explain your problem more careful?


#5

When I write the code as designed, my hero just stands there. When I just
have a basic attack enemy code, he attacks the ogres, but obviously doesn’t
attack the others.


#6

Could you post your code or send me sessionID?


#7

@Bryukh default gear worked with aggressively modified code. Didn’t work consistently which is ok. And with my config, a sword upgrade would take care of this and allow for simpler code without modification, and guaranteed level completion each seed.

@dwhittaker the Python code worked on my end. Did you add a : to the end of the if statement?

added LUA patch
added grammar patch


returns after playing to the campaign screen like the other levels to http://codecombat.com/play/undefined


#8

Hm. Could you give more examples or code? Which problems you had with the default equipment? BTW, what do you mean by “default equipment” for that level?


#9

can someone please explain how do I call the function and compare it with the id?


#10

ok nevermind, I figured it out


#11

@Bryukh When I say default gear, this is the equipment I chose for my character at that point in the game. Instead of upgrading my equipment I kept the minimum in most cases. I used the long sword up until I believe the final battle on the Mountain level. My gear would most likely not be standard.

What I mean to say is that if I can still modify the code and pass the level that it is fine. If a gear upgrade was required then I would list this, meaning that if someone choose poorly with gear they might need to subscribe to get more gems to buy better equipment to fix their bad choices, or that the level might be more difficult for some.

Perhaps this brings up another thought. Should we include a level or a dialogue that encourages the player to upgrade their equipment in a certain manner? In other words what is the minimum gear required for this level?

Here is the gear that I used:

I then used the stars to summon archers and different fighting strategies to defeat all of the ogres.

Let me know if I can further clarify. Looking at my post I can see how it was vague. Does this help more?


#12

Oh. Then it’s ok (“with aggressively modified code”). I tested it with the “course” mountain equipment.


#13

Soon there will be “Recomended Health” and “recommended dps”.


#14

what am I missing here…

# Protect the village from the ogres. 
# Watch for ogres, peasants and ogres disguised as ”peasants".

# This function checks if the text starts with the word.
def startsWith(text, word):
    # If the word is longer then the text:
    if len(word) > len(text):
        return False
    # Loop through the indexes of word and text.
    for index in range(len(word)):
        # If characters with the same index are different:
        if word[index] != text[index]:
            # Then the word doesn't coincide with the text.
            return False
    # We checked all letters and they are the same.
    return True

ogreNameStart = "Zog"

while True:
    enemy = hero.findNearestEnemy()
    suspect = hero.findNearest(hero.findFriends())
    # Use the function "startsWith" to check
    # if suspect's name (id) starts with "Zog", attack:
    hero.say(suspect)
    if startsWith(suspect, ogreNameStart) is True:
        hero.say(suspect)
        hero.attack(suspect)
    # Else if there is an enemy, then attack it:
    elif enemy:
        hero.attack(enemy)
    # Else return to the red X mark:
    else:
        hero.moveXY(27, 27)


#15

I suppose you need to remove say (everywhere) because you spend hero time for that


#16

I was using that to de-bug or test my code. It didn’t work before when I didn’t have it. I tried taking it out and he still lets the first on walk right by every time.


#17

Look for those lines:

# if suspect's name (id) starts with "Zog", attack:
...
if startsWith(suspect, ogreNameStart) is True:

suspect is not a name. It’s an unit.


#18

I wondered about that, but when I had him saying it, he was saying the name so I thought maybe it will check. Thanks


#19

When you use say(unit) it try to converts it to string. It’s like say(42).

But it doesn’t wok when you need specific methods.


#20

ya it works when you do it

   if startsWith(suspect.id, ogreNameStart) is True:

he goes and kills the first ogre