Category Archives: Uncategorized

2 Card Game

Consider this game: I write two distinct numbers on two separate cards, and allow you to pick one. You can look at the number written on the card, and you can decide if you want to switch cards. Your objective is to get the card with the higher value written on it. Is there a strategy that lets you win with >50% success?

Surprisingly, the answer is yes! Consider the following strategy: We sample randomly from any distribution X, say the standard normal distribution. We compare this value x with the value on the card, and change cards whenever our sampled value is higher than the value on the card.

So what’s the chance of winning with this strategy? If we let the two numbers on the two cards be a and b, with a < b, we can consider a few cases for where our sampled x ends up. If x > b, then no matter which card we picked, we would switch, and the chance of success is 50%. Likewise, if x < a, then we would always keep the card we picked, so the chance of success is still 50%.

If however, the value x we picked happened to be between the two values a and b, then we would always switch to the larger card, so the chance of success is 100%. This gives us a total winning chance of \frac{1}{2} + \frac{1}{2}Pr( a < X < b ).

An Advanced Guide to 2048 – The Slow Crawl Towards 16384 Part 3 – Recovery Plays and Technical plays

In parts 1 and 2, we discussed several techniques to avoid a scenario where things can go awry. In part 3, we will discuss several recovery plays to retrieve a perfect board state.

Largest tile not in corner

One of the most common problems occurs when the largest tiles isn’t in the corner after combining several tiles. When there is 1 large tile, the resolution is quite simple:

2048.38

With 1 large tile, first fill the bottom row (not complete necessary), then manipulate the board position such that the tiles all above the largest tile are all distinct, while there are several identical tiles in the column that you want to move into (see left picture below):

2048.39 2048.40

Shifting up after that easily resolves the problem (hope that the new tile doesn’t spawn in the corner again)

This is easy with 1 large tile, and relatively easy with 2 large tiles. The process for 2 large tiles is the same:

2048.35

The ease of which this can be done is mostly up to luck. An important thing to note is that if the board state becomes too messy and the tiles are not in the right position, you have to first resolve some of the larger tiles before continuing.

2048.36 2048.37

A more complex position is the one as follows, when one of the two largest tiles is not even in the correct row. This sometimes occurs after the “3 rows filled forced to swipe up” situation.

2048.41

In this situation, the first objective should be to bring both tiles to the second row, after which careful manipulation to ensure that the entire second row is filled with distinct tiles and for there to be several tiles that can easily combine with each other (the 8-4-4 in the top row and the 2-2 in the bottom row)

2048.43

There is a certain degree of luck to this. After obtaining such a board state, it is simply up to luck as to whether the 2s will spawn right below your 2 large tiles:

2048.42

Slotting tiles into a favourable position

It is usually the case that combining two tiles immediately brings no advantage to the player. Before combining tiles, look carefully to see if any advantage can be obtained in delaying such a process.

This is an extremely common position, there is no harm in trying to maneuver the 64 into a position that can be slotted on top of the 64 that will be created when the two 32s combine.

2048.44

First swipe left a few times to see if you can luck out and get no tiles to spawn on top of the fourth column. If you’re lucky combining the two 32s will not result in a small tile spawning in the position that will block the 64. This process helps to resolve large tiles in the second row that are a hindrance.

2048.45 2048.49

The following is another common occurrence, since we want to avoid combining the 64 with the two 32s which will result in a 1 space scenario (refer to part 2), we will be pushing the tiles down. However, there is no harm in swiping right a few times so that the tile that will be inserted will be the larger 8 as compared to a 2.

2048.47 2048.48

Here is a better example: swiping a few times to the right from the left picture gives the right one:

2048.53 2048.51

And the right structure collapses into a somewhat better position with the larger tile in the second row. This is a very small optimisation but it is very important.

2048.54 2048.52

Dealing with the 3 row death

3 row death is something that should be avoided at all cost. Most of your efforts during the game should be spent focusing on avoiding this problem. If it does happen, pray that the new tile spawns in a favourable position. I originally believed that there were some benefits to swiping left and right when the smallest tile spawns unfavourably but I now believe that to be untrue.

2048.55

The most forgiving spawn position is the one furthest from your largest tile:

2048.58 2048.59

As you can see, there are minimal problems when this happens. In this situation, there is almost no loss of space.

The second most forgiving position is the one where it spawns below your largest tile. It might be slightly counter intuitive as to why this is the case. The ideal board state is not the one where your largest tiles is in the corner, but the one where your large tiles are all next to each other. When the 2 spawns in below your largest tile in the corner, most of your board position is preserved:

2048.56 2048.57

As it can be seen, there are clearly some problems when this happens, but the problems are minimal. The player can still relatively easily create a 128 in the second row, combine the 128 in the third row with it, and create the 4096 tile.

In the worst scenario, the 2 spawning below disrupts the positioning of all tiles:

2048.60 2048.61

As you can see, there are huge but not insurmountable problems. The player now has to build 128s in the top two rows to be able to resolve the situation.

Sometimes though, there is some value in shifting the bottom row:

In situations such as the below, when there are more than 1 large tiles above the newly spawned tile, the formation is usually heavily disrupted if the player swipes down.

2048.612048.62

This position is not irrecoverable, with some luck, a relatively stable position can be acquired, taking into account the tip a scrolls up.

2048.66

However, as can be seen, this requires a certain degree of luck, and even the recovered position is still not trivial to play.

If the numbers are larger and recovery is nigh impossible, moves in the bottom row become necessary. In the above case, swiping right is the ideal solution as it preserves the connectivity between the 128 and the 256.

2048.64 2048.65

 

In the most ideal scenario, the second tile spawns in the least intrusive space right below the 2048. Do note that the player usually gets several attempts to right the position as the smaller tiles can usually be combined once.

Unfortunately, this move is usually a gamble. With smaller tiles, players should spare some thought to consider if moving the bottom tile is worth it.

2048.632048.67

Usually, 1 of the 3 possible secondary spawn positions will do absolutely nothing for you(left), and another will completely ruin your game (right position when the two new tiles are not next to each other). In this case, it happens that the right scenario is actually better than the original position as only a 128 has to be created in a 2×4 space. The recovery play in this end position will be similar to the one discussed earlier, columns 1 and 3 will be locked while column 2 will have to have similar moving tiles, allowing for the two 2048s to be combined.

There are some interesting variations, and the preservation of consecutive tiles being next to each other is extremely important. Much effort should be spent analysing these situations. In these situations, a simple wrong decision can invalidate hours of gameplay. Surely a minute or two’s worth of time looking at the individual possibilities is worth it.

There are many interesting approaches to the game. My first inspiration to attempt the 16384 came from a video on youtube. A certain Maarten Baert wrote a script that achieved a 16384 tile and a 8192 tile in the same board using a very novel strategy. Looking at certain things the bot does may help to improve your game especially in more complex board positions when moving in all directions is a necessity.

2048 is an extremely intricate game with many interesting optimisations. Persevere with the game, and with some luck, you could reach 16384 too.

success?

Part 1: Introduction + Basic techniques
Part 2: More Advanced techniques
Part 3: Recovery plays + technical plays

An Advanced Guide to 2048 – The Slow Crawl Towards 16384 Part 2 – More Advanced Plays

Earlier on in part 1, we discussed merging tiles towards the middle of the chain as opposed to the end. The insertion of tiles in this situation is extremely important. There are two main considerations.

Untitled4

The first consideration was discussed in the part 1, where the existence of spaces after merging creates slight problems as it introduces the possibility of a “2” spawning in an undesirable position

Oh crapTime to go flip a table

It is of course essential to minimise the frequency of this occurrence to ensure that this undesirable position does not happen often.

Even better!Building towards the centre

The second consideration is significantly more interesting. When combining tiles, it’s actually extremely important to consider not only if a space will exist in the column after combining but the number of spaces that will exist. We will seek to demonstrate why 1 space remaining after the collapse is worse than a situation where 2 or more spaces remain after the collapse.

Building towards the centre

This collapses into:

blurgh

While not immediately obvious, this one space position is terrible because of the ridiculous difficulty of continuously being able to put tiles into that corner position. Oftentimes something like this will be the position after a few turns:

uncomfortable

This position is possibly very deadly when the tiles are all larger. In such a situation, it may not be possible to combine the 32 tile with other tiles in the second row to create a 256 tile (in the hypothetically deadly situation the tiles should all be larger) If this is the case, you’re forced to combine tiles into the 16, but the existence of the 32 may not be resolved and will constantly act as a hindrance to remove space. If given a choice, I would avoid a scenario where combining would yield one empty square.

Another reason to not have the 1 empty space, is that the recovery play for the 3 large tile scenario is ridiculously impossible. Having the 2 spawn in the corner ensures the loss of 1 space.

This brings us to one of the most interesting decisions on the road to 16384. In the following position, what should be the player’s aim?

what do now

Do you aim to make a 1024 in the second row and keep the 512 in the bottom row? Is it better to take the easier route of making a 512 in the second row and hope things work out with the single empty space created after?

I once believed that creating the harder 1024 in the 3×4 space is better. After some discussion with other players, I have come to realise that this decision is based on how good you are at manipulating objects into the single space. There is a few tips in part 3 as to how to deal with the 1 space position, but with more optimised play, I believe that taking not taking the risk of making the 1024 and making the simpler 512 in the corner is simpler.

Do note that the player can at any time switch to building a 1024 in the second space if the position becomes difficult to recover from. If the second row involves a large 512 tile in the second or third space, attempting to build a 1024 instead of the 512 may be the slightly better option. It is interesting to note that when there is a large tile in the middle of the second row, creating a smaller tile at the side is oftentimes the same difficulty as creating a larger tile in the middle.

The same idea applies when building in the second row in the below situation; is it better to build a 64 or a 32 in the last two rows? However, in this case I believe that building the 64 is better, as the resultant 1 space position is incredibly risky to play.

same idea as before

Structure

Other than the ordering of large tiles which we’ve been talking about, there are two slightly more subtle nuances to the structure of your currently board position. There are two things to take note of:

Prioritising the locking of rows

This was covered briefly in part 1. To ensure that no space is lost by the unfortunate appearance of smaller tiles in the following situation:

Oh crap Time to go flip a table

In situations like the one below, the priority of the player should be to fill up the gap in the bottom row. There is a certain technique to this. While constantly moving in the “safe” directions in this case being left and down, you need to maximise the number of moves that will be available to you so as to allow for the maximum number of chances of spawning a small tile in the desired column. As you can see in the left picture, swiping left will preserve the two 2s in the second column that can be combined next while swiping down will result in no additional moves if a 2 spawns in the top left corner or the square right above the 512.

2048.23 2048.25

In the right picture, it should be clear that swiping down is the desired option, so as to fill up the gap.

Do note that this logic extends to the second column. It is highly desirable to lock in the second column as well. In the below picture, while combining the two 32s is tempting, the player should prioritise filling up the second row. Swiping down as many times as possible is the right move here. Of course, this is given that the player is trying to create a large tile in the second row.

2048.26

 

Prioritising the locking of columns

After the locking of rows comes the locking of columns. In a sense, the other major killer in this game is the “3 row death” where no valid moves are available but the “forbidden” move.

anrigbueiorugbqergqerg

Again we discussed certain ways to avoid this in part 1, in part 2 we’ll discuss another strategy. Other than locking rows to ensure no loss of space, columns have to be locked too so as to minimise the chances of the 3 row death. The below position is quite classic:

2048.27

Swiping left is one of the better moves here, as it creates a 8 and a 2 on top, ensuring that the 3 row death is impossible.

An interesting point to note is that this goes against most of what we’ve discussed previously. If we take into account the advice before, it should seem that trying to move down is better so as to keep all the larger tiles in the corner and avoid having to swipe right. It is inevitable that a position like the one below will occur after swiping left.

2048.28

The position does indeed seem rather undesirable as the largest tile in the top two rows, the 8 is in the middle and not in the corner, and space is lost. However, play in the top two rows is rather unique. It is incredibly easy to make a 32 in the top two rows, even if the largest tiles are not at the side and players should aim to constantly make 32s and 16s to insert into the second row. It is important to keep Tip 4 in mind.

2048.30Untitled33

When aiming to build a 32 in the top two rows, you need to be clear as to building which way gives you the most space. While trying to build an 8 in the top right seems like a good idea, a better line of play would be to build a 4 and a 2 to be combined. This allows for a situation where only a 4 is required to be created as opposed to an 8.

Being Flexible

