Tuesday, November 5, 2013

Match 3 Game algorithm Part 4 - How to enable the user interaction?

Until now, we manage to come out with a fundamental match 3 game with the matches detection and a deadlock detection. So far so good :)

But the thing is, something is still missing: user interaction. This is the crucial part that lets the players get hooked on the game. The players are required to make some moves to proceed with the games, either through forming more matches, or completing some special missions. (In the case of the candy crush, the missions are forming matches to clear the jelly, or achieving a threshold score with minimum moves, and etc)

Here, the basic user interaction tutorial would be: move the nodes/items, either horizontally or vertically.

At first sight, this is pretty straightforward. In fact, since the each node/item in my match 3 game is coupled with an integer index, it isn't hard to make a rule such that, if the first node touched is a neighbor of the second, both the nodes are exchangeable, and hence we could perform some matching detection algorithm.


For example, the picture shows a matrix of 8x8. At the nodes indexed at 10th, 17th, 18th, 19th and 26th, it is easily observed that, the node of 18th can be only exchanged with its neighbor which has the absolute index difference of 1 or 8. With this understanding, we could conveniently generalize the algorithm...

However, let's consider 1 more case:

Here, the node indexed 15th, despite being able to exchange with the node 7th, 14th, 23rd, it is unable to interact with the node 16th (because they are not directly connected). Therefore, this special case has to be addressed in our algorithm, which is stated in the next statement:

Statement 4:
- Two nodes are exchangeable, provided that their absolute index difference is 1 or 8, AND if one of them is in the column 0th or 7th, the other one is NOT in the column 7th or 0th.

Forgive my poor explanation in the last part. It simply means that, the node in the column 0th cannot be exchanged with the one in the column 7th.

Coming up next: Miscellaneous (Special Combinations)

1 comment:

  1. Did you know that that you can make cash by locking premium areas of your blog or site?
    Simply open an account on AdWorkMedia and add their content locking tool.

    ReplyDelete