2048
gabrielecirulli.github.io
gabrielecirulli.github.io
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)!
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!
Ex:
x x x 2
x x 2 4
x 2 4 8
2 4 8 16
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
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.
Great game though - wasted waaay too much time last night playing.
var value = Math.random() < 0.9 ? 2 : 4;
https://github.com/gabrielecirulli/2048/blob/master/js/game_...I refuse to do these calculations in my head...
The author should do this, and create a counter of moves within the app.
:P I guess it was almost perfect attempt, and the quickest of mine so far (just a single 16 apart of 2048)
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.
https://developer.mozilla.org/docs/WebAPI/Detecting_device_o...
This sort of clicked towards, oooh I don't know about 1:30am this morning.
Won a few times and still keep picking it up. Now the Tetris dreams are starting; must stop.
Note: shameless parody plagarism, (original: https://news.ycombinator.com/item?id=7386459), but this thread has 20x points.
Also about your autoit "analysis" 36 + 150 + 13 != 162
Anyway managed to get to 1024 + 512 + 256 after that without random button mashing.
Hah. It's binary crack.
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.
You know you've had at least 4 4's, but you could have had more.
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
Nice clone but it's definitely a clone and so should be treated as such.
It's good to get paid for your work, even if it was fun.
Oh, no we have another Flappy Story in the making here!
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.
http://forums.toucharcade.com/showthread.php?p=3142737#post3...
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!
That's pretty damn near optimal, might have had an extra 2 when doing the final collapse, can't remember.
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.
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.
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.
Upvoted you to show my anger! :)
(in case folks on Android want to play it)
But seriously, well done. :) Completely destroyed my productivity.
:-) Hope that's fine. It might take an hour or so for the domain to be accessible for everyone due to DNS cache.
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?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
I hate you. ;)
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.
Final part was fast as all you need is two 128 blocks, one 256, a 512 and the 1024.
LOVE the game. Who knew I could single-mindedly focus on one task for hours and not get distracted.
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).
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....
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();Set it to a 6x6 grid.
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
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
Or a truer JS clone: http://threesjs.com
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.
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.
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.
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.
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 :)
Fun though!
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.pngThe 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?
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: *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.
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.
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.
Kind of hard to explain in words, but hopefully that helps!
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.
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.
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.
http://hnplays2048.herokuapp.com/
Check it out! Or clone it! https://github.com/grant/hnplays2048
The most amazing thing about this game is how it manages to be so creative and different while being so simple.
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.
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!
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 8192function 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)
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 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.
Does anybody have a better approach? Other than randomize and trying your luck? Or maybe that is the best algorithm for this case..
"Will 2048 ever reach 2048 points on HN? And how long will it stay at exact that number of points?"
Good luck everyone! ;)
2048 (gabrielecirulli.github.io)
1337 points by frederfred 8 hours agoWanted to add that the author also created HN Special, an extension for Chrome that makes HN look decent and adds some useful niceties. https://github.com/gabrielecirulli/hn-special
What's the theoretical max tile value you can get on Three.
It's unfortunate that RNG plays a significant role.
https://gist.github.com/k0nserv/9472334
EDIT: Script reached my score of 256
EDIT2: Script reached 512
https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-frc3/t1.0-...
Meta question: Would it be possible to get 4096?
Tada! I got my 2048 tile :) So happy
https://drive.google.com/file/d/0Bz9_OO8kXRkfY0RWdzZ6cDA4RDQ...
https://www.dropbox.com/s/4cmpwguulkbaktu/Screenshot%202014-...
Now, back to life...
it really is an amazing addictive game :)
thanks again!
This WebKit monoculture is getting quite anything. It's msie all over again...
I have a suggestion that is different from the common. Other than taking this finely open game in to a walled garden, bring flattr or gittip there :).
The key is big numbers at the bottom
Screenshot: http://imgur.com/9QzI3Z2
am DEFINITELY sure it's not hardware because it's working on my SUPER FAST laptop (1.1 Dual Core, intel HD, Firefox 27.0.1)
so am sure YOU did something
Oh and browser is FireFox 27.0.1
I suppose i'll have to just check this at home to figure out what the fuss is all about
like lining up the blocks descending sequentially starting in the top left hand corner, and then creating s serpentine pattern. try to keep the big numbers in top left corner for as long as possible!
Great game by the way!
I'd appreciate it, if someone can share a few more links with similar puzzlers on the web.
I have it on my iPhone and it's fun.
I scored worse by actually thinking and applying strategy. this IS a difficult game.
I will choose the lesser evil : burn the computer !
Thanks ;-)
Very simple strategy: propagate large values upwards (never press down).
Kudos to the creator for the perfect execution and design.
Finally beat it, 20588.
Very fun though.
Good game.
Great work!
I'm pretty sure I never used the down arrow in this game (sometimes you have to). If your high numbers end up in the middle you're kind of screwed.
okay, awesome game.
Still, fuck you.
Whole well. That's HN for yea.
I solved the puzzle
Fuck I think I'm addicted.
Congrats on the next flappy bird.