The final kithmaze Loop


#1

Not sure if this is a “bug”, but here is a problem:

(This is the instruction)

Use a while-true loop to both move and attack.

(And this is the winning code)

loop:
self.moveRight()
self.moveUp()
enemy = self.findNearestEnemy()
self.attack(enemy)
self.moveRight()
self.moveDown()
self.moveDown()
self.moveUp()

As you can see, there isn’t a while-true loop anywhere, just plain “loop”.


#3

Please format your code according to the FAQ. If you don’t know where it is here’s the link:
http://discourse.codecombat.com/faq
Currently:

enemy = self.findNearestEnemy()
self.attack(enemy)

Would turn into:

enemy = self.findNearestEnemy()
self.attack(enemy)
self.attack(enemy)

#5

Currently, CodeCombat’s loop: is virtually equivalent to while True:, so both solutions are correct. CodeCombat evaluates solutions based on whether they achieve the correct end results, not the means to do so.

There’s quite a bit of history behind this as well. CodeCombat has introduced the non-standard “loop” construct so beginners can make loops with simpler syntax and thus focus on the programming logic and not the syntax. Of course, this has some huge downsides, such as teaching syntax (loop:) that is not really being part of the programming language. It seems that CodeCombat is now moving towards favoring while True: over loop: (at least for Courses). See this thread for more info.


#6

Ah, I just found the triple backtick trick. Will use that in the future.