
Show HN: Snaketron, online multiplayer Snake - lopatin
http://snaketron.com
======
a1k0n
Nice. The protocol is completely insecure and the server trusts everything the
client does, so "Joshua" is just getting all the food every turn (by sending
"eaten-snack" messages) and drawing random stuff.

The client should only be able to send the direction it's turning and on which
turn, and that's it. The server should allow for some slack in the turn
numbers, but not much.

------
chubot
Nice job, spent a good 30 minutes playing this :) Brain virus.

I encountered some bugs where there was a guy who couldn't lose. He just kept
going straight and when he ran into me he didn't die. Maybe someone cheating
by editing the JS?

Also, I noticed some glitches where other players' snakes had a really high
velocity. Or was that a power up that I didn't get?

Tangent: Does anyone notice CRAZY GC pauses on Firefox, or something that
appears every 5 seconds or so? It makes the game almost unplayable on Firefox.
Switched to Chrome to play it.

~~~
lopatin
That's odd about the other snake having a higher speed than you. I've noticed
that when I was testing a lot but I thought I patched all the bugs that caused
it. I'll look into it thanks for pointing it out!

------
steve8918
Nicely done! I had a lot of fun playing this for about 30 mins!

A couple of questions: I thought that if one snake ran into another, it would
end the game but there were a couple of times where they just passed thru each
other. Was this a bug?

Also, there were a couple of times when either I or my opponent ran into the
other, and it ended in a tie. Shouldn't that be a win for the other player?

~~~
lopatin
Thanks! Both of those are bugs caused by latence issues. I tried my best to
make the game playable, but they still sometimes occur. Most likely the person
you were playing with had a slower connection or had a browser that didn't
support web sockets.

~~~
archangel_one
I had some similar problems; a couple of times I was just ahead of the other
snake but when I turned across his path it recorded as a draw. I understand
that it's really difficult to solve this sort of thing and provide a good
experience for the players, but it kind of kills the game for me if it shows
me that I'm going to win and then declares that actually I didn't.

------
pronoiac
On Chrome, the arrow keys occasionally scroll the page. Keeping my other hand
on the Home key helped.

I've also had it tell me "You won. :(" which is incorrect. :)

Edit: the Github badge at the top can get in the way. And there could be a
check if you've disconnected. And it doesn't remember me if I reload.

------
MCompeau
It's great how you can use spacebar to start a new game, definitely fuels the
addictive/impulsive play. Unfortunately the cycle is broken everytime I have
to take my hand off the keyboard and use the mouse at the Game Over prompt.

~~~
ryangilbert
I agree... hitting spacebar after game over would be nice. I find that once I
hit the okay button and play again then when I hit the first down (or up)
arrow afterwards that it slightly moves my screen.

All space bars and arrows while playing the game should fix that.

------
cing
I thought this might be a multiplayer game of a single instance of Snake where
the consensus move is executed in realtime from many players. Of course your
version makes sense, but I think the latter would also be cool :)

~~~
mgkimsal
Sort of like a ouija snake?

------
prezjordan
This is very nicely done, thanks for making it open-source - I'm learning node
to work on a game idea I've had for a long time. Could someone explain the
basic idea of server.js and some of the stuff in public? It's a little
overwhelming.

~~~
lopatin
Yea definitely, I wanted to comment this better but I was just too eager to
release it hah.

The run down is this. server.js is a long running script and it only has a few
global vars like games and playerQueue. These belong to the application as a
whole. They're basically data structures that hold everything that's
happening. Which games are being played, which players are waiting, and so on.
The main stuff happens with socket.io in the io.sockets.on('connection' ...
The paramter 'socket' in this code refers to the connection to a single player
so if my server logic says that this player just won the game, I would say
socket.emit('won-game') or in my situation I emit a 'gameover' message with
some data specifying which username just won.

There's a lot more to it and I plan on getting to commenting the code better
but that should point you in the right direction if you want to analyze the
code.

------
fidz
Really great! I think it was on "really big" canvas with multiple snakes, but
two snakes in real time are good too. Um, are those anonymouses are messing up
the score? Especially in loss/win ratio.

Btw, where do you host this app?

~~~
bfilmheld
I made a prototype for this, playable on <http://bfilmhelden.de:8080>

------
freditup
Cool game but quite buggy. Sometimes a snake went through me, another time the
opponent rammed into me and it was a draw. If we can have 3D shooters online
without these problems, I would think a snake game would be possible too ;D

Anyway though, I do think it's well done, and open source too, so no real
complaints.

~~~
lopatin
Thanks :) I think the issue is that some people are playing with browsers that
don't support web sockets, so even if you support them, their connection
affects the synchronization between you two. I should probably start doing
some feature detection for websockets

~~~
freditup
Sounds like a good idea. It's weird how JS is a step back in time compared to
Flash, yet is so rapidly modernizing.

One other little problem I noticed (on FF13) is that if I accidentally held
the down or up keys for too long, my browser would scroll down the page.

------
tylermenezes
My biggest problem with this is I've gotten two opponents which didn't try to
grow, just kept going in circles. They were pretty much guaranteed to win,
since I eventually hit myself. Even if I hit them, it was just a draw.

Kind of silly, since they'd obviously get bored quickly, but still a problem.

~~~
6ren
I think a "need to eat" would fix this, e.g. tail gets shorter by one every
unit-time (e.g. 10s).

------
superkuh
There are already people cheating. I'm looking at you Anon #2340.

------
coffeeaddicted
I love it. Tell against whom you fight - that would add to the thrill
(especially if it's one of the top-10, maybe even show the number _fat_ in
that case).

------
bfilmheld
Love it! You made a very entertaining game out of this idea!

I'm curious if you did by any chance see my take on multiplayer snake? (From
here or the tigsource forums, maybe? It's playable at
<http://bfilmhelden.de:8080/> less polished tough. Made some different
choices. (E.g. clients can only send commands, and also send always the full
game state.)

------
jboggan
It works really well about half of the time for me. A really nice effort, but
I do notice the other snake "moonwalking" sometimes and reversing several
steps before retracing their route. Sometimes I am able to kill them while
being several pixels away. It's an awesome start and a great excuse to learn
Node though.

------
ryangilbert
As more people keep playing I've noticed it's starting to glitch.

Last game my opponents snake ran into me and I could tell that he was then
done playing because his snake kept going in a straight line over and over.
About a minute later it finally said I won.

Just a heads up.

~~~
lopatin
Gotcha. I haven't experienced that yet but it may be resulting from all the
traffic I'm getting right now.

Or .. were there still snacks popping up after he ran into you? If not, it's
possible that the server restarted when that happened due to some exception so
you just ended up playing solo with no server connection.

~~~
laumac
Yeah this happened to me too. After a while the snacks stopped popping up and
my opponent just kept looping. Which means you have to refresh and lose your
running score :(

Fantastic game though, so addictive... the running score, and win ratio are
great. It would be cool if you could see your opponent's win ratio or a rank
of some sort too? Perhaps when you're counting down for the game to start?

------
piptastic
Very fun :) I used to play a lot of nibbles back in the day...

Small bug: over 10.0 W/L and it stopped showing up in the leaderboards:
<http://i.imgur.com/NChEp.png>

Once I lost a 2nd game it appeared again.

------
unimpressive
Magnificent. I was hypnotized by my 1# spot on the running score until I lost
it.

The meta competition is an addiction +1 powerup.

My personal recommendation is some catchy techno tune as music. Heart pumping
sort of music that gets you into the zone.

~~~
lopatin
Great suggestion, I would snake to techno

------
lumberjack
JS events using in these JS only apps conflict with Pentadactyl and Vimperator
for me. :(

EDIT: It's the extensions' fault, just to be clear. Also, I'm amazed by the
addictive nature of this simple game!

~~~
minoru
You can enable "ignore all keys" mode with Shift-Escape in Vimperator. It
would then just pass all your key strokes directly to the app. I believe there
should be similar mode in Pentadactyl as well.

------
binxbolling
This is maddeningly addictive. However, "draws" are a little weird -- I often
saw my opponent run directly into me, yet we get a draw? Shouldn't that be my
win?

~~~
piptastic
When I played, it looked like if you run into each other in the first 1-3
segments of the head end, it will declare it a draw. However if the player
runs into you further down the chain you'll win.

------
ricardobeat
This is great!

Would be cool to have maybe 3 rounds vs the same opponent and a chat window,
so the competition can heat up a little.

Also, I hope passwords aren't being stored in clear text :)

~~~
lopatin
Sure aren't :) Crypto node module FTW. And I should definitely add those
components to make it more competitive thanks for the suggestion!

------
dancole
Someone should write a bot program to play this game... which reminds me of:
<http://aichallenge.org/>

------
Dejital
At one point I was playing two games at once, from what it looked like!
Otherwise, very cool and a lot of fun. On Firefox 12.0

------
mikeroher
Any tips on where to get started with Node.js?

------
borski
Typo on the landing page: "New to Snaketon?"

Great fun though...collisions of snakes are buggy, but other than that it's
really a good time.

------
phildeschaine
Pretty cool, but the fact that you have to account for latency sucks. Is there
a way to make movement purely client-side?

~~~
lopatin
Thanks! I actually spent the majority of my time fixing latency issues. The
movement actually is mostly client side, but I have to sync positions
sometimes. With _purely_ client side movement many issues arise like one snake
lagging behind the other one due to rendering being slower on one computer, a
snake turning a block too late on one browser because it gets the signal
later, .. things like that. So I just sync positions when it matters.

------
kzahel
I was able to move diagonally through the other player's trail. Still looking
for a continuous-movement version of this

------
ryangilbert
Wow... this is definitely one of the coolest things I've seen on HN in my
short time here.

------
dubcanada
There is way too much latency to play properly.

------
ryangilbert
is the site down now?

------
firesofmay
Site is not loading!

~~~
lopatin
Just fixed sorry bout that. MySQL crashed overnight and just got to fix it.

------
fredsters_s
so fun!

------
boboblong
It should not be a draw when player A runs into player B near player B's head.
Player B should win.

------
boboblong
Also, make running into the edge kill you, or at least change it so that the
edges become lethal after a certain amount of time. That would make the
endgame more dramatic, as it would be easier to encircle your opponent.

