# Match-three puzzle games algorithm

## Recommended Posts

Hello everybody, I need little help I am trying to make games like 'matching three object'  in (9x9) grid but I dont know what is the algorithm and how to implement the algorithm. please give me some resource, code, algorithms anything that can help me.

Thanks.

##### Share on other sites

I'm sure there is something generic out there. What I would do is to set some rules and check them. First have each object have an id that defines its type, then do a check if the selected 3 are matching their type, if they are then continue to check their distance from one another, if the distance is (next-right, next-left, next-up, next-down, next-diagonal-top-right, next-diagonal-top-left, next-diagonal-bottom-right,next-diagonal-bottom-left) then continue to check the next element of the 3 if all these checks return true, then you have a match 3.

Maybe its too much work like that I don't know, its what I would think of to do, if nothing else came up.

##### Share on other sites

Hi, I have some experience in making match-3 games.

There can be lot of "levels" for match-3 - from simple one to very complex. One example: simple top down falling vs. complex falling to sides. You are also free to think of different tasks for your user.

Best tutorial I have seen for simple match-3 game is at RayWenderlich.com: http://www.raywenderlich.com/66877/how-to-make-a-game-like-candy-crush-part-1. After reading this tutorial we made simple native Android/iOS match-3 in modern flat design. Now, we are working on much more complex one in Phaser (screenshot) with lot of tasks for users, including battles, diagonal falls, lot of animations... So I recommend: start simple and then enhance your work.

##### Share on other sites

Hi, I have some experience in making match-3 games.

There can be lot of "levels" for match-3 - from simple one to very complex. One example: simple top down falling vs. complex falling to sides. You are also free to think of different tasks for your user.

Best tutorial I have seen for simple match-3 game is at RayWenderlich.com: http://www.raywenderlich.com/66877/how-to-make-a-game-like-candy-crush-part-1. After reading this tutorial we made simple native Android/iOS match-3 in modern flat design. Now, we are working on much more complex one in Phaser (screenshot) with lot of tasks for users, including battles, diagonal falls, lot of animations... So I recommend: start simple and then enhance your work.

I have seen this tut but It seems to me quite complex can you please clear the steps needed to implement the match three algorithm.

##### Share on other sites

I have seen this tut but It seems to me quite complex can you please clear the steps needed to implement the match three algorithm.

There is nothing like single match-3 algorithm. Match-3 game is made from set of small pieces like: "allow user to make swap", "detect chains", "remove chains" ... for the most simple version the core is what MichaelD wrote in his answer: "detect rows and colums". There is no special algorithm for this - just take cell and check if there are at least 2 adjacent cells of the same type to form at least three.

The tutorial at RayWenderlich.com has two parts. In second part there is image with sequence of events in the top (http://www.raywenderlich.com/66915/how-to-make-a-game-like-candy-crush-part-2) - you can take it as template and implement it by yourself step by step. But again, I recommend whole tutorial. There are some iOS specific things you can skip, but I do not know about any better one. Everything is nicely explained in detail and they are not building any advanced match-3, but the basic one.

##### Share on other sites

Hello everybody, I need little help I am trying to make games like 'matching three object'  in (9x9) grid but I dont know what is the algorithm and how to implement the algorithm. please give me some resource, code, algorithms anything that can help me.

Thanks.

well you dont give to much details about how the game is going to work so i'm going to guess here,plus above comments.

if you use a grid an approach is to use a bidimensional array to manage the game logic. any change combos is calculted by the array and then 'displayed' on screen by sprites.