Hacker News new | past | comments | ask | show | jobs | submit login
2048 (gabrielecirulli.github.io)
2903 points by frederfred on March 10, 2014 | hide | past | favorite | 410 comments



Hey, author here! I'm pretty overwhelmed that this made it to the top of HN without me even thinking of posting it here :)

I made this game as a fun weekend project, inspired by another game called 1024 (https://itunes.apple.com/us/app/1024!/id823499224) and a spinoff called 2048 (http://saming.fr/p/2048/). I did mine to add animations to the latter, which was a bit hard to play without them.

I discovered Threes only today, and I had no idea it looked so similar. I searched a bit and it appears as if 1024 is also inspired by Threes, so my game is probably the last of a long chain of clones :P

The code is also open-source. You can find it here: https://github.com/gabrielecirulli/2048

Feel free to ask me anything, and thanks to everyone for the attention! :)

By the way, my highscore is somewhere around 6000. Admittedly, I'm quite bad at playing my own game :P

EDIT: Make sure not to get addicted!

EDIT 2: The game now has swipe gestures and vim keys support (added by @rayhaanj)!


Holy shit I just lost like 45 minutes to this.


I've been playing this all day today. I basically created my own demise.


Creating a game that you, the creator, can't stop playing is the sign of a pretty good game. It's like "eat your own dog food", but with crack.


Too damn addictive.

Won a few times and still keep picking it up. Now the Tetris dreams are starting; must stop.


I was reading all your "I wasted x hours on this" and I rolled my eyes - "My god, these guys fall for everything". Then I tried it. Couldn't sleep. Damn it!


Just be glad you are already immune to Tetris.


Best strategy (for me) seems to be to play it like tetris. Never ever use the up key and create a row at the bottom where everything collapses into it.

This sort of clicked towards, oooh I don't know about 1:30am this morning.


That sort of works, I've been using a similar strategy but switching what I call "bottom" whenever the moment suits.


The enemy gate is down.


YES!


I'll have to look into that way of playing.


Empirically, this got me much further than the corner (stair-stepped) approach.


Yes, I won twice yesterday with this strategy.


I launched a very similar called Even last week on Android -- http://bit.ly/even-game -- have fun!


Downloaded and installed. Can you please remove the almost mandatory google games sign in, or make it optional. I tries to connect every time I move between the game and the menu, and I don't want it to connect...


Evil evil game.


And to quantify the evilness -- 1024 and exactly 12000 points.


Ha. 2048 and 20000+. Now I can put it in my /etc/hosts.


"I am sorry '2048' users, 22 hours from now, I will take '2048' down. I cannot take this anymore."

Note: shameless parody plagarism, (original: https://news.ycombinator.com/item?id=7386459), but this thread has 20x points.


just spent a few hours on this. I'm in love-hate relationships with the author now


Two hours straight and managed to get once to 1024.


I lost my whole damn day.


lost precious time for thesis writing! evil game!


You definitely need to have some kind of counter for how many times someone has reached 2048, and out of how many games played.


Or an expansion on that. Keep track of how many 128s, 256s etc you've ever formed. Show them as big counters directly under the game with an animation when you create any of them.


Log scale histogram?

Edit:

Actually all you need to store is the highest block achieved, and the number of times it's been hit. For instance, if you've only ever generated 2 8's, then you know that you've had 4 4's, and 8 2's...

Edit 2: Does the game allow four 2's to cascade into an 8? If so, maybe you could also store combo stats. It'd be way cooler to smash together four 256's than to smash together two 256's two times.

Not sure how that plays into the histogram.


> For instance, if you've only ever generated 2 8's, then you know that you've had 4 4's

You know you've had at least 4 4's, but you could have had more.


Ah. Lower bounds... they get me every time!


I can't tell if I despise you or admire you, all I know is that there was light outside my window when I first began playing this, and now it's pitch dark.

Upvoted you to show my anger! :)


So addictive. You know since tiles slide to the edge it would be great if this took advantage of accelerometers to allow tile combining by tilting. I know this is a browser game but if you ever create an app using the tilt motion to combine tiles would be awesome. :)



I haven't been this addicted to a game since Drop7.


I was so addicted to Drop7, and so annoyed at the crappy Android version, I made my own HTML/JS version with appcache, so I could play it in chrome offline: https://github.com/pavellishin/drop7


This is fantastic! Thanks so much for sharing, I learned so much from reading your very elegant and well-commented code.

Just in case anyone is looking at this and wants a direct link to play pavel_lishin's version, here's the raw github version: https://rawgithub.com/pavellishin/drop7/master/drop7.html

Side note: I got hooked on Drop7 during my first semester in college. I was fascinated by the game and wrote a simulator to pick the optimal move: https://github.com/keshavsaharia/Drop7Simulator


Ooh, nice! I thought about writing some sort of AI to play for me, but never got around to it. (Plus, it felt weirdly oroborous-like.)


Awesome work, thanks for posting. I too was annoyed at Android support. It could be one of their more popular games if it was just updated a little.


Same!


Please allow me to throw money at you somehow


Or you can download Even (free!) that I launched last week -- http://bit.ly/even-game -- have fun!


Yes! At the very least put up a BTC or Dogecoin address we can send donations to!


Or maybe go buy Threes which this is a descendant of?

http://asherv.com/threes/

Nice clone but it's definitely a clone and so should be treated as such.


I have Threes and they way way over-designed it. Also it's rubbery interface is really quite annoying. This one however is a perfection - simpler idea, pure gameplay, subtle animations and UI mechanics. It really beats Threes hands down even if it's a "clone".


Yep, and if you have a spare couple of minutes to play a game, the first minute is spent loading it.


iDevices only. Bleh.



They've been promising an android version for some time now. If they don't hurry up, though, they'll get beaten to it by clones.


Not sure if I can do that. Wouldn't it be unethical and unfair to the other developers?


You can always pay some sort of % as tribute, but you've created something that we all find a horrendous waste of time :-) so a way of remunerating you to some degree is not in the least bit unethical.

It's good to get paid for your work, even if it was fun.


Out of curiosity, I'd love to hear what your Google Analytics graphs look like! How long to people spend playing it?


Right now there are around 2100 people on the site and an average visit duration of around 4 minutes :)


How many reached 2048?


The latest stats show no "game-win" events :P It might just be a matter of time though.

EDIT: oops, there was a bug in the win/lose tracking so I probably missed out on a few wins. I fixed it now, so it should hopefully track it if someone else wins!


I just beat it! First try.. but I've been addicted to Threes for the past week or so.

http://i.imgur.com/nf25AVZ.png


If that's real, congrats! I had started doubting that anybody would ever win the game :P


It took me a few tries, but it's definitely winnable.


Do you have new numbers? I got a bunch of people addicted and I assume I'm not the only one.


Can you add in how many moves!!?


Each turn, one 2 tile is added, and other tiles may be combined. So you can derive the move count by adding together the numbers on all the visible tiles and dividing by 2.


This is inaccurate, because you have a 10% chance of getting a 4 tile added instead of a 2. That part makes the game tricky, because otherwise you could optimize every solution like an algorithm without ever losing.

    var value = Math.random() < 0.9 ? 2 : 4;
https://github.com/gabrielecirulli/2048/blob/master/js/game_...


Oh, huh, I didn't even realize it was doing that. Even so, the move count will still be roughly proportional to the sum of the board (plus or minus some random variation), won't it?


Thanks Neckbeard,

I refuse to do these calculations in my head...

The author should do this, and create a counter of moves within the app.


eh... Sorry - I was tipsy when I posted that...


This would be cool. I think winning in the fewest moves would be the most impressive. i.e. how few tiles you 'waste'. Though winning with the lowest score may approximate this.



http://www.screencast.com/t/NYuiFDueop8

:P I guess it was almost perfect attempt, and the quickest of mine so far (just a single 16 apart of 2048)


okay, and i win... and my record is 32768 score so what? it was fun) my screen: http://upload.freehacks.ru/MKPEP2 my implementation and guide you can found there: http://vk.cc/2nGPL3


Looks legit


I'm gonna call fake on this one.


There's actually a semi-optimal strategy that nearly guarantees winning if you're diligent about it. Just build a stairstep pattern with the highest numbers in the bottom corner of the stairs. Then basically combine sideways and downward and "always" resist the temptation to push up. Its kind of how some tri-diagonal matrix algorithms work. The only problem is you have to be fastidious about never using the one direction you've reserved as your excluded case (Up in my example) as that can screw your staircase by putting a [2] right underneath your wonderful [1024]. Just move blocks back and forth, waiting for the right blocks to create combo patterns, while generally storing lower cost blocks on the outside of the stairs, and then snake them through the stairs when you get a chain set up.

Ex:

x x x 2

x x 2 4

x 2 4 8

2 4 8 16


Did that, got stuck like that, pretty unfortunate.

http://puu.sh/7rKEF.png


After half an hour playing blindly I realized this, but even using this it´s hard to go beyond 500


I found one not-completely-horrible strategy was just blindly running round the curser keys.. eg. up - right - down - left, repeatedly. Got near 4000 points with that..

Great game though - wasted waaay too much time last night playing.


It's a good start but you will get stuck at higher level. in your case focus on increasing the value on the bottom left. When possible, shift the last line to the right. Never go up.


I was surprised at how well that worked. I was basically blindly cycling between left,down,right (with one accidental up) and got to 1024 on my first try.


function press(key) { var eventObj = document.createEvent("Events"); eventObj.initEvent("keydown", true, true); eventObj.which = key; document.dispatchEvent(eventObj); }

for (y=0; y<=1000; y++) { press(39); //right press(40); //down press(37); //left press(40); //down }

this gave me 1024 in couple of tries :D http://i58.tinypic.com/am9sh4.png


Here's a random key press loop: function press(key) { var eventObj = document.createEvent("Events"); eventObj.initEvent("keydown", true, true); eventObj.which = key; document.dispatchEvent(eventObj); } for (y=0; y<=1000; y++) { press(Math.floor(Math.random() * 4) + 37); }


Yes, I also discovered this after 20ish minutes of playing. If you're not diligent about it, it's very hard to recover.


However, I've locked myself a few times so it was impossible to go on without using 'up' (or whatever):

x x x x

x x x x

o o o o

o o o o

where at no point the same numbers next to each other allow collapsing. Maybe it's the problem not growing from the corner.. hm.


With enough tries anything is possible. There is probably even a person who ascended nethack on his first try (using the wiki of course, we're still talking things with p > 0) and didn't play it again because it's too easy and boring.


I've seen that. Wiki, #nethack, valkyrie, and some decent but not extraordinary luck.


And here's another win, took me a fair few hours though.

http://imgur.com/9FckZVX


I'd be interested in seeing the lowest winning score, highest winning score, and lowest losing score (!)


Managed to purposefully lose with 627 points. Lowest I've managed to lose by. :)


Beat the game: http://oi62.tinypic.com/2wdopq9.jpg

At least I don't have to spend any more time on it.

My simple strategy was to keep the biggest blocks in a corner at all times.


It took me 2-3 hours on friday, and some luck :) http://imgur.com/PNRIfW6


I did, with 23000 points.


Make sure not to get addicted!

Hah. It's binary crack.


Programmer Step #2 - write an automated solver :)


I thought about this for 5 minutes and really got nowhere. Can anyone come up with a nice analytic way to think about an algorithm?

There are a couple of brute force approaches: a) always pick the direction that will result in the most blocks to combine, b) always pick the direction that will result in the largest score.