It’s natural to be strongly against and never think about moving in the forbidden direction. However, it is oftentimes the case that moving in the forbidden direction is useful, especially if all important columns are locked.

2048.33

In this situation, all that is necessary is for the two 64s to be combined and the tiles can cascade to form the 4096 tile. However, the most natural thing to try and do would be to combine the 8 and the 4 tile in the 3rd row. An elegant solution exists by swiping up. The 8 displaces the 4 and the second row will shift to the right when swiping right, allowing for the two 64s to be combined as seen below:

2048.34

Another interesting scenario occurs when trying to fill up a row. In the bottom scenario, swiping up as opposed to left avoids the 1/5 chance of a small tile spawning unfavourably. The player can swipe up and down until the bottom row is filled with no worries.

2048.32

Part 1: Introduction + Basic techniques
Part 2: More Advanced techniques
Part 3: Recovery plays + technical plays

An Advanced Guide to 2048 – The Slow Crawl Towards 16384

2014 saw the rise of two games, 2048 and flappy bird, both notably having simple mechanics while requiring skill to execute. The casual player had no trouble getting into them, and the high skill cap along with the natural competitiveness of these games propelled them into outspread popularity. We’ll be looking at the arguably more intricate game, 2048 today.

2048 was created in February 2014 by Gabriele Cirulli, based off the original game threes by Sirvo. The free, slightly less complex 2048 rose into popularity shortly after it’s creation, while the prettier, original version did not see much success.

The game is rather simple, there is a 4×4 grid with numerous tiles with powers of two on them. The player can swipe in each of the four standard directions to move all the tiles in that direction. When tiles with the same value collide, they merge to form a tile with double the original value. Each turn, a new tile spawns at a random location. The original version only allowed for a maximum value of 2048 to be attained; the game automatically ends when the player attains a tile with the number 2048 on it. Shortly after it’s release, this cap was removed, and players could attain tiles with larger values.

So onto the game!

Before we discuss the strategy of the game, we need to look at the motivation behind these strategic maneuvers. First, we’ll look at the theoretical maximum value attainable:

Suppose instead of a 4×4 grid, we only had a 1×2 grid. What would be the largest value we can get playing in this grid? Let’s just ignore the fact that 2048 allows for 4s to spawn randomly and consider the scenario where only 2s can spawn. Quite clearly, in a 1×2 grid, we can only attain a maximum value of 4. Why can’t we get 8 you ask? Well, quite simple, to get an 8, we’ll need two 4s. And it’s impossible to get a 4 in a single square. Likewise, the maximum value you can attain in a 1×3 grid is 8, as we’ve already shown that it’s impossible to get a 8 in a 1×2 grid to combine with our first 8 to get 16. By induction, we can quite clearly see that the maximum possible value attainable in a 4×4 grid is 216 = 65536. Of course, since the game allows for 4s to spawn, it is also possible, albeit extremely unlikely to achieve 217 = 131072. A clearer explanation is available on the numberphile youtube channel: video link

What’s the point of this you ask? It’s important to understand what the game is about, what the restrictions are, so that we can devise a strategy that allows for the creation of larger tiles. The game of 2048 is largely a game about space. A 4×4 grid is not a terribly large amount of space for us to create our ultimate goal, the 16384 tile. A 4×4 grid gives us 16 units of space, while the 16384 tile requires log2 16384 = 14 units of space, leaving us essentially 2 units of space to spare.

Basic Strategy:

An inevitable conclusion reached by anyone playing this game is that keeping the largest number in the corner is a necessary part of the winning strategy. Why is this so? In a sense, the game requires you to build a long chain of consecutive powers of 2 to reach the next power, and one of the best ways to allow for these consecutive powers of two to easily be combined is for the consecutive powers of two to be adjacent to one another.

A nice long chain combining into a 4096 block1 space wasted with the 2 in the corner

<These board states are generated at this version of 2048 which allows users to generate any board state they want. Many examples in this post are impossible.>

It’s quite intuitive as to why the largest square should be in the corner. If the largest square is not in the corner, a space is essentially wasted, and a larger number has to be created in a smaller space. In the above two examples, you can see that a 32 has to be made in the rightmost 2 columns when there’s a 2 in the way, while only a 16 has to be made in the rightmost 2 columns when the 2 is not present.

