6 kyu
Pong! [Basics]
207 of 1,301KDaryl
Loading description...
Fundamentals
Games
Algorithms
Object-oriented Programming
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Language: Java
I passed the sampleTest(), but the ATTEMPT gives me the following error message: expected: <Player 2 has won the game!> but was: <Player 1 has missed the ball!>
I don't understand why this happens, since the winning condition is evaluated first, followed by the conditions for hitting or missing the ball.
Your code passes the tests now, I'm going to assume that you solved it and mark this as resolved.
Yes, thank you
Language: C++
Test suit missing the required header
std::string
.the picture is gone (
<img alt="pong" src="http://gifimage.net/wp-content/uploads/2017/08/pong-gif-3.gif">
)Added PHP 8.0 support
approved
How is such a mistake even possible: Expected: "Player 1 has hit the ball!" But was: "Player 2 has hit the ball!"? I passed the test task but further...
The description states
Alas, this is misleading; according to tests, "Game Over!" should be returned every time
play()
is called after either player has won, regardless whether they hit or miss.changed. Enough?
Yes. Well done :)
Rust translation
This one was fun. Thanks for the kata :)
Heya, the testing suite seems to be around the wrong way. Language is C#.
Expected: <string.Empty> But was: "Player 1 has missed the ball!"
(Expected always shows up as whatever I return as, instead of the other way around).
.
Seems to be an error with the random tests in C# (or I could be wrong on something). I pass the test suite no problem. Random tests are outputting the correct results for me when I debug to Console. But when I run the test, it always says:
Expected: "Player 1 has missed the ball!" But was: "Player 2 has won the game!"
The weird thing is, even if I change the "player x has won the game" code to say something completely different, so there's no reference ot that result, it will still output that as the result. (I'm clearing the string / result line each time and it works perfectly in the test suite). The other issue is if I return nothing / "" in the code, it will then say Expected: "", or whatever I change the result / return statement to.
Is something buggy with this or am I missing something?
EDIT: testing the suite with a complete blank statement (the default code), it says:
Expected: <string.Empty> But was: "Player 1 has missed the ball!"
As if it's around the wrong way somehow?
It can happen (and, frankly, happens more often than it should) that actual and expected values are swapped in assertion messages.
If you are able to confirm that it's indeed a case here, please raise appropriate issue as a new post. I cannot verify the kata at the moment :(
Ah ok, just did that. Thanks!
Random Tests Test Passed: Value == 'Player 1 has missed the ball!' Test Passed: Value == 'Player 2 has missed the ball!' Test Passed: Value == 'Player 1 has missed the ball!' Test Passed: Value == 'Player 2 has missed the ball!' Expected: 'Player 2 has won the game!', instead got: 'Player 1 has missed the ball!' Expected: 'Game Over!', instead got: 'Player 2 has missed the ball!' Expected: 'Game Over!', instead got: 'Player 1 has missed the ball!' Expected: 'Game Over!', instead got: 'Player 2 has missed the ball!' Expected: 'Game Over!', instead got: 'Player 1 has missed the ball!' Expected: 'Game Over!', instead got: 'Player 2 has missed the ball!'
Every player has missed the ball, how can 'Player 2 has won the game!' ???
The language is Javascript
Same problem for me, i have written in c#
Can you post your current solution as a spoiler so i can have a look!
.
Needs edge case:
maxScore = 0
.Hey, if maxScore was 0 then nobody could win, hence there would be no need to play a game. So i think its all good:)
Typo in the kata description. Output requirements say:
'"Game over!" - If the game has ended but either player still hits the ball'
but the tests only accept "Game Over!" (capital O)
Fixed.
... should equal 'Player 1 has missed the ball!' ... should equal 'Player 2 has missed the ball!' ... should equal 'Player 1 has missed the ball!' ... should equal 'Player 2 has missed the ball!' ... should equal 'Player 1 has missed the ball!' ... should equal 'Player 2 has missed the ball!' ... should equal 'Player 1 has missed the ball!' ... should equal 'Player 2 has missed the ball!' ... should equal 'Player 2 has won the game!'
Why 'Player 2 has won the game!' in full test suite?
Mmmm, sounds like an issue: that's ok that player 2 is winning, but he should have done so one round earlier!
btw: don't forget to indicate the language you're using.
Can you show what the value was to win the match ie.
maxScore
and also tell us what language you are using?:)No user - no question.
Lol.
That looks correct. Player 2 wins when Player 1 misses the ball (and on that turn, Player 1's miss is not announced).
The max score in that game (assuming that's the full game) is 5.
Maybe it's widespread in C# (at least I heard it from Donald), but in JS it's not conventional to move an opening curly brace to the new line.
I just realized C# was a translation -_-
But writing like this is not good anyway.
Hey, this is just a convention i follow when programming regardless of the language. Its not as if it is bad practice but rather personal preference so no need to really change it tbh
well, the idea is nice, but the description is rather desorganized...
Game over!
case isn't described anywhereThansk for pointing that out, its always hard to spot these things yourself. Ive updated the description now and hopefully that helps. if you think it needs some more tinkering let me know, if not you can mark this resolved :)
Thanks again
already better, but still not enough to my taste. ;)
Is it good now?
yep
PHP, Ruby, Python, TypeScript, C# translations, please check and approve :-)
Approved, thanks!
Now somebody just has to complete this in PHP and TS to verify that all versions are working correctly...
TS translation is a direct copy of the original JavaScript :-)
I believe that they're good (completed Ruby and Python versions myself and I'm sure the other 3 versions are just as good), but it'd still be nice if those 2 languages got solutions from other users as well.
Anyway I'm cleaning up stuff here before it can be approved so it won't be a problem :)
If player 1 and player 2 take it in turns to have a go, why are sample tests 4 and 5 asking for player 2's result? :-)
(Javascript)
var game = new Pong(2);
Here we say that the score to win is 2
Test.assertEquals(game.play(50, 53), "Player 1 has hit the ball!");
Player 1 hits the ball
Test.assertEquals(game.play(100, 97), "Player 2 has hit the ball!");
Player 2 hits it back
Test.assertEquals(game.play(0, 4), "Player 1 has missed the ball!");
Player 1 misses and player 2's score increases by 1
Test.assertEquals(game.play(25, 25), "Player 2 has hit the ball!");
Player 2 hits the ball
Test.assertEquals(game.play(75, 25), "Player 2 has won the game!");
Player 1 misses and increases player 2's score. Player 2 wins, so we return that string
Test.assertEquals(game.play(50, 50), "Game Over!");
Another turn but the game is over so return game over
Hopefully this helps
It's a 2-player game, not a 1-player game where 1 and 2 take turns. That may have been the source of the confusion.
@KDaryl, it maybe a good idea to put the above example in the description?
@adrian.eyre, agreed, updated the description.
( JS )
Description is incomplete. There's a whole
class
to implement, not justplay
.Nope, just the function play() has to be completed. Nothing else needs to be added to the class.
Ehm, your own solution has changes to the constructor, as does every other solution at this time.
Maybe it's possible to solve this by just writing
play
, but effectively we're asked for the entire classPong
.( Besides, it's better to specify expected behaviour and not specific implementation. )
Sorry, youre completely right. Ill update the description, thanks for the feedback!
What is the middle of
6
pixels ?!?Sorry, the paddle is actually 7 pixels in height (3 pixels below its centre and 3 above) hence why i said 6. I have corrected the description. Thank you