I know someone was working on an AI that plays Threes (the game that inspired this one). Haven't seen any code from him though.

http://forums.toucharcade.com/showthread.php?p=3142737#post3...


I think you want to keep the large numbers in the corner.


How about using A* algorithm?


> this made it to the top of HN without me even thinking of posting it here

Good for beta testing it.

Unlike with Threes, there's no real reason to use numbers since they're all powers of 2. If you used letters (A, B, C, ...) you could market it to non-HN sorts, and have a version of the game in a 5x5 grid, or, more to the point, in a 6x6 grid with letters A to Z. Most people in the world know the order of letters in English.


Good idea with the letters, but perhaps not necessary. People are happy with simple numbers. Just look at Sudoku which doesn't use A to I.


I'm certain letters are necessary for a 5x5 or 6x6 board. M is better than 16,384, and Z far better than 67,108,864.


Why? Instead of A, B, C, you can go with 1, 2, 3. Ie use the binary logarithm of the numbers.


Good idea with the simple numbers, and certainly necessary to use some tokens other than what this 2048 app uses so we can have a version of it in a 5x5 or 6x6 grid.

When you wrote "Good idea with the letters, but perhaps not necessary. People are happy with simple numbers. Just look at Sudoku which doesn't use A to I", I thought you hadn't noticed my mention of the larger grid, which was really the main point of my comment and maybe I should've worded it differently. Though if you'd begun your comment differently, i.e. "Good idea with the larger grid, but perhaps the letters aren't necessary. People are happy with simple numbers. Just look at Sudoku which doesn't use A to I", I wouldn't have felt the need to reply to correct a perceived communication mistake.


Oh, for a larger grid, you might want to have letters anyway, because your point still applies.

It's interesting that log_2 2028 is just above what you can represent in a single digit. That's very close to merging two 9s.

I'd like to actually see someone pit x, log_2 x, and letter(log_2 x) against each other in an A/B test of the game. The latter two are simpler, but the former might be more exciting, because of bigger numbers.


Shit I just spent like 4 hours. I have final exams next week. You are evil!


Great "time waster" - just got 5752 score from first try! Very well executed, who cares if its a clone! :) Great job!


Hi Gabriele, I created a mirror of your project with an easier memorable name at

http://2048.mx/

:-) Hope that's fine. It might take an hour or so for the domain to be accessible for everyone due to DNS cache.


It's very coincidental that my game called Even, based on very similar gameplay was launched this past Friday -- http://bit.ly/even-game

(in case folks on Android want to play it)


I've started playing threes a week ago. Both threes and 2048 are fun to play. Except that I think in threes the challenge starts earlier in the game and every step counts and you can easily get into a deadlock. Can't wait to see the source code and analytics. Maybe you want to add on the page the highest score :)


Very fun game! Love the dynamic, couldn't get higher than 256 though. Also check out Fives for Android--somewhat similar: https://play.google.com/store/apps/details?id=com.rcg.fives


Likewise. I had one game where I had a 256 block and two 128 blocks, but I ran out of room to maneuver before I could combine the 128s to another 256 and then combine the 256s to a 512.


by pressing up-right-down-left, then repeat, I managed to get to 512 two times...


I did it by pressing up-left-down-right, repeating each direction as many times as possible. That's the worst part - knowing that your carefully calculated playthrough is actually no better than someone just pressing the keys in a set order.


Ran your strategy 162 times with autoit of which the following blocks came by: [128]: 150 times, [256]: 36 times, [512]: 13 times, [1024]: 0 times. Anyone else a good suggestion for an optimal "blind" strategy?


Perhaps I had a little bit of luck. But this shows you can easily get to 256 with little dedication. After which you can start to puzzle things together.

Also about your autoit "analysis" 36 + 150 + 13 != 162


Well, when it reaches a 256 block, it also reached a 128 block, so some games count for 2 or 3 blocks.


That's true. :)

Anyway managed to get to 1024 + 512 + 256 after that without random button mashing.


UUDDLRLRBA


I prefer Trip actually, it has the same rules as Threes, but it's much harder to get a high score compared to Fives. Because you only ever get 1, 2 or 3 as the new card, everything needs to be built up from there, it requires a lot more thought and planning. https://play.google.com/store/apps/details?id=ca.ginik.trip


You might also want to check out Even -- http://bit.ly/even-game -- have fun!


Two hours lost at uni today and checking hn first thing back home... nooooooo! I will now proceed to waste time. Good job! :)

edit: Ok, some random friend just emailed me and told me to check out your game. This friend does not hang out at the online places I do. It seems to be on fire!


Finally, at 2:26 a.m. I was successful with a score of 21000 ... that was fun, thank you!



Wow, that was fun, thanks! It starts to make sense after a while. Are lower or higher scores better? I'm at 21,204. http://imgur.com/4tnVPZ4



