Categories
News

Two days experiment

Well.. about week and a half ago a friend of mine sent me a link to a web-based game named 2048. It’s mathematical puzzle based on multiplication of twos. After quick investigation we found that the game is based on another idea of Threes! app. Very attractive game where you should combine different numbers to get threes – 3, 6, 12, etc. You’re playing on the field of 4×4 cells and can move numbers on this field in four directions, but once you made movement all cells start moving in that direction. Only similar numbers in 2048 and only those that gives threes as result (in Threes!). After each movement one more random number appears on the field (one of two minimum numbers). Well, it’s a bit tricky to put numbers in the right sequence.

After a short discussion with Grig we decided to create a game for iOS based on power of a number. We selected 2 because it’s easily to calculate than threes and more hard than simply adding 1+2+3, etc. Create one more game wasn’t a key, the key was in speed.

We limited our time to 2 days of complete development – coding, design, localization, marketing materials for AppStore (well… in the beginning we limit this time to two hours :) but something went wrong that day).

We splitted work on the app. Grig started with UI, and I worked on an algorithm for movements and collisions for similar numbers. In the base it was simple. Depends on the direction of a movement start from 0x0 point of the field or from point 4×4 and move backward on field. Get the number and move it to a next cell on the field if it’s empty. If next cell is a similar number then multiply and put result into the cell.

In reality we found that gameplay could be different depends on how algorithm handles multiply collisions. For example:

+---+---+---+---+
| 2 | 2 | 2 | 2 |
+---+---+---+---+

This combination could be represented as:

 +---+---+---+---+
 | 4 | 4 |   |   |
 +---+---+---+---+

or

+---+---+---+---+
 | 8 |   |   |   |
 +---+---+---+---+

This doesn’t make a game easier or harder, but this changing gameplay process. For example, on field of

 +---+---+---+---+
 | 2 | 2 | 2 | 2 |
 +---+---+---+---+
 | 4 |   |   |   |
 +---+---+---+---+
 | 8 |   |   |   |
 +---+---+---+---+
 | 16|   |   |   |
 +---+---+---+---+

Two behaviors above will have following effects:

When the algorithm process only one collision at a time:

                 Move to left                Move to bottom            Move to bottom x 2
 +---+---+---+---+           +---+---+---+---+           +---+---+---+---+           +---+---+---+---+
 | 4 | 4 |   |   |           | 4 | 4 |   |   |           |   |   |   |   |           |   |   |   |   |
 +---+---+---+---+           +---+---+---+---+           +---+---+---+---+           +---+---+---+---+
 | 4 |   |   |   |           | 4 |   |   |   |           | 8 |   |   |   |           |   |   |   |   |
 +---+---+---+---+   --->    +---+---+---+---+   --->    +---+---+---+---+   --->    +---+---+---+---+
 | 8 |   |   |   |          | 8 |   |   |   |           | 8 |   |   |   |           |   |   |   |   |
 +---+---+---+---+           +---+---+---+---+           +---+---+---+---+           +---+---+---+---+
 | 16|   |   |   |           | 16|   |   |   |           | 16| 4 |   |   |           | 32| 4 |   |   |
 +---+---+---+---+           +---+---+---+---+           +---+---+---+---+           +---+---+---+---+

When all similar number in the row combined to one:

 
                 Move to left                
 +---+---+---+---+           +---+---+---+---+
 | 4 | 4 |   |   |           | 8 |   |   |   |
 +---+---+---+---+           +---+---+---+---+
 | 4 |   |   |   |           | 4 |   |   |   |
 +---+---+---+---+   --->    +---+---+---+---+
 | 8 |   |   |   |           | 8 |   |   |   |
 +---+---+---+---+           +---+---+---+---+
 | 16|   |   |   |           | 16|   |   |   |
 +---+---+---+---+           +---+---+---+---+

If new random numbers are not appearing then second result is obviously worse, but when new numbers appearing every movement result isn’t predictable easy and second result could be better just because in this case you got one new number on the field only, in contradiction to the first result where you need two movements for result of 8 in the top cell and get 3 new number on the field.

Same decision we’ve made on order of pairs collision.

On movement to the left

+---+---+---+---+            +---+---+---+---+       +---+---+---+---+ 
| 4 | 4 | 4 |   |  should be | 8 | 4 |   |   |   or  | 4 | 8 |   |   | ?
+---+---+---+---+            +---+---+---+---+       +---+---+---+---+

Finally, I’ve stop with algorithm that processes one collision on similar numbers in a time. Complete investigation and coding took about 5 hours.

While I worked on the algorithm, Grig has created UI, interactions and animations, the next day he committed final version. In a day X, then we’ve merge our code we got a problem :) I’ve created the algorithm that works with Matrix of multidimensional NSArray (4×4) and Grig create a linear NSArray with offset. So, I was forced to rewrite part that processing cells completely, because in multidimensional array I was able to use comparison 0 < index of cell < elements.count to limit number movements, but in a linear array I have to identify borders of the rowor column manually. This work took 2 more hours.

When I’ve finished we checked an app and that works! Everything was right… well… actually not. We spent about 4 hours on debug and fixes for gameplay, UI and special cases in movements matrix.

Only one thing that left to do is music and sound effects. Music we’ve found on Kevin MacLeod site (incompetech.com). This is CC licensed art and free to use. We spent some time on discussion which music should be used, but stopped on music that I heard previously in old arcade flash game. It’s soft and should be comfortable for most people.

Well… screenshots and AppStore description on two languages were written quick and app submitted for review. Complete time that we’ve spent together is about 19 hours of work and about 4 evenings (we’ve worked on this project outside of an office). This time is less than two work days, and I’d glad that experiment was success.

The game is available in the Apple Appstore for free:
store_AppStore

Leave a Reply

Your email address will not be published. Required fields are marked *