Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Snaketron, online multiplayer Snake (snaketron.com)
96 points by lopatin on May 26, 2012 | hide | past | favorite | 55 comments



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.


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.


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!


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?


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.


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.


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.


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.


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.


Lol that actually occurred to me. I had some issues with hotkeys but I think I might figure it out and add that, now that a few people have mentioned it already :)


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 :)


Sort of like a ouija snake?


Left is made of fire.


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.


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.


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?


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


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.


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


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.


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.


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


Hey man, that was my strategy a few times.. seems like a legit way to play I think.


You can still win - just keep on eating, at one time a green point will suddenly appear in their path and it will make them lose (and you can get lots of points in the meantime).


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


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).


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.)


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.


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.


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.


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?


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.


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.


Great suggestion, I would snake to techno


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!


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.


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?


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.


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 :)


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


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


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


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


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.


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


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.


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


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


There is way too much latency to play properly.


is the site down now?


Site is not loading!


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


so fun!


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


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: