Pong in the shortest code
As always the code must be written in a free language (in both senses) and should be runnable on linux. Any libraries used must also be free, easily available and not be written for the purposes of this competition (and also not already contain a working version of Pong!).
Honestly, this question is a little too difficult for code golf. The ball physics for Pong is pretty complicated.
Just for reference there are some other code-golf, Noughts and Crosses (aka Tic-Tac-Toe) (both could use additional entries, who likes to "win" by default?), Write a small HTTP server, Self-Interpreting Interpreter, Self-compiling compiler, Compile Regexes ...
@felipa, Can you formalize 'as close as possible'? I don't know why my sed solution isn't in the lead.
@boothby My mistake. I didn't have time to actually run the python code and made a wrong assumption.
@felipa When you have the time, I would recommend you try it. In its current form, it is as fully featured as the 953 byte HTML/JS solution, with the exception that there is no pause function. Graphically, I think it is also quite agreeable. Nevertheless, I would like to request that it not be selected as the accepted answer, as its validity seems to be contentious.
AFAIK, "a free language (in both senses)" is certainly not "always" a requirement. We get plenty of answers in C#, Mathematica, etc.
/* Variable index:
a -> left player score
b -> right player score
c -> context
e -> event
i -> counter for dashed line
k -> keycode
m -> left paddle y
n -> right paddle y
p -> left paddle y velocity
q -> right paddle y velocity
s -> is start of game
u -> ball x velocity
v -> ball y velocity
w -> game is waiting (paused)
x -> ball x
y -> ball y
The script can be placed at the end of
onLoad. It needs the following canvas element:
Player 1 uses the q and a keys, and player 2 uses the p and l keys. Press the esc key to pause and any key to start/continue.
You can play it in your browser here.
I wasn't sure of the physics to use, so I started off with a simple reflection method and then added some variety and experimented with it a bit. The ball's velocity in the y direction is affected by where on the paddle you hit the ball, so you have some control over where the ball goes. The ball's velocity in the x direction slowly increases with each hit in the rally.
Could be golfed a bit more, I know I'm about two years late here. but you could assign `20` to a variable named `g` and save one measly byte.