It happens to be the case that it is possible to produce a chain of consecutive powers of 2 that covers the entire board with the largest tile not in the corner, however, it is extremely difficult to manipulate the board if this is the case.

This brings us to

Tip 1:

Try and keep the largest tile in a corner, as well as keep the next largest tiles beside it.

Once we’ve established the importance of “space”, we can begin to talk about other strategies:

Losing space

One of the more common ways of losing space is to have the game spawn a new tile in a space right beside your largest tile:

1st row lost space second row lost space

In both cases, a minimum of 1 space is lost. The board state on the right is slightly more complicated, you can either consider it as 1 lost space, and build towards a 256 tile (by looking at the chain in the second row upwards, aim to convert the “4” into a 32), or consider it 2 lost spaces and build a 128 tile downwards. Difficulty wise, these two options should be almost identical.

How did it come about that we were forced to lose this space? It is not uncommon that a completely filled column/row ceases to be filled when two tiles are combined. In the process, we may be forced to make a move that loses a space as we can see in the situation below:

Look a chain!Oh crap

Swiping down is the lesser of two evils:

Time to go flip a table

It is usually the case that you will be able to swipe in neutral directions (in this case being left or up) a few times before being forced to swipe down. Doing so is strongly advisable.

It may not be immediately apparent, but it is in the player’s best interest to avoid having rows simultaneously having relatively large numbers and empty squares. One of the ways to resolve this is:

Tip 2:

While creating larger tiles, try and merge tiles towards the center of the chain, and not towards the ends. Doing so will reduce the likelihood of being forced to swipe in an undesirable direction as the number of vacant spaces created when combining tiles is minimised.

Look a chain!

As opposed to the above, try building either of the following:

Building towards the centreEven better!

This is partly where experience plays a part. It is important to know what you’re comfortable with making with any amount of space. If you’re comfortable with making 256s in 3 rows, go ahead and use the merging option on the left, if you’re more comfortable with making 512s in 3 rows, go ahead and use the superior option on the right.

With more experience, other reasons to build as above will become clear. It is fundamentally much easier to build a larger number in the center of a row/column as opposed to building it at the ends. Oftentimes, attempting to build a 256/512 in a corner slot ends up creating unnecessarily large tiles in the second row that can become problematic.

Tip 3:

Prioritising the combination of awkward tiles

don't do dumb things

Similar idea to tip 2. In the above situation, it is far better to combine the 64s in the second row, than the two in the first column.

yayarghhhh

Look at the awkward 64 in the picture on the right. In the above scenario, the 64 could very likely be moved to the bottom row too, but an unlucky spawn could ruin any plans for that to happen. The safer more stable option is to combine laterally.

Tip 4:

Always think about the concept of space; try and combine things in the right direction.

Space.1

Suppose now you’re playing this game, and you’re trying to create a 128 in the second column in the corner to combine with the 128 already present in the first column. The most intuitive way of completing this is to build a 16 on top of the 16 in the second column, and then build a 32.

However, this isn’t the best way to do things, especially at the higher numbers when space is extremely valuable.

Space saved!Successssss

A slight improvement would be to merge the two tiles above the 64, so as to give you one more space to build towards the bottom. As we can see, this one unit of space allows you the leniency to build smaller tiles in the second column. Before, we had to build 32s. Now, we only have to build a 16. While this play may seem rather inconsequential, it is important when it comes to the later parts of the game when every single bit of space is valuable.

Tip 5:

There isn’t much to this one, but one of the most frustrating things when playing this game is to have the game completely screw you over by having a 2 spawn in a position that forces you to swipe in your “forbidden” direction. This happens when there are 3 complete columns with no adjacent similar tiles:

anrigbueiorugbqergqerg

I don’t have a good way to avoid this. The only tip I have is to resist your urge to combine similar tiles, and take a good look at the situation before making your move:

Untitled15

Moving left in this situation will only give you a 20% chance of randomly creating huge problems for yourself. Control the urge, move down and then left.

phew yay

Some general tips:

Getting to 16384 will take a long long time, I took about 3 hours of gameplay, much patience will be needed, take breaks if necessary and make sure you don’t lose concentration above all else.

This was:
Part 1: Introduction + Basic techniques

Move on to:
Part 2: More Advanced techniques
Part 3: Recovery plays + technical plays