Live data from Hacker News

2048 Solver

github.com

21–30 of 41 posts

Re: 2048 Solver

#21

Hello everyone, I am currently taking a course in Artificial Intelligence and have been planning to implement the A* algorithm towards 2048. But seeing here that people believe that this isnt a "true" A* implementation, would the hackerNews community be interested in an actual working Javascript implementation of multiple AI methods? (i.e. having a dropdown selector for the method to use and implementation via a butt…

Yes, that'd be kind of cool.

Re: 2048 Solver

#22
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…

My first reaction was that Monte Carlo would be the way to go.

Seems like a great application for Monte Carlo tree search.

Re: 2048 Solver

#23
post #20

Question for AI people: is 2048 and interesting game to try different algorithms on and if so, why?

I'm not really an AI person, but I think it's interesting, yes:

Each individual decision is simple (choose from 4 directions), but the overall strategy is difficult (the arrival of each new piece has a random element).

The game tree[0] is awkward to draw in full, because of this random element. If we can draw it out well enough to analyse it, we can come up with a perfect play algorithm that wins as often as possible. Tic-tac-toe is 'solved' in this sense: we always know what the best play is.

Since 2048 remains unsolved (for now), AI algorithms which simplify and try to approximate that process come into play. As long as nobody has come up with perfect play, it's still interesting to see who can come up with the best play.

2048 is relatively simple game to remain unsolved, so it's nice and accessible to apply algorithms to (and still relevant to do so).

[0]https://en.wikipedia.org/wiki/Game_tree

Re: 2048 Solver

#25
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 choosing. I wrote a small dumb Python webserver using the Flask microframework:

https://github.com/loisaidasam/2048/blob/master/py/webserver...

And it simply returns a random direction:

https://github.com/loisaidasam/2048/blob/master/py/game.py

This can be adapted obviously for whatever logic you choose. The reason I forked this version and not a totally server-side one (which would be better for performance obviously) is that you can actually watch the moves this one makes as it chooses them, which makes it kinda fun.

Enjoy!

Re: 2048 Solver

#26
post #24

I'm afraid the implementation of the game here has a bug which makes it much easier than the original. http://pastebin.com/VwwGCYYy

I will fix that, thanks for the info

Re: 2048 Solver

#27

Hello everyone, I am currently taking a course in Artificial Intelligence and have been planning to implement the A* algorithm towards 2048. But seeing here that people believe that this isnt a "true" A* implementation, would the hackerNews community be interested in an actual working Javascript implementation of multiple AI methods? (i.e. having a dropdown selector for the method to use and implementation via a butt…

This would be cool. Please don't just post the code though... Have a working, interactive 2048 game that runs your algorithm so I can watch it without doing anything. Not everyone here is a coding guy...

Re: 2048 Solver

#29
post #20

Question for AI people: is 2048 and interesting game to try different algorithms on and if so, why?

Follow up question:

I'd rather not say how many hours I sank into 2048 before I could beat it. But, it's interesting to recall the little rules, preferences and maybe even aesthetics that I picked up along the way and the order they came in. HN was all 2048 AI that day so I was noticing how I was learning the game.

An early strategic step was deciding to play in only 3 directions, with one direction as the least favorite, potentially dangerous direction. If my high square is on the bottom right with the second highest to its left then up is not allowed and left is dangerous because it could put a 2 in the high square's place.

If I hadn't been "recording" the process at the time I would have missed what sent me down the '3 directions' path. I started by deciding to have the high square in the corner. Then I decided I wanted to lock the whole row as a way of keeping it there.

Another more subtle reason reason was that this simplified the rules of the game and let me learn a few other strategies. Moving in all directions was too complicated.

An early strategy that i tried and abandoned was trying to getting high squares to one another. Instead I concentrated my attention on the squares in the locked row that stay in place fore a while and started worrying about doubling only those.

This was another way of simplifying the game. It meant that my attention could be focused on certain spaces, not on everything. For example, I want to double square D2. Line D is locked I need to get D2's value to C2. It's easiest to do this if outside of line D all values are lower than D2.

Interesting stuff. makes me want to learn a new games just to watch me learn it.

So the question: How doable is it to watch humans develop learn and represent them?

And a second one: is there a '_why's shoes' equivalent for AI?

Re: 2048 Solver

#30
I must say that the game itself is implemented in the wrong way! The AI here is just playing another much simpler game here.
Post reply on HN