Even lower: 20148

http://imgur.com/28YNfDS

That's pretty damn near optimal, might have had an extra 2 when doing the final collapse, can't remember.


Even lower : 20132 http://imgur.com/dWiXGaW


Oh, _now_ you tell me not to get addicted! >:( You should've made that a splash page to the site, not an edit to a comment on the submission link.

But seriously, well done. :) Completely destroyed my productivity.


Just wanted to let you know (but wanted to wait before somebody would down vote such a comment here) that I really enjoyed your game, thanks and cheers!


Thanks a lot jerk...now ive lost 2 hours of sleep because of this game! Keep up the good work!


Totally cool, and addictive. Not exactly news, but at another level, completely HN worthy


You bastard! I had to work today!


awesome game. I love the math

  2 * 1024 = 2048
  4 * 512  = 2048
  8 * 256  = 2048
  ..
  1024 * 2 = 2048
            20480 <-- minimum points
is there a elegant formula to get to the minimum required points?


That's not quite the minimum points, since occasionally (10% of the time) a 4 spawns, instead of a 2.


that's incorrect.

just because a 4 gets spawned 10% of the time, doesn't mean that there couldn't be a game where 4 does not get spawned


4s reduce the total score. (E.g. I won with a score of about 20200 once.)


i stand corrected


20144 score


Thanks for the swipe gesture support, had fun playing it on the way home.


This is very fun and addicting, now I just have to get some work done.


I just wasted 60 mins playing this game. And I think I'm hooked.

I hate you. ;)


Ah! This game IS addicting! My highest so far is around 3500.


Extremely addictive and awesome patterns! Well done!


Congratulazioni Gabriele ;-)


Can't stop playing ;-)


Great job!


"EDIT: Make sure not to get addicted!"

Oh, no we have another Flappy Story in the making here!


No one has mentioned it yet, but this is an in browser version of the excellent iOS app Threes: http://www.joystiq.com/2014/01/30/addictive-ios-puzzling-com... (no affiliation, just a fan)


It's similar, but different. With Threes you combine 1s and 2s to make 3s, then similar numbers to double them. Also, the tiles in Threes only shift at most one spot at a time - with this game, everything's flung to the other side of the board.


It's much better than Threes because there's not a single reason why Threes should take almost 1 min to start on iPhone 4S.


Stealing all your contacts takes time, you know?...


While this is often true with games, given that Threes doesn't use your contacts, I would be quite surprised if this was the reason.


In-app anayltics initialization is a bitch too. So many motherships to talk too, so little time.


It is very strange. Is the app not written with native code?


Threes uses Unity. I would guess that contributes to the performance issues its been having.


I had more fun with this than Threes. I think it's how the tiles slide all the way over.


I agree, there's something satisfying about sliding all the things with just one keystroke. I wonder if it's like that desire to chuck things in parabolic arcs that made Angry Birds so popular? I actually bought Threes from the iOS App Store but I've spent much more time on this game for whatever reason.


Quite similar to Tripple Town also.


Not many posting winning scores, so here's mine: 2048 and 20368 points

http://imgur.com/c3aHuT4

I'm not going to claim it was first try. Probably my tenth. However, I got much better at avoiding the key mistakes:

- Always keep your highest number in a corner

- Use the rest of that edge as a "staging area" for the components that can next double the highest tile. Work the other tiles toward the opposite corner on that side and then double them upward into the highest corner.

- When you double the highest corner, you'll expose the "staging area" side. During this time, quickly work number back to fill that side so you avoid being forced to move the highest number out.

- NEVER let yourself fill a 3x4 grid. This will force you to move the highest column away from the edge and will probably end the game in a handful of turns.


21304 on my second try after reading your advice. (Probably 8th play or so overall.) Good advice. :)

http://imgur.com/uAZYb1s


These are some great tips. By keeping the highest number in corner and making sure I am not forced to move it, I have been able to get till (~20000 score) 1024, 512, 256 etc and then game over :( Going to try again.

LOVE the game. Who knew I could single-mindedly focus on one task for hours and not get distracted.


20484 after about two hours. A few close calls and at times I felt like I was playing Tower of Hanoi leveling up areas. Only pushed up twice.

Final part was fast as all you need is two 128 blocks, one 256, a 512 and the 1024.


Won with a score of 20252 thanks to your tips. And 3x4 grid isn't impossible to get out of, but you need some luck and a plan (like your staging area)


With this technique, the lowest I've scored is in the 6,000s, and that was when I veered from the protocol. (That bloody 3×4)


Won with score : 20132 http://imgur.com/dWiXGaW


Yeah, good advice. Took me about a day of playing, finally won with 21276 points.


First of all, kudos on a well designed game. It's obvious you've made something pretty addictive, as evident by the place on HN and the responses you're getting here.

One thing I've found out is that you can pretty easily get to at least 512 or higher just by repeating the following pattern:

  right + down + left + down
Try it out and you'll quickly see how it works. Any other similar pattern would also work:

  right + down + right + up
  up + right + up + left
  left + down + left + up
I will also sometimes break the pattern to consolidate some of the larger numbers when opportunities present themselves. But other than that, I usually stick to the pattern.

Of course, it will only get you so far, because you will eventually run out of space to keep the pattern working. But it will get you past the first few thousand points (512 or higher).


I managed to beat it following a basic pattern similar to yours:

1) Mash up-left (or towards any corner) until blocks stop moving

2) Press right

3) Start over

