[Adventurer] Pong Pong

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

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.

1 Like

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.

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:

1 Like

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

1 Like

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:

I did it in 2 lines.

I used one line. (20 char)

how???!!!(20 character)

1 Like

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

1 Like

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()

Can you show how you do it?
thanx

1 Like

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.

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

1 Like

And one more tip.

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

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.

It seems my solution, even though it gets the 6 lines of code reward, is running into an issue where Pender starts to wander off to the right with Python; am I doing something wrong, or could there be some other underlying issue here?

The dog will continue ā€œfetchā€ indefinitely at least in this level. Removing it from your while loop should fix your problem.

    hero.attack('ball2')

MOD edit: Code removed to prevent a solution being posted.

Done.
This is easy :smiley: !