Trying to hack match 3.
rickierich

I am trying to hack match 3. I really need to follow the logic of how you make matches. 

It does not appear, immediately, that how you did your matching. I need to find the point where you do your matches at the lowest level. 

I need to be able to match objects based on their category. The pseudo-code is simple enough, I thought about all these complicated ways, but I noticed the easiest way would be to just add a field to the items which represent their category and instead of checking if the indexes matched. check the group id(no) and see if that matched.

I assumed when you did your match you simple checked index of the two objects. 

If It was java, you would simply override the equals function and add a field groupid. Working from someone else's code it is not immediately obvious to me how you have done the equivalent and whether you have placed the match as one method. Assuming you have one boolean method to see if items are the same can you show me where it is.

Follow the logic of others is difficult. 

All 12 Comments
rickierich

I believe the answer is in this tail-recursive function.

 var createMatch = function(axis, squareI, match)
        {
            var square2 = !columnsLocked[squareI.col+axis.x] && board[squareI.col+axis.x] && board[squareI.col+axis.x][squareI.row+axis.y] && board[squareI.col+axis.x][squareI.row+axis.y].getBehavior("Match3Item");
            squareI && square2 && squareI.type == square2.type && !square2.moving && match.push(square2.owner) && createMatch(axis, square2, match);
        };

The == (equivalence) test needs to be removed and done with a seperate function. following your logic. I simply have to find where you type everything and put my category IDs instead.

rickierich

var nullMatch = function (array, item, item2)
        {
            if (item != item2)
                return; // No need unless both previous 2 match
            for (var i = 0; i < array.length; i++)
            {
                array[i].normal = array[i].normal == item ? null : array[i].normal;
            }
        };

 

this needs to be changed.

rickierich

more hacking than I thought!

rickierich

This is turning into a case study. This probably should not be changed. I suspect type as you have used needs to stay as it is, because you might generate the board with it.

 this.changeItemType = function(x, y, type)
    {
        var typeExists = false;
        for(var i=0; i<this._items.length; i++)
        {
            if(this._items[i].normal == type)
            {
                typeExists = true;
                break;
            }
        }
        if(!typeExists)
        {
            wade.error("Type does not exist! Cannot change type of match3 item");
            return false;
        }
        wade.removeSceneObject(board[x][y]);
        var newSquare = createSquare(type, type, false, x, y);
        board[x][y] = newSquare;
        wade.addSceneObject(newSquare, true);

        check.push(newSquare);
        update();
    };

Gio

> Follow the logic of others is difficult. 

I know what you mean but we do try to make it as easy as possible for you :)

You don't need to change any code, just handle the onMatch event. In there you can check your object types, or do whatever you want to do. Like all other Wade events, at the end you return true if you want to stop the event or handle it yourself (i.e. no match is made); or you return false to say that you don't want to stop the event and let Wade process it (i.e. a match is found and is resolved in the normal way).

You can add an onMatch function to your scene object, or you can use the Match3 editor - click the last tab on the right that says Events and then onMatch.

Like all other event handlers, the onMatch function is passed a data object containing everything you need - console.log(data) to look at it.

I hope this helps

 

 

rickierich

I do not think that will help in my case. 

I am doing something like this.

smile is an emoji, heart is an emoji, sad face is an emoji.

L is a letter, B is a letter, M is a letter.

So when the user has puts L B and M in line that would be a match as they are all letters.

if they put smile heart and sad face that would be a match as they are all emojis.

onMatch and the match3 app would not put them as a match to call onMatch function. Hence I need to hack the code. What I want to do is just add a field to the json setup called category: and then just place them in categories. then the place were the matches are made have it use a boolean function that checks the categories are a match. 

I think that description is clear.

rickierich

I believe the best way is to add a function called matchTest to match3item and move this function there.

var createMatch = function(axis, squareI, match)
        {
            var square2 = !columnsLocked[squareI.col+axis.x] && board[squareI.col+axis.x] && board[squareI.col+axis.x][squareI.row+axis.y] && board[squareI.col+axis.x][squareI.row+axis.y].getBehavior("Match3Item");
            squareI && square2 && squareI.type == square2.type && !square2.moving && match.push(square2.owner) && createMatch(axis, square2, match);
        };

 

is there anywhere else critical to consider. 

var nullMatch = function (array, item, item2)
        {
            if (item != item2)
                return; // No need unless both previous 2 match
            for (var i = 0; i < array.length; i++)
            {
                array[i].normal = array[i].normal == item ? null : array[i].normal;
            }
        };

this is another critical area.

rickierich

my approach will be to put == checking on items in the matchitems behaviour.

this means categoryID needs to be stored in a the -_items array. in the WSC and the create square and the array storing the squares needs to make sure it is recorded. 

Then I will change the == to use .equals. 

 

 this.changeItemType = function(x, y, type)
    {
        var typeExists = false;
        for(var i=0; i<this._items.length; i++)
        {
            if(this._items[i].normal == type)
            {
                typeExists = true;
                break;
            }
        }
        if(!typeExists)
        {
            wade.error("Type does not exist! Cannot change type of match3 item");
            return false;
        }
        wade.removeSceneObject(board[x][y]);
        //need to send category
        var newSquare = createSquare(type, type, false, x, y);
        board[x][y] = newSquare;
        wade.addSceneObject(newSquare, true);

        check.push(newSquare);
        update();
    };

There appears to be code not called, or have I missunderstood html5. 

Gio

Hi again, sorry for the late reply (I had a few days off).

I think in your case, the simplest solution (again, without changing the core Match3 code), would be to just use the same type for all the items of the same type. For example, instead of having "smile", "heart" and "sad face" as separate items, use only "smile".

Then after an item is added to the scene (for example in Match3Item.onAddToScene), change the graphics:

var r = Math.random();
if (r < 1/3)
{
    this.owner.getSprite().setImageFile('sadFace.png');
}
else if (r < 2/3)
{
    this.owner.getSprite().setImageFile('heart.png');
}

Does that make sense?

rickierich

Yes it does, make a lot of sense, do not know why I did not think of that. 

I have taken it another way, cause I think the abstraction is cleaner to have a category.

rickierich

got it done, had to butcher the code, but it was a better approach to add a category. I will clean it up and post it, for so you can understand what I did maybe you can build on it for the next update of the game.

Gio

That would be interesting to see, please do post it when you get a chance.

Thanks

Post a reply
Add Attachment
Submit Reply
Login to Reply