Hunters and Prey serious bug


#1

For the level Hunters and Prey in Cloudrip Mountain the sample code is in Javascript while I use Python. When I put a python code my whole code ends up being wrong. Does anyone have any solutions???


#2

press reload on the top right corner


#3

I already tried but it still ends up in Javascript.


#4

did go to hero and check if its python


#5

I did and it shows that I am using python. This is my code:

# Ogres are trying to kill your reindeer!
# Keep your archers back while summoning soldiers to attack.

def pickUpCoin():
    coin = self.findNearest(self.findItems())
    if coin:
        self.move(coin.pos)
    pass

def summonTroops():
    if self.gold > self.costOf("soldier"):
        self.summon("soldier")
    # Summon soldiers if you have the gold.
    
    pass
    
# This function has an argument named soldier.
# Arguments are like variables.
# The value of an argument is determined when the function is called.
def commandSoldier(soldier):
    enemy = soldier.findNearestEnemy
   if enemy:
        self.command(soldier, "attack", enemy)
    # Soldiers should attack enemies.
    pass

# Write a commandArcher function to tell your archers what to do!
# It should take one argument that will represent the archer passed to the function when it's called.
# Archers should only attack enemies who are closer than 25 meters, otherwise, stay still.
def commandarcher(archer):
    enemy = archer.findNearest(archer.findenemies)
    if enemy and archer.distanceTo(enemy) < 25:
        self.command(archer, "attack", enemy)
    else:
        self.command(archer, "move", archer.pos)
loop:
    pickUpCoin()
    summonTroops()
    friends = self.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            # This friend will be assigned to the variable soldier in commandSoldier
            commandSoldier(friend)
        elif friend.type == "archer":
            commandarcher(friend)

#6

mabye you should ask nick if you think this is a glitch


#7

I have invited him and am waiting for him to come.


#8

so you did @ and then nick


#9

@nick Please help me Out!!!


#10

What’s your CodeCombat username? I’ll check it out. It sounds like if you go to the hero selection screen and pick both a different hero and a different programming language, you might be able to switch it back to Python.


#11

It is DarkShadow66!!!


#12

If nothing works @nick can someone just translate this to Javascript and give me the translated code!Thx
My code:

loop:
    coin = self.findNearest(self.findItems())
    enemy = self.findNearest(self.findEnemies())
    friends = self.findFriends()    
    if coin:
        self.move(coin.pos)
        if self.gold >=20:
            self.summon("soldier")
            
            for friend in friends:
                if friend.type is "soldier":
                    self.command(friend, "move", {'x':25, 'y':70})
                    
        elif enemy:
            if friends:
                for friend in friends:
                    if friend.type is "soldier":
                        self.command(friend, "attack", enemy)
            for friend in friends:
                if friend.type is "archer":
                    self.command(friend, "move", {'x':25, 'y':25})
                    
        elif enemy:
            if friends:
                for friend in friends:
                    if friend.type is "archer":
                        self.command(friend, "attack", enemy)

#13

I need a answer in at least 2 days because I am falling behind everyone in my class!


#14

wait i thought you just said you were using python


#15

try exploiting it for now i found a exploit by accident and the ogre attacked the soldiers instead


#16

so i built summoned archers around the deers and the ogres did not spawn around them because they cant spawn near archer (summon not build and dont command)


#17

All I need is someone to translate my code to JavaScript


#18

How to translate the code into javascript:

  1. put β€œ;” after each instruction. If you forget, the compiler will tell you to do it EASY.
  2. put a β€œvar” to declare the variable each time you write a new variable. If you put too many var or not enough the compiler will tell you EASY
friends = self.findFriends()

becomes:

var friends = self.findFriends();
  1. Put the if or for in the parentheses
  2. Remove the β€œ:” after if or for
  3. Put brackets β€œ{” around the instructions inside the if or for
    DIFFICULTY: STRAIGHT FORWARD
if friends:
    for friend in friends:
         if friend.type is "soldier":
               self.command(friend, "attack", enemy)

becomes

if (friends){
    for (friend in friends){
        if (friend.type is "soldier"){
             self.command(friend, "attack", enemy);
        }
    }
}
  1. Inside the β€œif” argument python uses β€œis” for equal, β€œnot” for negation,
    β€œis not” for not equal. Javascript uses β€œ==”, β€œ!” and "!="
    DIFFICULTY: EASY
Python          JavaScript
is                ==
not               !
is not            != 

so

if friend.type is "archer":

becomes:

if (friend.type == "archer"){
  1. In JavaScript the for in works different: it will give you the index of
    an element instead of the object element.
    You need to add this line immediately after the for:
friend=friends[i];

DIFFICULTY: YOU"LL FIGURE IT OUT

for friend in friends:
     if friend.type is "archer":
         self.command(friend, "attack", enemy)

becomes:

for (i in friends){
     friend=friends[i];
     if (friend.type == "archer"){
         self.command(friend, "attack", enemy);
     }
}
  1. Replace all self with this
self.command(friend, "attack", enemy)

becomes

this.command(friend, "attack", enemy);

Congratulations, you have now learned how to program in JavaScript !!


#19
  1. Learn to program in both Python and Javascript, ask your schoolmates for help. Do not rely on code copied from internet.
    DIFFICULTY: HARD BUT WORTH IT.

#20

You know what my mind is getting messed up because I have many problems going on. So can someone just send me the translated code in my gmail!!Thx
PLEASE PLEASE PLEASE PLEASE
My gmail:
crummyface126@gmail.com