TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Mathematics of 2048: Counting States with Combinatorics

159 pointsby jdleesmillerover 7 years ago

9 comments

air7over 7 years ago
2048! Towards the end of the 2048-craze era, I wrote a solver for the game that unlike other solvers that came out, had no built-in algorithm about how to play.<p>It was quite simple: It simulated games from the current position using random moves, and chose the move that resulted in the highest average end-game score. The surprising result was that even though random moves are obviously a terrible game plan (on average, random play from a given starting position lasted 40 extra moves and scored an extra of 340 points before dying), using the least bad move each time led to very good game play over all: An average game had 70000 points and lasted 3000 moves, reaching the 2048 tile 100% of time and the 4096 tile 70%.<p>Also, perhaps of interested to this crowd, I later noticed that the web version of the game had exposed JS for the board state and controls. This allowed me to write a bookmarklet version of the solver that could play the original web version directly. This was fun because many game variants came out (like Hexagon 2048, and 20Euros) which were all different games, but were based on the same controllers. The solver, being &quot;general purpose&quot; could play many of these variants without any tweaking.<p>Solver demo: <a href="http:&#x2F;&#x2F;ronzil.github.io&#x2F;2048-AI&#x2F;" rel="nofollow">http:&#x2F;&#x2F;ronzil.github.io&#x2F;2048-AI&#x2F;</a> Write up: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;22342854&#x2F;what-is-the-optimal-algorithm-for-the-game-2048&#x2F;23853848#23853848" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;22342854&#x2F;what-is-the-opt...</a> Bookmarklet version: <a href="http:&#x2F;&#x2F;ronzil.github.io&#x2F;2048AI-AllClones&#x2F;" rel="nofollow">http:&#x2F;&#x2F;ronzil.github.io&#x2F;2048AI-AllClones&#x2F;</a>
评论 #15329226 未加载
评论 #15329216 未加载
评论 #15332513 未加载
评论 #15332723 未加载
dopppover 7 years ago
Would be nice to see a similar analysis done on Threes given that it came before 2048. By game design standards, 2048 is very poorly designed. 2048 is easily beatable whereas Threes takes a lot longer to master and beat [0].<p>[0] <a href="http:&#x2F;&#x2F;asherv.com&#x2F;threes&#x2F;threemails&#x2F;" rel="nofollow">http:&#x2F;&#x2F;asherv.com&#x2F;threes&#x2F;threemails&#x2F;</a>
评论 #15330917 未加载
评论 #15328149 未加载
评论 #15328182 未加载
评论 #15328957 未加载
Hbthegreatover 7 years ago
Once you know the basic strategy&#x2F;naive algorithm behind winning it becomes easy to get to much higher than 2048.<p>1) Swipe left until nothing else moves<p>2) Swipe down until nothing else moves<p>3) (If an empty space) Swipe up once<p>4) Repeat from 1.<p>There will only be a few times that you have to stop this process to get &quot;unstuck&quot;.
评论 #15329602 未加载
ggmover 7 years ago
win? you mean people &quot;win&quot;? I&#x27;ve never &quot;won&quot; this game. Its beaten me.<p>you can stop smirking, all three-fifty-hundred of you. I know.<p>(lovely game btw)
评论 #15328657 未加载
评论 #15328175 未加载
popcorncolonelover 7 years ago
I really thought this article was going to be about the state of combinatorics in the year 2048.
评论 #15332787 未加载
justinpombrioover 7 years ago
This isn&#x27;t an estimate, it&#x27;s an upper bound. Unless I&#x27;ve missed something, a board filled with 2s would be counted as possible by this article, despite being unreachable. There are many unreachable states that they are counting.
评论 #15331798 未加载
TeMPOraLover 7 years ago
Great post!<p>2048 is really an addicting game; at this point it&#x27;s my go-to activity when I&#x27;m e.g. in a boring conference and have brain cycles to spare. I have a copy in my browser, on my phone and inside my Emacs.
评论 #15328557 未加载
infinity0over 7 years ago
&gt; at least 938.8 moves on average<p>&gt; at least ... on average<p>wat<p>&gt; The main simplification that enabled that calculation was to ignore the structure of the board<p>Oh OK so he doesn&#x27;t mean &quot;minimum&quot;, he means &quot;assuming perfect play under his simplified model&quot;. Which is neither the minimum, nor the average assuming perfect play under an exact model.<p>So it&#x27;s unclear that his previous figure of 938.8 is particularly meaningful since it assumes an inexact model.<p>Actually, assuming a perfect AI exists (i.e. the constraints imposed by the structure of the board is not a hindrance to a sufficiently-advanced AI) then the average number of moves needed is simply 2048 &#x2F; mean( (2,0.9), (4,0.1) ) = 2048 &#x2F; 2.2 ~= 930.91 which is very close to the previously-quoted figure and has the advantage that it<p>- is independent of any potentially inaccurate model of the game dynamics<p>- takes like 1s to calculate, and you could do it in your head
评论 #15329572 未加载
评论 #15329193 未加载
feborgesover 7 years ago
I love the smell of tex equations early in the morning.