Match 3 Gem Movement

So I am in the process of creating a match 3 game for my internship and struggling to find a nice, clean way to get gems to navigate through the grid.

Currently, gems fall vertically perfectly and looks very nice. However as time went on, they wanted “obstacles” such as holes in the grid, to which gems should move around, very much like candy crush.

I can’t seem to find a nice method to go about this, my plan is to use a path finding algorithm that simply navigates each gem down the way until they can no longer. We had something like this before but it causes “overlap” if you want to have gems fall async, rather than 1 column at a time (slows down user experience), so I would need to figure out the criteria that needs to be met before a gem that may cause overlap can move.

Then I thought, surely there is a better damn way of doing this? This seems overly complicated and it shouldn’t be. Does anyone have any ideas? Sources? Techniques? Would appreciate any insight to this.

This is a difficult question depending on what level of complexity you want to achieve, it would be nice if you could provide some more information:

  • Should gems start moving at the same time, when for example a cell frees up and every gem can move one step downwards?
  • Can gems only move along the x and y axis, or also diagonally?

A first idea is to create a tag system to tag cells with “taken/not taken” / “gem exiting left/right/up/down”.
Than you let your gem decide what to do by choosing a behavior.
You could create a list of behaviors that is sorted by priority. A behavior has a method to check whether it is applicable by providing the cell that the gem is on.

Example-Behavior-List (C0 is the cell the gem is currently on):

  • Fall down (cell below C0 has tag “not taken” or “gem exiting down”)
  • Move left (cell left of C0 has tag “not taken” or “gem exiting left”)
  • Move right (cell right of C0 has tag “not taken” or “gem exiting right”)
  • Do not move (always applicable)

You just iterate through the list and check until you reach an applicable behavior.
A gem in movement does not change his behavior until he reaches his goal.