Matching Algoritm

Get help using Construct 2

Post » Thu Apr 23, 2015 3:35 pm

Hello! I'm working on a Diamond Dash type matching algorithm. Right now it works 95% of the time, all of the time (lol).

The idea behind it is simple. Once a game piece is placed, check the game pieces around it, starting at 0 degrees working its way counter clockwise. Once a match is found, check pieces around that game piece. If no matches are found, retrace steps and check pieces that have not been checked.

Please take a look at it, feel free to use the algorithm and comment any bugs that are rendering it unuseful 5% of the time!

Thnx!

https://www.dropbox.com/s/9q0eadso2xvv3 ... .capx?dl=1

PS: Cannot attach capx to post for some reason...
B
6
S
2
Posts: 18
Reputation: 536

Post » Thu Apr 23, 2015 4:27 pm

How about this?
https://copy.com/nVYGNNmNa3zVGOlg

btw, you exchanging of pieces is flawed, since it is possible to overlap multiple empties.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu Apr 23, 2015 11:28 pm

Thanks mindfaQ. I haven't been able to see your capx because i need to download the beta version of C2, but could you please elaborate on how my exchanging of pieces is flawed? It would be a great help for the future!
B
6
S
2
Posts: 18
Reputation: 536

Post » Thu Apr 23, 2015 11:33 pm

isn't it easier to store every piece in an 2d-array and when its replaced u check its neighbour cells or do I missunderstand it?
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Thu Apr 23, 2015 11:36 pm

probably. there are many ways pf going about this. i know of at least 3 ways.
B
6
S
2
Posts: 18
Reputation: 536

Post » Fri Apr 24, 2015 4:40 am

When you drop a piece, you check for overlapping empty sprites. Since those have a collision size of 10 x 10 boxes and your game piece a collision box for 42 x 42 pixels, there are places, where your gamepiece overlaps multiple empty sprites. In that case, two or even three of the empty sprites are destroyed and only one is created -> you end up with empty spaces in your grid.
After your overlapping condition, you could add "pick nearest empty" or (even better) compare two values: distance(gamepiece.x, gamepiece.y, empty.x, empty.y) < gamepiece.width - empty.width * 2
This way you will end up with only one empty picked, and in the case of the distance expression, you also get some snapping back, when the game piece is in the middle of two empty pieces and when it is not sure if the user wanted the piece to drop on empty 1 or empty 2.

And here the checking function I would have done (although I would probably input the piece information into an array and iterate over that):
Image
It's a bit simpler imo, you have a queue of pieces to check (starting with the exchanged piece), this looks at the pieces around it and finds pieces that have not been looked at (queued) before (status = 0); those pieces are added to the queue. When the queue is empty, you've found all adjacent pieces of the same color.
Of course you can pack these 4 events of looking around into each direction into a for loop, but while it saves space in the event sheet, I don't think it will be faster at execution, since calculations won't get less.
Last edited by mindfaQ on Fri Apr 24, 2015 4:49 am, edited 2 times in total.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Apr 24, 2015 4:42 am

thanks man. you're awesome!
B
6
S
2
Posts: 18
Reputation: 536

Post » Fri Apr 24, 2015 4:48 am

I added some further explainations.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Mon Apr 27, 2015 1:32 pm

My approach for matching puzzle swap that utilize flood-fill
ImageImage
B
102
S
46
G
22
Posts: 772
Reputation: 21,593

Post » Mon Apr 27, 2015 4:31 pm

thanks man. ill check it out.
B
6
S
2
Posts: 18
Reputation: 536

Next

Return to How do I....?

Who is online

Users browsing this forum: justifun and 9 guests