Live data from Hacker News

2048 Solver

github.com

31–40 of 41 posts

Re: 2048 Solver

#31
post #7

I could be wrong here, but from my reading of the source this doesn't look like an A* search algorithm. For starters, the search space is nondeterministic, and since you can only explore in one direction, you're not really performing a search space exploration as much as choosing a direction and going with it. Secondly, the implementation doesn't perform the combination of current state score and proposed state score…

Show us your better solution! Thanks!

Re: 2048 Solver

#32
post #6

Interesting work. I'd be curious to see this algorithm applied to the original game. Since this is a re-implementation of the game in Java, it may be solving a completely different game.

And indeed it is. A much easier game, unfortunately.

Re: 2048 Solver

#33
Given the number of straight 2048 implementations out there now that appear to have slightly different rules making the game easier, perhaps it would be a great idea for the definitive 2048 rules to be published.

Re: 2048 Solver

#34
post #7

I could be wrong here, but from my reading of the source this doesn't look like an A* search algorithm. For starters, the search space is nondeterministic, and since you can only explore in one direction, you're not really performing a search space exploration as much as choosing a direction and going with it. Secondly, the implementation doesn't perform the combination of current state score and proposed state score…

Show us your better solution! Thanks!

https://news.ycombinator.com/item?id=7475031

Re: 2048 Solver

#35

I forked the main 2048 repo and modified it so that you can write your own "brain" for it: https://github.com/loisaidasam/2048 Essentially it communicates via an API to a webserver where you write your "brain" logic and respond to the API requests with which move to choose next: https://github.com/loisaidasam/2048/blob/master/js/autonomou... Since it's over web, you can write your webserver in the language of your ch…

This is the most efficient version I was able to get: https://news.ycombinator.com/item?id=7475031

Re: 2048 Solver

#36

Given the number of straight 2048 implementations out there now that appear to have slightly different rules making the game easier, perhaps it would be a great idea for the definitive 2048 rules to be published.

The definitive 2048 rules can be gathered by decomposing the original source, bugs and all.

Re: 2048 Solver

#37
post #7

I could be wrong here, but from my reading of the source this doesn't look like an A* search algorithm. For starters, the search space is nondeterministic, and since you can only explore in one direction, you're not really performing a search space exploration as much as choosing a direction and going with it. Secondly, the implementation doesn't perform the combination of current state score and proposed state score…

Check my AI for 2048 https://news.ycombinator.com/item?id=7474909

Only reach 8192, but with the game implemented in the right way :)

Re: 2048 Solver

#38
Let me start by saying that I'm glad you ported this game to Java, it certainly increases the reach of the game and the number of people who can hack on it. You're also a really organized Java programmer, which makes it a lot easier for other people to build on what you made.

With that said, this Java implementation needs a lot of performance improvement. I made some trivial changes on it and benchmarked it at a significant speed boost, I'll send you my revisions on GitHub so you can take a look. Also, as another commenter mentioned, this isn't true A*, but good work nonetheless.

Here's a simple performance improvement: Java's ArrayList is just a wrapped array with two fields:

  private transient Object[] elementData;
  private int size;
When you initialize it, it initializes elementData to a null array of size of 10. When you put the 11th thing into the list, it creates a new array of size 15 (in general, a 50% increase), and copies references from the old array. This means that in your search, a board with 11 or more open tiles will trigger a resize. This is easily prevented by initializing the list with

  new ArrayList  (15)
Bam! One optional parameter, 9% runtime improvement. As the performance gets optimized you can search larger trees in less time.

Re: 2048 Solver

#40

Let me start by saying that I'm glad you ported this game to Java, it certainly increases the reach of the game and the number of people who can hack on it. You're also a really organized Java programmer, which makes it a lot easier for other people to build on what you made. With that said, this Java implementation needs a lot of performance improvement. I made some trivial changes on it and benchmarked it at a sign…

Thanks for your help! I will try it out :)
Post reply on HN