Share your repls and programming experiences

← Back to all posts
2048 Game and Bot
MrEconomical (2293)

2048 Game and Bot

I have made a working 2048 game and a bot to play 2048.

The game works like a normal 2048 game, except there are no fancy animations because the bot runs too fast for the animations to look cool.

Activate the bot in the bot config tab. There are three options:

  1. Random Moves: The bot chooses random moves until the game is over.

  2. Random Bot: Random move simluation strategy. That is, for every starting move it simulates 30 games up to 60 moves in which it plays random moves and uses the starting move that has the best result.

  3. Minimax search: For the current state, goes through every possible move and for those moves goes through every possible tile spawn location up to a max depth of 5 because the branching factor is very high. Uses heuristics for number of empty tiles, monotonicity (row either increasing or decreasing), large tiles near the edge, smoothness (similarities in tile values close together for merge potential), and tiles merged.

I spent a long time working on this project. Unfortunately, none of the bot methods work spectacularly. I might improve upon it in the future by adding better heuristics or using a better algorithm. Comment any suggestions you have!



@MrEconomical delet the children.

DarshanRajpara (16)

I think I've noticed a trend with his repls.....

They're always beautiful, better than I can do, even with python, my favorite language.

LittleNomster (114)

Love it! Could be smoother movements though.

JohnStarrs (23)

I wanna learn html css and js now if you can do cool stuff like this
absolutely amazing

LordoftheString (3)

this is so cool! nice job on the graphics. just like the real game!

KellerWorthen (41)

this is the best version of 2048 i have seen

ReubenBakas (0)

i take that back
it took long but it did

mwilki7 (1133)

what on earth is that lookup table

MrEconomical (2293)

@mwilki7 the shifts table is precomuting all the rows so I can shift each row in O(1) to make the bot very fast and the scores lookup table is the score based on heuristics for every single possible row so I can score the current board layout very fast

mwilki7 (1133)

I see, that makes sense
im just shocked at the size because im a lazy programmer