The trick is to keep the high numbers in the top corner so the new numbers don't spawn behind it, you basically start building towards that corner and things start to work themselves out.

Like you, I had to do a bit of actual logic near the end, you can see that I overshot by a small margin and ended up with a 128 block too....

http://i.imgur.com/NA92d3G.png


This works remarkably well. There are some spots where you have to apply logic -- in particular, I found that I progressed best when I built out the top row with my highest blocks (and then push/cascade my next highest block into the top when it got to be high enough) and I occasionally had to mash up-right rather than up-left to make that happen.


Yeah, same here. As long as you keep your high numbers against once side and the low numbers against the other, it's not hard. Pick one direction that you never ever use and you do fine.


Lol I'm kind of sad that the right+down+left+down trick got me further than all of my previous actual attempts hahaha.


For those "playing" in the javascript console, here's one way to get a handle on the (inaccessibly scoped) game objects:

    GameManager.prototype.__actuate = 
        GameManager.prototype.actuate;
    
    GameManager.prototype.actuate = function() { 
        window.gm = this; 
        this.__actuate();
    }
On the next move, the game object will exfiltrate itself into the global window namespace.

    gm.grid.eachCell(function(x,y,_) { 
        gm.grid.cells[x][y] = new Tile({x:x, y:y}, 1024); 
    });
    
    gm.actuate();


Heh, nice trick! The only way to get high score is to actually play, though :P


Not quite: http://i.imgur.com/Zr8piE7.png

Set it to a 6x6 grid.


Hey Steven, you should include the actual clickable URL. Noob


Made it to 1024: http://imgur.com/QQUXzCN. Here's my routine:

1. "tumbler" until 128: up right down left, repeat

2. Get 128 on the top in the middle two slots. Really any edge works, but I'll say top for simplicity. Keep a semi-large value on the side with one open slot in top row to prevent sliding. The other side on top is used for staging

3. Only use left, right and up. Never let a smaller value get trapped. This rule can only be violated to avoid filling the top three rows with the fourth empty.

I lost this game because I mistakenly filled the top three rows, forcing me to use a down. I think this strategy is viable to win however


That's cool! My current strategy is just to keep going until I lose. Admittedly, I'm pretty bad at my own game :P


Won on my first try after my original post! http://imgur.com/rnGYLY9

Here's the new routine: 1. "tumbler" until 128 can move to the upper left corner.

2. The highest number on the board is always in the upper left. Make the top row descend left to right.

3. Before combining values on the top row, keep hitting up until one of the lower rows will not combine from a left.

4. Often, the slot you are filling (eg, top right or one below top right) will have a two. Alternate pressing "left" and "right" until a two appears, allowing you to combine

5. Keep the second row locked as soon as possible with unique values ASCENDING left to right. This way you can use up, left and right without moving the slot you are filling on the far left of the second row.

There are a few other pattern recognition tricks that you'll pick up to aid in filling a slot for higher values. A few other misc tips:

* try to keep high number squares close together, and merge up to the top row as soon as possible. Otherwise, they will just close off a slot

* You may get a 2 trapped on the top row blocked by a higher value below it. Unfreeze the second row by combining squares & hope that a two appears in the new opening

* only 2's or 4's will appear. They (always") appear in the space left behind by the previous movement


This strategy worked quite well for me up until right around where you got to, 11532. Certainly much more effective than just trying to wing it without a strategy.


Excellent strategy. Got painfully close to victory - 16,516 total.


used the same strategy, lost at about 11.5K after I had to use a down after filling my top two rows. definitely works well.


See also the original iPhone game: http://threesgame.com (Support the developers! It's a great game.)

Or a truer JS clone: http://threesjs.com


This game is not the same dynamic as Threes. Both are great games and worth checking out.


Great game! Love the simplicity!

I played a round, and got to 512. But toward the end I wasn't sure if I was actually playing with a strategy, or just pressing buttons randomly with some thinking involved.

So I built a script to randomly press the arrow keys[0]! I let it play a few games, and the highest it got to was 128 before consistently losing. So I guess you'll need some decent strategy to get to 2048.

0 - https://gist.github.com/Wayfarer247/9469272


> So I built a script to randomly press the arrow keys[0]! I let it play a few games, and the highest it got to was 128 before consistently losing. So I guess you'll need some decent strategy to get to 2048.

That's a great idea for testing the depth of simple games. It's good to know a baseline score: players should be getting to the 128 tile or better, or else they're doing really bad.


Losing that early could be almost as impressive as winning. Think about how hard it would be to miss every question on a multiple choice test.


If you remove one key it'll get to 256. I removed the `down` key and larger blocks started gathering on top, which was advantageous.


I wrote a version myself in python and have been playing with strategies. It seems fairly resistant to simple greedy strategies (maximize highest score/maximize empty squares/etc).

In terms of "blind" strategies [up, right, down, left]* works pretty well, but [up, right, up, left]* is by far the best I've found. It gets to 512 about 30% of the time (!), with about 0.2% hitting 1024. Still haven't seen a "win" using the blind strategy in several 10,000s of runs.


This simple game really shows how amazing the human mind is. I've never played any variant of this game before and when I first started I was blind to the mechanics of how this worked. I was moving so slowly and would fill up the board quite quickly.

After playing this game for 2 hours now my fingers are moving faster than my conscious mind can really follow. In my last game I was doing combo moves taking "2" blocks to "64" blocks in mere keystrokes. I've been surprised several times when things work out.


That's true! I noticed it as well, and it's pretty awesome.


So I'm playing this since 10 minutes now and I have no idea what so ever I'm doing but it makes me feel like I'm performing well.


10 minutes is farther than I got... I only now realize after the first run how to play the game. Dang, that can get addicting.


I got the hang of it during my first play, and ended up with 512 with a 256. I suspect there may be a system that lets you clean up the mess without creating too much new mess.


This game feels like life. I plan and make a move. Some pieces move exactly as I had wanted. A bunch of other pieces that I wasn’t looking at, also move. Some of these unexpected results surprise me and make me happy, I even subconsciously take credit for them. Some others, I don’t even notice. It’s okay, there is too much going on.

Sometimes it feels too hard and pointless to plan, so I am pressing the arrows almost randomly. Need a break from thinking and taking responsibility. I just hope that I am going in the “right” direction. Sometimes I do, sometimes I don’t. It’s also hard to tell. Ah well.

Now I’ve been doing pretty well at this for a while, I am getting pretty good I think, I have it all under control. A few moves later, before I even know it …. oops! suddenly it’s all a mess! :(

But there are miracles also. I’ve been in this mess for a bit now and it’s not much fun. It’s slowed down and my heart is not in the right place. Suddenly, a couple of moves later, I am totally back in the game! I don’t know if I know this, but it was barely my doing!

Of course, it’s this elusive goal (of 2048 or 42 or whatever else), it’s the reason why I keep going. I am pretty sure it’ll be really cool once I get there :)


This is one of those games that I do best on my first try when I have no idea what I'm doing, and then do worse and worse the more I think I have a strategy.

Fun though!


exactly. I got up to 256 first try and it took quite a while before I ran out of open tiles. 2nd try hit the wall shortly after 128... third time it went so quick and I only had a single 64. addictive and ridiculousness! :-)


