[racket] Why don't you tackle a universe-based pong game?

From: Darren Cruse (darren.cruse at gmail.com)
Date: Mon Jan 19 17:36:50 EST 2015

Just FYI in another thread Matthias suggested maybe I try a universe
(networked) version of my pong game and I did give it a go and just posted
it on my repo at:  https://github.com/darrencruse/pong-world-racket

If anybody cares to actually try it, I do have a "run.rkt" option to fire
up the server and both clients on one machine (copying what I saw in the
Hungry Henry game from Realm of Racket).  But I have more extensive setup
instructions in the README if you want to run it for real.  I also mention
I've got the server code up on an ec2 instance but I've stopped it at the
moment.  If anybody tries this for real let me know and I'll fire that back
up you can try that as your server if you like.

Regarding the design I thought about some different approaches but decided
to try a simple approach - that I wasn't sure would run well over the
network but I decided just to try it and see.

This is where the world state that used to live in my original
(non-networked) pong game gets "owned" by the server, with keypresses for
paddle movements sent as messages to the server.  So the server updates the
ball and paddle positions and repeatedly sends the entire world state to
what are (basically) "thin" clients, only responsible for drawing the world
state and forwarding up the keypresses.

I liked this approach from a design point of view because it seemed close
to something that could become a generalized extension of the basic world
big-bang approach.  Where your world state doesn't "live" on your machine
it lives "in the cloud" and inputs like key presses get handled on the
server and your world state automatically gets transferred across the wire.
 i.e. if combined with a way to automate the deployment of the code base
across both the client and server, it seems like a neat idea...

At least that was in the back of my mind when I started on the pong game.

It turns out the universe pong (I called it "pongiverse") runs pretty good
for me in a number of my tests.  Though with an older linux box it was
funny the messages would back up and it's display would get behind the
other machine, and then all of sudden zip zip zip it would process the
backlog all at once and the game display would scream for a moment till it
caught up.

So I do see the approach is flawed for complex/fast moving games - the
screen movement shouldn't be tied to network latency.  After doing this I
found a really nice article (that even uses pong for it's examples) that
talks about different design approaches:
http://drewblaisdell.com/writing/game-networking-techniques-explained-with-pong/

It calls what I did a "Terminal Client" whereas what would be ideal is a
"Predictive Client".

But it certainly was fun and I like how Universe has been designed to make
these types of programs fairly easy.

Last thought:  It's funny it does seem like this "generalization" of
thinking of the world state as "living on the server" would work well for
some things, e.g. forms submitting their data to the server for processing
or games that are more "turn based" (it's your turn, now it's your turn).

I wonder if others have thought this way too?  Or if Racket maybe has
something similar to this idea already?  (I'd stumbled briefly on "Places"
was that like this I wonder?)

Sorry for writing too much hope this a little interesting to some of you
guys. :)

I do think the Universe stuff is interesting.

Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150119/4e0b7c28/attachment-0001.html>

Posted on the users mailing list.