Awesome! The next step is oneliner or code golf
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.
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 ā¦
Ohhhhh, cool sorry. (((20cjhatafjcherssj)0)
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.
I did it in 2 lines.
I used one line. (20 char)
how???!!!(20 character)
never mind, I found out how to do it in 1 line.
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
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
- 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
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 !