The game is super addictive and I figured out a way to get to 11000 in the first hour. It's actually an excellent analogy for social network-type products and any business really. If your users belong to different clusters and similar clusters don't meet, there is little value and the network doesn't become more valuable for anyone. By focusing on the same corner scenario you help similar clusters find each-other consistently and thus amplify value to each-other. I took over one corner and keep stacking on to it with blocks of increasing value, essentially never moving out of it. If you move out of your corder, a different cluster takes hold in it and then everyone in that corner will hesitate to buy into you, even if the other cluster is small - it becomes a thorn in your butt. Great job! I learned something new today (Plague has also been very educational for me so far, but for viral dynamics.)


Quick and dirty 'dumb' solver (might require manual intervention sometimes):

		var manager = new GameManager(4, KeyboardInputManager, HTMLActuator);

		// Pattern definition (0: Up, 1: Right, 2: Down, 3: Left)
		var pattern = [1, 2, 3, 2];

		// Pattern Repeater
		var i = 0;

		// Interval
		var solverInterval = window.setInterval(function() {

			// Check if game is over
			if (manager.over)
				clearInterval(solverInterval);

			// Repeat pattern
			if (i % pattern.length == 0)
				i = 0;

			// Execute the move
			manager.move(pattern[i]);

			i++;

		}, 200);
Best pattern found so far is "var pattern = [1, 0, 3, 0];" I reached 1024 with it. https://dl.dropboxusercontent.com/u/21387598/1024-Best.png


I have some interesting results.

The first time I played the game I scored around 3000 points. After that, I tried to slow down and focus on keep the same kinds of numbers together, but after that, I couldn't get past 2250.

So I wrote a script that used Math.random() to hit the array keys continually, and the score was much lower: 1000.

Then I tried the sequence RIGHT UP LEFT DOWN over and over instead of Math.random() I scored significantly higher than all of them, in the 4000s.

Does anyone know why this might be?


Tried 3 games, and the scores were 2700, 1200, 5000. So maybe. But then I wrote a function to play it for me:

    var manager = new GameManager(4, KeyboardInputManager, HTMLActuator);
    
    function play() {
      manager.restart();
      var m = 0;
      while (!manager.over) {
        manager.move(m);
        m = (m+1)%4;
      }
      return manager.score;
    }
... and that gets scores between 500 and 3000.

(Edit) Histogram of 500 runs:

  0k: ***
  1k: *******************
  2k: ****************
  3k: *********
  4k: *
  5k: *
  6k: *


Which is about the same score you get if you concentrate and really try hard to get a high score.

I think this might be a "hacker" version of the slot machine - the player feels as if he's in control while in fact the outcome is pretty random.


I don't buy it. I got monotonically increasing scores, with my last play around 10k.


Hmmm, that wasn't my experience. I got a score of 7540 on my first try. Although I do suspect that the skill component might be less than we think.


Yeah, when I tried a systematic approach, I was getting better results than when I tried thinking about it. Left Down Right Down repeat.


This is actually a good method: by using this method (avoiding up and favouring down), you tend to cluster 2s and 4s towards the top while larger numbers percolate downwards (and towards the middle). If you encourage this natural tendency, you can do even better.

When you're nearly stuck, you can often pick left or right so that a new tile can access both 2 and 4 and save yourself.

I got comfortably to 1024 with one go of this method, scoring 16744.


Nah, if I concentrate I can get to 14k. I haven't actually won yet, though; I keep making a mistake.


I don't know, but I can confirm.


I think I have the beginning of a solution. The end result should be 2048 on the top-right corner (for the explanation). Always keep the highest value there. To do that never do a down without the right column filled and never do a left without the top row filled. Within those restrictions keep the top row in ascending order by building numbers on the left of the second row, so that they will match above and cascade right in powers of two.

