Share your repls and programming experiences

← Back to all posts
2048 Game and Bot
h
MrEconomical

2048 Game and Bot

Hello!
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!

Voters
PYer
leemlam
GaussInTheHauss
DinaMerali
BubbleNugget
ArthurWu
Fleqs
VictorLi11
LittleNomster
LukeJensen03
Comments
hotnewtop
[deleted]

MrEconomical

@nulll fixed

[deleted]

@MrEconomical delet the children.
yes.

Rileygamer21

This reminds me of code bullet's AI https://www.youtube.com/watch?v=1g1HCYTX3Rg

DarshanRajpara

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

Love it! Could be smoother movements though.

JohnStarrs

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

LordoftheString

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

KellerWorthen

this is the best version of 2048 i have seen

MrEconomical

@KellerWorthen no fancy animations tho

ReubenBakas

i take that back
it took long but it did

ReubenBakas

doesnt work

TylerBernardo

This is amazing!

MrYeeter

cooool

mwilki7

what on earth is that lookup table

MrEconomical

@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

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