[Adventurer] Pong Pong


#22

Awesome! The next step is oneliner or code golf :wink:


#23

I’m loving these concept levels, there such good levels, wow! I got the 6 second bonus (just) I love the things Pender says when she hits ( should I say attacks()) the ball. Great level it’s really satisfying the way she just gets to the ball to hit it on both sides. Wonderful level Catsync.


#24

Is it meant to be Ping Pong instead of Pong Pong, just wondering, I’m from England so maybe It’s different? I just wanted to say in case it was a typo.


#25

Nope it’s not a typo. Ping - the first player hits the ball, Pong - the second, Ping - the first. So in our case it’s just Pong Pong Pong … :wink:


#26

Ohhhhh, cool sorry. (((20cjhatafjcherssj)0)


#27

couldn’t you, in javascript, put all your code on two lines? (cheats) I used a 9 line code, then compacted it into 3 lines, and I beat the challenge. :smiley:


#28

I did it in 2 lines.


#29

I used one line. (20 char)


#30

how???!!!(20 character)


#31

never mind, I found out how to do it in 1 line.


#32

I use this code: 30 lines code or less
Is it OK?
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(“ball”)
hero.attack(“ball2”)
hero.moveRight()
hero.moveRight()
hero.moveRight()
hero.attack(“ball”)
hero.attack(“ball2”)
hero.moveLeft()
hero.moveLeft()
hero.moveLeft()


#33

Can you show how you do it?
thanx


#34

no, but here’s what you could do. when you say to move right or left, instead of repeating it, add the number of times you want it to happen in the parenthesis. Also, say “fetch” before the while loop. and, you don’t need to find if the enemy exists, cause really, this is a dungeon level. you don’t need to find if the enemy exists.


#35

tips for those who want to make it with less lines

  1. moveRight can take number as parameter(same for other move functions)
hero.moveRight()
hero.moveRight()
hero.moveRight()

is the same as
hero.moveRight(3)
2) moveRight() can take negative number as parameter
hero.moveLeft()
is the same aas
hero.moveRight(-1)

Good luck


#36

And one more tip.

Are you sure you need while cycle? Maybe for cycle is better?


#37

You can complete the level in “one line” if you seriously abuse a for-loop. Whatever it is that counts the lines only counts a for-loop declaration as one line, and you can do a theoretically infinite number of things inside of a for-loop declaration.

Consider the first statement in a for-loop. This statement is executed once before the body of the loop. That’s usually used to declare an iteration variable, but you can use it here to say fetch.

The second statement is a condition, just like in a while loop, and it’s evaluated before every iteration of the loop. This condition is usually used to test the value of an iteration variable, but you can just set it to true.

The third statement is executed at the end of every iteration. Usually this is used to increment an iteration variable, but you can use it here to run the body of your code. Condensing this to one line might take some effort, but through the creative use of ternary expressions and logical operators, you should be able to do pretty much anything.

I’d post my working code here, but I’m pretty sure that’s against the rules.