I did this successfully for a while and then had no other option but a down without the rightmost column filled and lost my placement.

EDIT: A variation of this that works well is to only do up, left and right if at all possible. This keeps the highest values on top making it easier to match top-down. I've been stuck on 512 though.


The key is to have a well defined 'edge' between filled and empty areas - so that the high-valued tiles are on the corned away from the emptiness where 2s spawn; and low-value tiles are on/near the border.

Note that you can't afford to keep much unconnected duplicates - near the win point, you need to have 1024+512+256+128+64+32+16+8+4+2 which is 9/16 tiles filled already, so a few extra mid-value tiles cut your 'operating space' to near zero; so you must keep the high-values mostly ordered and agressively eliminate unneeded duplicates.


I was able to get 2048 building off of your solution. As you said, always keep your highest number in the top right corner. Try to build the next highest numbers up along the right edge, so that you have say, 256, 128, 64, 32 along the right edge. Always keep 4 numbers there, and only use up/down/right. Then just focus on building whatever number you need next to double the bottom right number, so that you can "chain up" numbers along the right edge and double your highest number in the top right.

Kind of hard to explain in words, but hopefully that helps!


Yep, this is pretty much the same solution with the right edge instead of the top edge. I got to 1024 and then blundered and couldn't get 2048. This thing is addictive though.


I managed to get 2048 on my first try. Different enough from Threes to stay interesting, but a lot of the same strategy applies. In Threes though, the number that appears has a higher chance of being a bigger number (24, 48, even higher later) the longer the game goes on. There were a few times I was almost stuck and was able to get out of it by continually moving in the same direction and sucking up 2s.

http://cl.ly/image/462B1P0Y250T


Why do I feel like another good name for this game would be "8 years of running a startup"?


Finally won with a score of 20548. At first I was using a strategy of getting the biggest number into a corner. This follows a pattern of mostly up-right-up-right-... with an occasional left or down thrown in to get unstuck. This approach can pretty reliably get you to 512 in the corner without much trouble. But eventually this method saturates the available "storage" space with an inefficient pattern of tiles up to the diagonal. Then you have to start changing things up and continuing becomes tricky.

Then I tried the approach mentioned here of left-down-right-down-left... in a very mechanical fashion. I believe that this is very likely the optimal mindless strategy. It works amazingly well. As long as you never hit up, it fills things very efficiently and the biggest numbers percolate down towards the middle of the bottom row.

The way I finally won was to take this second approach and augment it with some periods of trying to get the biggest number in the corner. Start with ldrd until you get some 64s or 128s, then slow down and play catch-up with a corner. Then go back to ldrd. Occasionally stopping at strategic places to consolidate things also seems to help quite a bit.

All in all, a very fun game with some interesting properties.


Quite a lot of fun.

One minor nit: if the board is full, but you can make a move that will free up a space, you can make that move and the new tile will appear in the newly opened space, but then the game immediately ends afterward. EDIT: OK, apparently this only happens if there are actually no more moves; as long as moves remain the game continues.

Also, hitting "space" reset the entire game; I'd expected it to either do nothing or add a tile without moving.


That's intended. In 'Threes' for the iPhone you have to use that remaining block to solve more as you can see what's coming next.


The source code's here, in case anyone is interested: https://github.com/gabrielecirulli/2048


Hey guys! I made a multiplayer version of this game in about an hour or so. (Twitch plays pokemon style)

http://hnplays2048.herokuapp.com/

Check it out! Or clone it! https://github.com/grant/hnplays2048


I got a 1024 and a 512 playing alone, then somebody appeared and screwed the game in 10 seconds. The "Twitch plays pokemon style" is an very apt.


That's pretty funny! Well done!


It's a ton better now. :)


Working on syncing atm...


Very cool. Spent a while trying to get a high score by thinking about it, but in the end managed to beat it just by pressing the arrow keys anticlockwise one after the other!


Love this! Just when you think that a genre like tile puzzle games has been completely done, something like this comes along and shows a new way of thinking about it.

The most amazing thing about this game is how it manages to be so creative and different while being so simple.


Thanks! I shouldn't take all the credit for it though. The game is basically a clone of the two games I've been inspired by, as an attempt to make my own version and learn new things along the way!


I never imagined that I would one day feel like I'm "downing in my own filth of useless powers of 2".


Nice, only thing I don't like in the game is that I do better scores just doing (repeat((left or right once) + (up till it doesn't work anymore))) than when I think about my moves...


While we are throwing around clones of threes, here is my SEXY clone of titled Menage a Threes. Heh. http://www.kongregate.com/games/honkskillet/menage-a-threes

Also, protip: to get high score choose one direction that you will never push towards. You'll end up with a gradient of high value tiles on one side, lower on the other, which desirable.


