Live data from Hacker News

2048 AI

ov3y.github.io

71–80 of 197 posts

Re: 2048 AI

#71
post #58

It's like watching War Games - http://www.youtube.com/watch?v=NHWjlCaIrQo

A book with a vaguely similar idea, I recommend over the movie.

Colossus by Dennis Feltham Jones

( don't read the wikipedia entry as it contains spoilers ( whole plot ) )

Re: 2048 AI

#72
post #33

It gets so close! http://puu.sh/7rrD6.png I find it frustrating to watch it hit (where I have not managed to get to) where you have one block 128, 256, 512, and a 1024. Moving around only makes it harder to join things together. I am rather convinced this game is more by luck than actual good-play.

Interesting, mine beat the game: http://puu.sh/7rwqf.png

Re: 2048 AI

#73

I'm running some trials here and keeping track of the results with this AI. I'll edit this when I have the data to provide the information. Something that occurred to me is that "score" and "winning" can have different optimizations. Score is based upon combining blocks, where as winning is based upon reaching the 2048 block. This means the game can be optimzed in two different ways: 1) To maximize score, wherein you…

If you have only a single 2048 tile in the end, and arrived to that by only combining the minimum number of required tiles, then your score will be 10*2048. If you think backwards, you'll get 2048 for the last tile, before that you need to get twice 1024 for the previous two, and so on until the level of 4's, which is the first one at which you get scores. This assumes only twos appear on the board.

Re: 2048 AI

#75
post #30
post #27

What are the rules for new tile placement? Is it deterministic, random, or adversarial?

Random location (uniform). 90% chance of a 2, 10% chance of a 4. This actually made it hard to model the computer move in the search.

When playing, it seemed like a 50% chance the new tile would be placed in exactly the spot or two that I didn't want it, even if there were 8+ open spaces.

Re: 2048 AI

#76
Here's the routine I've used to win multiple times in a row:

1. "tumbler" until 128 can move to the upper left corner (up right down left, repeat)

2. The highest number on the board is always in the upper left. Make the top row descend left to right.

3. Before combining values on the top row, keep hitting up until one of the lower rows will not combine from a left.

4. Often, the slot you are filling (eg, top right or one below top right) will have a two. Alternate pressing left and right until a two appears, allowing you to combine

5. Keep the second row locked as soon as possible with unique values ASCENDING left to right. This way you can use up, left and right without moving the slot you are filling on the far left of the second row.

6. Never fill the top three rows such that a left or right cannot be used. You will be forced to use a down, messing up the top row.

There are a few other pattern recognition tricks that you'll pick up to aid in filling a slot for higher values. Other misc tips:

* try to keep high number squares close together, and merge up to the top row as soon as possible. Otherwise, they will just close off a slot

* You may get a 2 trapped on the top row blocked by a higher value below it. Unfreeze the second row by combining squares & hope that a two appears in the new opening

* only 2's or 4's will appear. They (always?) appear in the space left behind by the previous movement

Re: 2048 AI

#77

Is this game always guaranteed to be winnable, or is it like Solitaire?

Quick idea for empirically determining "winnability": implement the complement AI for computer moves [which are (i) position and (ii) value i.e. 2 or 4], perform a decent number of runs with depth limits for I.D. set much bigger, then look at the results. Also, I haven't looked at the code but I don't think looking into improved heuristics can hurt.

edit: I used 'look' 3 times in the last 20 words, what's wrong with me

Re: 2048 AI

#78

Hahah, I knew this was coming sooner or later. Thanks! Great job! EDIT: This AI is a better player than me.

I don't know if you've experienced it yourself or have heard other reports of it, but after playing your game for a few hours last night I've been experiencing a 2048-flavored "tetris effect" all day today. My brain keeps on trying to identify "like things" to collapse together; pretty wild.

Re: 2048 AI

#79
post #43
post #38

The AI implements minimax using alpha-beta pruning. Minimax assumes that the game/computer which the AI is playing against is playing adversarially - i.e. that the computer will insert the new tile that's the worst possible tile for the player/AI to receive. But that's not actually what the game is doing. Instead, new tiles are inserted randomly. As a result, minimax probably isn't the best approach here. I think som…

Heh. If you look in the code you'll see a big commented out chunk where I tried randomly sampling computer moves to get sort of an 'expected value' for the opposition's move. Empirically, it performed worse. I think this is for the same reason that all minimax algos assume optimal play by the opponent: if you assume optimal and they play less than so, it can only work in your favor. However I think there's some truth…

I suspect that the best objective function would be "maximize the time until I lose" which is closer to avoiding the worst case scenario than it is to performing best in the average case scenario.
Post reply on HN