How do I Detect a Match Prediction in a Match 3 Game ?

0 favourites
From the Asset Store
Match 3 Game Gems
$6 USD
40% off
Match 3 Game Gem Pixel Art work for any kind of Match Games.
  • Hi rafaeltrigo

    thank you for the vote of confidence, and challenge accepted.

    I will change this tomorrow, and let you know.

  • I decided to give it a try as well...

    I started with your code, and figured it would be fastest using an array so ended up doing what made sense to me - but haven't put many comments in yet so it might be hard to follow.

    The board can be any size, just change the Columns and Rows global variables and everything else will adapt. I fixed a number of issues - now it wont let you make a move until all other blocks have stopped moving, if you make an invalid move it will reverse it, as long as you hold down on a block you can move it back or another direction (you have to let go to finalize the move), multi touch will only allow one move at a time...

    after a move has completed it makes an array of all possible moves and then sorts them by the number of blocks that will be removed. This will prioritize a move of two sets of 3 over one of 5 in a row. This could be changed by making the scoring work differently, but this is a start... it shows the recommended move as soon as it has calculated it for testing purposes, or you can click the Hint button.

    https://www.rieperts.com/games/forum/Match3.c3p

  • AllanR

    WOW, you practically made a new game, thanks for the help, I will see your code with more detail for I learn new things!

    I think that kind of games, like Candy Crush, where each level is different, should be a lot of work to program it ! thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • found a couple of bugs... with moving blocks too quickly (starting a tween while one is still running), and suggestions when there are no moves and after an invalid move. I will post an updated version later today, maybe with a few more comments to help explain what is going on as well.

  • Thanks AllanR

    Would be very interesting if we be able to show the player all the pieces that will be part of the match like this !

  • I can take a look at that, shouldn't be too hard but have to change a couple things in the way it looks for matches (and want to optimize the code a bit).

  • Hi,

    I changed to code of the match 3 template to also allow a suggestion by pressing the "S" button in the interface. It holds a rather easy solution by checking if the top left and bottom let or top right and bottom right jewel are the same of the center jewel.

    A function with a pretty straight forward logic you can easily adapt.

    The guys at scirra just approved the version on the store. Feel free to pick it up if you still need it. I copied the code of the function below in case you're interested

    cheers!

    * On function 'CheckSuggestion'

    | Local number suggestionfound‎ = 0

    | Local number curcol‎ = 0

    | Local number currow‎ = 0

    | Local string curtype‎ =

    | Local string typeTL‎ =

    | Local string typeTR‎ =

    | Local string typeBR‎ =

    | Local string typeBL‎ =

    ----+ (no conditions)

    -----> suggestion: Clear

    ----+ System: For "columnloop" from 0 to NUM_COLS-1

    --------+ System: For "rowloop" from 0 to NUM_ROWS-1

    // once a suggestion is found, stop searching for it

    ------------+ System: suggestionfound = 0

    ----------------+ (no conditions)

    -----------------> System: Set curcol to LoopIndex("columnloop")

    -----------------> System: Set currow to LoopIndex("rowloop")

    -----------------> System: Set curtype to Functions.GetJewelTypeForCoordinate( currow, curcol )

    -----------------> System: Set typeBL to Functions.GetJewelTypeForCoordinate( currow+1, curcol-1 )

    -----------------> System: Set typeBR to Functions.GetJewelTypeForCoordinate( currow+1, curcol+1 )

    -----------------> System: Set typeTL to Functions.GetJewelTypeForCoordinate( currow-1, curcol-1 )

    -----------------> System: Set typeTR to Functions.GetJewelTypeForCoordinate( currow-1, curcol+1 )

    // powerups don't count for suggestions

    --------------------+ System: curtype ≠ "cross_powerup"

    ------------------------+ System: curtype = typeTL

    ------------------------+ System: curtype = typeBL

    -------------------------> System: Set suggestionfound to 1

    // add jewels to dictionary for highlighting

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow & jewels.column = curcol

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow-1 & jewels.column = curcol-1

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow+1 & jewels.column = curcol-1

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    ------------------------+ System: curtype = typeTR

    ------------------------+ System: curtype = typeBR

    -------------------------> System: Set suggestionfound to 1

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow & jewels.column = curcol

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow-1 & jewels.column = curcol+1

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    ----------------------------+ System: Pick jewels by evaluating jewels.row = currow+1 & jewels.column = curcol+1

    -----------------------------> suggestion: Add key str(jewels.UID) with value 0

    // Possible extension : also check TR + TL or BL + BR

    ------------------------+ (no conditions)

    -------------------------> (no actions)

    // Finally also return the number of values in the explode dictionary, so expressions that call this function can check if there are any matches in the entire grid

    ----+ (no conditions)

    -----> Functions: Set return value suggestion.KeyCount

  • rafaeltrigo

    Well, that got rather complicated! I cleaned up my code a fair bit, but it is probably difficult to follow...

    It will find the best move and show it after a delay of 3 seconds. It now weights the moves to favour ones lower down the board - because that gives a better chance of starting a chain reaction.

    The animation on the hint isn't nearly as nice as in candy crush, but that would take a lot more work!

    https://www.rieperts.com/games/forum/Match3Hints.c3p

  • AllanR

    That was a Great Job , some people think match 3 games are easy to code , but is not , Thanks a Lot

  • rafaeltrigo

    Well, that got rather complicated! I cleaned up my code a fair bit, but it is probably difficult to follow...

    It will find the best move and show it after a delay of 3 seconds. It now weights the moves to favour ones lower down the board - because that gives a better chance of starting a chain reaction.

    The animation on the hint isn't nearly as nice as in candy crush, but that would take a lot more work!

    https://www.rieperts.com/games/forum/Match3Hints.c3p

    A great example. Do you think it can be optimized for Tap blast like game?

  • in a tap blast type game, you don't have to worry about checking all the directions each piece can move. So, the logic should be easier... you also don't have to look for chain reactions. Doing hints would work pretty much the same.

    So, yes, it can be done.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)