Maybe Monday morning is finding me too pedantic, but this is similar to Threes (http://threesgame.com), not just like Threes. There are some pretty obvious differences, from the movement of the tiles to the requirements for tile mergers (multiples of 2 rather than 3). The comments thus far do not make that distinction.


I've made a version of 2048 on Hexagonal Board - check it out https://play.google.com/store/apps/details?id=com.spiralcode... It's free and has no ads, so enjoy! I guarantee you will like it.


Reminds me threes: http://asherv.com/threes/


agreed, was just playing that moments before seeing this coincidentally.


I eventually won and went on to score 32420, eventually losing after getting a second 1024 on the board. I'm fairly certain a 4096 is achievable.

The cardinal rule, as many have said, is to keep one side filled, in descending order, with your largest piece in one corner. Once you have that side filled, you have to make sure that any time you have a duplicate on that row that you:

(1) only ever shift toward your largest number

(2) ideally have a parallel row that will not shift before you do (1)

Until you can refill your last row, circumstances may lead you to have to move in the forbidden direction, which could wreck the whole game. Point (2) ensures that you can fill your back row with another piece immediately, restoring 3 directions of moves as quickly as possible.

If you end up with any 2's on your back row, you must build them up to higher numbers ASAP. Last thing you want is buried 2's.

Once your numbers start getting high, I think it makes sense to use the front two rows exclusively for 2's, 4's, and the occasional 8, but to shift 8's to the third row as soon as possible.

I've found that to actually finish once you have all the pieces you need, it may make sense to break script, but if you want to go on to try to make 4096, you may want to carefully stay on script.

I've found that in tricky situations when I want to combine large value pieces that are just not in alignment, it makes sense to try to slide lower value pieces under one to "boost" one of the others into alignment. The ability to do this makes it valuable to keep your combining pieces in the middle of the board.

Lastly, when you have multiple possible moves, make the move that takes most advantage of the piece that's about to appear, either because you can quickly combine the new piece or because it can "boost" another piece into alignment.

Follow this advice, and you will be a star!


I believe the largest tile you manage to get is 65536, that is if every random number falls in the perfect place.

And this would be the largest score you could get on the board:

      2      4      8    16
    256    128     64    32
    512   1024   2048  4096
  65536  32768  16384  8192


Reaching 4096 is achievable. I've just done it!

http://i.imgur.com/JhwQzln.png


This script will give you a keyboard-shortcut to skip the 'boring beginning' of the game. Run it a few times to get a nice starting point:

function arrows(key) { var eventObj = document.createEvent("Events"); eventObj.initEvent("keydown", true, true); eventObj.which = key; document.dispatchEvent(eventObj); }

document.onkeypress = function (e) { e = e || window.event; if (e.charCode = 122) { for (y=0; y<=100; y++) { arrows(39); arrows(38); arrows(37); arrows(38); } } };

var divje = document.createElement('div'); divje.innerHTML = "Press 'z' to fast forward ;)"; divje.style.position = 'fixed'; divje.style.padding = '10px'; divje.style.top = '10px'; divje.style.left = '10px'; document.body.appendChild(divje);

(some js based on script from varyform)


My entire agile team is now impeded because of this game.


Oh! My productivity! It's like the "great sudoku disaster of '02" all over again!


Simple and creative! I like it a lot.


Ship it as a mobile app, seriously!


Yeah I'm really enjoying it, would love it on Android. It's different enough from Threes and Fives to warrant its creation.


would definitely agree, its a really fun game!


Check out Fives on Android--similar but I think way more polished, and well, on your phone: https://play.google.com/store/apps/details?id=com.rcg.fives


I wonder if there's an optimal strategy. Hmm.


I looks like the new block appears randomly. If the new block appeared even if you didn't move anything it would be easy, but they don't and that can ruin your strategy.

I got to a 512 block in a corner and then got blocked by a new block in the same corner.

I think the strategy is very simple. Pick a corner and mash keys that move into that corner. For example for bottom-right corner, just mash right and bottom. When you can't move anything anymore, move into the direction that keep your highest block in a corner and then continue to mash and hope that a new block doesn't appear anywhere close your highest block. I have gotten a 512 block in 2 minutes twice( score over 6000 ). It would only take time to reach more, and maybe actually look at the board instead of mashing; but that is problematic since the new block appears to be random.

1024 could be reached in under an hour and 2048 in a day, i think.

It would be better if you got the position of the new block. That way the game would be solvable in some normal time.


I tried a "tumbling" strategy, where I would press right, down, left, up, repeating. You'll see that the blocks end up tumbling around. I was able to get 256 several times.

I also tried a very deliberate (and slow) strategy of actively trying to build up the necessary matching blocks and was able to get to 512 with a score of 5900.


I seem to pretty much always get a higher score by button mashing, or going up down left right in rotation than by trying to figure it out. :(


So far the best heuristic I've found is to not let smaller blocks get trapped behind bigger ones.


I found that smashing the arrow keys was the most effective way to play this game.


I've found simply pushing up, left, down, right, I can routinely outdo the score I can attain by actually playing with thought.... Kind of disappointing, but then I lost hours to this already. Fabulous game!


Egads this is excellent! As others have mentioned, would love to see a 5x5 variation and also be allowed to "keep going" after getting to 2048 to see how far you can go. I was disappointed that it ended and I had about half the squares empty and -might- have been able to get a 512 on the board as well. But just fantastic. Perfect balance of "speed when I want to blast through the easy levels" and "I need to think about the best next move" as well as try to construct an algorithm that helps get me to the endgame!


Finally had a chance to play Three's since it came out on android today and it honestly just made me want to play this more. The games are very similar, but 2048 is just more enjoyable to me.


I feel like a crazy person, but when i play this game for a while, screen text appears smaller. Like it's messing with my eyes or something. Does anyone else feel this happening?


You're not alone.


Wrote a script which plays using a simple greedy approach. Chooses the current best option. Doesn't seem to get past 512 so far. It does however consistently get till 256. Just copy the code in the console and restart the game (space bar) to run.

Does anybody have a better approach? Other than randomize and trying your luck? Or maybe that is the best algorithm for this case..

https://gist.github.com/AeonAxan/9482114


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

Search: