Questions tagged [2048]

2048 is an open source tile-based puzzle game. Questions with this tag should be either about implementing the game or implementing solving strategies. Ask on https://gamedev.stackexchange.com/ if it's a specific game development issue. Ask on https://gaming.stackexchange.com/ if it is about playing the game.

2048
Filter by
Sorted by
Tagged with
2070 votes
14 answers
1.0m views

What is the optimal algorithm for the game 2048?

I have recently stumbled upon the game 2048. You merge similar tiles by moving them in any of the four directions to make "bigger" tiles. After each move, a new tile appears at random empty position ...
nitish712's user avatar
  • 19.6k
17 votes
2 answers
5k views

Python: Justifying NumPy array

Please I am a bit new to Python and it has been nice, I could comment that python is very sexy till I needed to shift content of a 4x4 matrix which I want to use in building a 2048 game demo of the ...
Akins Nazri's user avatar
4 votes
1 answer
1k views

2048 game - AI can't score more that 256 average

I'm trying to implement AI for 2048 with MiniMax and Alpha-Beta pruning, based on a snake strategy (see this paper), which seems to be the best as a single heuristics. Unfortunately, AI makes 256 in ...
Keeper's user avatar
  • 457
4 votes
0 answers
206 views

What is the optimal algorithm for the Bicoloured 2048 game?

I made a new variant of the famous 2048 game. In this variant there are two types of tiles (2 and 3) that need to be merged separately. This makes the game considerably harder than the original. I was ...
Dmitry Kamenetsky's user avatar
3 votes
2 answers
229 views

2048 : Strange behaviour of reduceRight in map with lodash/fp

The following code is the beginning of an attempt to make my version of 2048 (the game) using lodash-fp. I'm used to regular lodash, but this is my first contact with the fp flavor. It implements the ...
Nicolas Le Thierry d'Ennequin's user avatar
3 votes
2 answers
229 views

2048 change check method java

I am trying to write a 2048 game in java. I am trying to make it so it checks if the board has been changed, and if it was changed it will add to the move counter and add a number to the board. ...
CRT TV's user avatar
  • 185
2 votes
3 answers
664 views

How can I implement the merge functionality for 2048

I am trying to implement the game 2048 using JavaScript. I am using a two-dimensional array to represent the board. For each row, it is represented using an array of integers. Here I am focused on ...
Joji's user avatar
  • 5,203
2 votes
1 answer
94 views

TensorFlow neural network as an API?

I am in the process of writing an AI for the game 2048. At the moment, I can pull the game state from the browser and send moves to the game, but I don't know how to integrate that with TensorFlow. ...
Neywiny's user avatar
  • 81
1 vote
2 answers
66 views

Creating an array of objects in javascript, then fetching properties

so I'm trying to recreate 2048 in javascript right now and having some trouble. Basically, my idea was to create the grid as an array of 16 objects that take coordinates and a boolean variable of ...
tag00's user avatar
  • 13
1 vote
3 answers
822 views

CSS, divs moving around on content update

I'm trying to code 2048 using HTML/ CSS/ JS I got the layout of the grid using this Html: <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" ...
Majd's user avatar
  • 348
1 vote
2 answers
761 views

Filling 2D Array with 2 values from a random list (2048 Game)

I am trying to recreate the 2048 game and I have hit a brick wall and am stumped. I have made my grid with a 2d array and it seems to be working okay. I have then made a method to store an list of ...
CosmicCowboy's user avatar
1 vote
1 answer
630 views

2048 game in Python

As a beginner I started to code a 2048 game. I made the matrix and filled it with 0's. Then I wanted to write a function which loops trough the whole matrix and find all the 0 values. Then save the ...
D.Tomi's user avatar
  • 71
1 vote
1 answer
34 views

Why when I run my code the panel opens but it never reaches the actionPerformed function

panel view of my 2048 gameI am trying to make the 2048 game. I made the terminal version to check my game logic and everything seems to be working. Now I added a GameFrame and GamePanel class. My aim ...
Maria's user avatar
  • 11
1 vote
2 answers
167 views

Can't pass 1d array into a method because there is a 2d array parameter

I can't pass the 1d array into the method because there is a 2d array parameter. I can't remove the 2d array parameter because my 2048 game board runs on that 2d array board subject. Is there a ...
TechUltimateHD's user avatar
1 vote
1 answer
2k views

UCB formula for monte carlo tree search when score is between 0 and n

I'm implementing an AI that plays 2048 using monte carlo tree search. According to wikipedia https://en.wikipedia.org/wiki/Monte_Carlo_tree_search and all other sources that I have checked in the ...
joan capell's user avatar
1 vote
1 answer
157 views

failed to resolve some method of tkinter

I am creating 2048 game on python with tkinter but I have a issue I don't know what is wrong in left, right, up and down methods created in PageOne class. In another class (StartPage), bind function ...
Fabio Citti's user avatar
1 vote
1 answer
73 views

How to run a loop in the background while running other code in python

I have a python script that (somewhat) plays 2048. The way it works is it presses left, detects if there has been a change or not, and if there hasn't (AKA the move didn't work) it presses up, if that ...
TotallyNotTeo's user avatar
1 vote
2 answers
372 views

error while converting java.awt.geom.Rectangle2D to javafx.geometry.Rectangle2D

Rectangle2D bounds =g.getFontMetrics().getStringBounds(message,g); i got this error how can i solve it ! Type mismatch: cannot convert from java.awt.geom.Rectangle2D to javafx.geometry.Rectangle2D
Sa_IS's user avatar
  • 33
1 vote
0 answers
181 views

2048 merge methods assistance

I'm trying to figure out how to work the shift right,up,down,left methods. I feel like my solution should work so idk if I'm calling it wrong or something. Main import java.util.Random; import java....
scuttles's user avatar
1 vote
1 answer
2k views

Making a java 2048 game, upon sliding it goes through the loop more times than it should and hits tests/alters numbers already altered

So I have a solid slide function, the problem is (which is very hard to explain!) it goes through all the possibilities including spaces in the 2d array that have already been added together: say ...
oldaccawd11311's user avatar
1 vote
2 answers
738 views

Issue assigning two self variables to each other in python

I'm working on building a 2048 game and trying to build a stopping condition. But facing some issues with two variables. The idea I tried was simple - stop the execution when two matrix values (one ...
codegooner's user avatar
1 vote
0 answers
343 views

python 2048 implementation

I was reading a code of 2048 game and came across the following snippet def up(game): print("up") # return matrix after shifting up game=transpose(game) game,done=cover_up(game) ...
Sagar Moghe's user avatar
1 vote
2 answers
747 views

undo operation implementation in 2048 game

I've implemented 2048 game in C++, github link : 2048 For implementing undo operation, i.e. going back to previous state of game, I'm maintaining a matrix for previous board configuration, but if I'm ...
Mandeep Singh's user avatar
1 vote
0 answers
2k views

2048 AI: Expectimax better than Minimax?

I am building a 2048 AI, and it is leading to a rather peculiar observation (peculiar enough to me). The optimizations are not up to the mark right now (coupled with the fact that the code is written ...
Tanmay Garg's user avatar
1 vote
1 answer
1k views

How to applied alpha-beta pruning in implementing 2048 AI agent with minimax algorithm?

I'm developing an AI for 2048, and am about to apply minimax algorithm. However, the search tree of 2048 is actually like a Expectiminimax tree without Min role. I wonder if I don't have Min role, ...
Elliot Li's user avatar
  • 452
0 votes
2 answers
159 views

C in 2048,problems with moving [duplicate]

I am making 2048 game in C and I need help. Moves are made by pressing W,A,S,D keys e.g. W is for moving up, S for down. However, after every letter you have to press enter to accept it. How can I ...
Daniel Kaduk's user avatar
0 votes
2 answers
144 views

Is it good practice to put if statements in main() or inside functions to respond to user input?

I'm writing a 2048 program for the terminal for university. To play the game my program needs to either shift left, right, up, or down. So I have two options: Write a function that takes the ...
t020608's user avatar
  • 343
0 votes
2 answers
215 views

2048 game on 1d list - why it works for some tests and not others?

Trying to implement the 2048 game in python, starting with a function that merges a 1d list . My code works for all but one test see below. I believe this is due to the code not processing consecutive ...
JoeP's user avatar
  • 55
0 votes
1 answer
1k views

How do I resolve this? TypeError: main.<locals>.<lambda>() missing 1 required positional argument: 'gamepanel'

I'm using tkinter to make 2048 game gui, I created this function control_game I want to have it such that anytime I click these keys (up, down, left, right) on my keyboard the control_game function ...
densteam-io's user avatar
0 votes
1 answer
309 views

Try to make 2048 game in React. Data in the state is mutated when it should not have been

This is my code repo https://github.com/540376482yzb/2048game_react This is my live demo https://objective-fermat-0343a3.netlify.com/ The current state of the game only goes left and right. However ...
ZhouBing Yang's user avatar
0 votes
3 answers
214 views

sliding array values

I'm trying to recreate the game 2048 in vb and I'm struggling with figuring out how to get the values in an array to slide together. I'm trying to do this in a single dimensional array before I task ...
Michael Rennison's user avatar
0 votes
1 answer
94 views

Making a "2048 solitaire game" with F#: Creating a fsi file, fs file and fsx file

In your solution, you are to represent a board with its pieces as a list of pieces, where each piece has a color and a position. This is captured by the following type abbreviations: type pos = int * ...
Hoodwinked's user avatar
0 votes
1 answer
93 views

Printing 2048 board in python with spacing with standard libraries

I want to print a 2048 board with proper spacing. I was able to reach till here. ╔═══╤═══╤═══╤═══╗ ║ 1 │ 2 │ 3 │ 4 ║ ╟───┼───┼───┼───╢ ║ 3 │ 2 │ 4 │ 5 ║ ╟───┼───┼───┼───╢ ║ 1 │ 1 │ 4 │ 2 ║ ╟───┼───┼───...
Random_Pythoneer59's user avatar
0 votes
0 answers
27 views

The up/down keys are triggering an "unrefined" error

I am tring to make an ai to complete the 2048 game. I have the game made, but I'm on the first step of adding the ai in JavaScript and I've run into a problem. The game looks OK before anything is ...
code tec's user avatar
0 votes
1 answer
84 views

How to structure a non-periodic task in pyRTOS?

I am working on a Realtime Computing project using pyRTOS to create the tasks and applying the RTOS concepts. My project is a version of the game 2048 to run on a physical touchboard. As part of the ...
marqueslua's user avatar
0 votes
1 answer
203 views

Making a "2048 solitaire game" with F#: creating the functions for the implementation file (.fs file)

I am tasked with creating a version of the 2048 game. This version is on a 3x3 field, and uses colors (instead of numbers). The functions that I will need have already been given to me. Among these, I ...
Hoodwinked's user avatar
0 votes
0 answers
564 views

Creating 2048 GAME in java using only the console

I hope i find someone to help finish the game ( 2048 )., since I'm in a computing programmer for only 2 month it's been difficult for me to do it. The basis of this game that the user can choose what ...
Fadilox Almany's user avatar
0 votes
0 answers
59 views

What is an alternative method to replace grayscale value?

I am trying to make a bot to read the data from the game, 2048, and decide the best movement. I have preset the grayscale value for every number. But unfortunately, the grayscale value for an empty ...
smljiaooo's user avatar
0 votes
0 answers
143 views

Making 2048 game faster

Is there a way to make my 2048 game run faster? I made a setting called high speed mode so that if moves were made really fast I would just skip the spawning, combining and moving animations, however ...
babayaga007's user avatar
0 votes
0 answers
32 views

Why does my 2048-style game stop working after 128? [duplicate]

For fun, I'm making a 2048-style combine-and-display program. Every outer loop, it adds a 2 to the 0-index of an integer array list. In an inner for-loop, it checks to see if the value of the index is ...
Quintis555's user avatar
0 votes
0 answers
186 views

2048 game movement assistance java

I started making this extremely simple 2048 game, without graphics and stuff (only array), and made the board : import java.util.*; public class GameBoard { String [][] GameBoard; void justprint(...
Kian Shah's user avatar
0 votes
0 answers
143 views

Only moving DOWN when plays 2048 automatically with Selenium

I am trying to play 2048 automatically with Selenium as directed in Automate the Boring Stuff. But every move is DOWN no matter what argument I send to send_keys(). Here is the code: from selenium....
Ryan-Rguo's user avatar
0 votes
1 answer
839 views

How to merge/shift rows/columns up or down basis 2048 game

I need some help creating 2 functions push_up and push_down (think 2048 game), I've managed to create functions that would push the values left and right and then sum them together if they are of ...
Ninja01 's user avatar
0 votes
0 answers
48 views

Hi, im making 2048 using python and a graphics library and need some assistance

i'm using python and need to use an array to make 2048. i am trying to figure out how to make the mechanism to create the moving of numbers in an array to remove the zero's and add two of the same ...
Max Neath's user avatar
0 votes
0 answers
95 views

2048 Game - Trigger key events in the console?

I'm trying to trigger key events in the Chrome console but nothing seems to work. I want to trigger any of the arrow keys programmatically (for an experiment). I've tried this (among many other ...
gatzkerob's user avatar
  • 877
0 votes
0 answers
78 views

Modifying interface with key interactions in javafx

I'm trying to code a 2048 game using JavaFX and I'm facing a problem. @Override public void start(Stage primaryStage){ primaryStage.setResizable(false); Scene scene = new Scene(firstContent())...
Bruh's user avatar
  • 147
0 votes
1 answer
2k views

A function about checking whether the game is over in 2048 game

I took some days to code 2048 game. And now I made most of the functions but one, testing whether the game is over. To code this game, my idea is to merge the same numbers first with the function up(...
Theodore Tang's user avatar
0 votes
0 answers
156 views

C - Function to see if a game reached the "GameOver" point. (2048 copy)

I'm programing a 2048 game copy in C. But I can't figure out the game over function. I've this struct: typedef struct struct_BLOCO { int valor; int cor; int x, y; } BLOCO; And this is ...
NeoFahrenheit's user avatar
0 votes
0 answers
37 views

Bug when fields move downwards at 2048

i created my first 2048 game with JS. And i still have a bug which makes me crazy! When i once move up, every downmove some fields wont move down. Can anybody help? // #### Bewegungen und Matches ...
Marc Hahn's user avatar
0 votes
1 answer
199 views

NetLogo: 2048 bot optimisation

I am trying to make a Netlogo simulation of a 2048 game. I have implemented three heuristic functions determined by weight parameters and want to use behaviour space to run simulations and check what ...
Gloria's user avatar
  • 3