# How do I compare different instances positions ?

0 Favourites
• 4 posts
• Hello,

First of all I apologize for my bad english because it is not my native language.

I am doing a board game which is aimed to create shapes with some pawns in the way of "Connect Four".

For example I want to detect when 5 tokens are aligned (like that : imagizer.imageshack.us/a/img910/9062/VS7cEE.jpg).

My problem : I don't know how to compare the positions of multiple instances of a same object. I tried to use families but that was without any success..

Thank you for your help !

PS : Perhaps my question has already been asked on the forum but I did not find an appropriate answer. Anyway I am sorry if the subject has already been posted.

• You could make a "Check system" that would go through all pawns. Since you already know the position (Depending on how you made it of course), you should be able to store the values in an array as variables for each pawn, whatever you prefer.

Board and there indexes

(0,0), (1,0), (2,0)
(0,1), (1,1), (2,1)
(0,2), (1,2), (2,2)
[/code:2zaip23m]

So if you place a pawn on (1,1) you add that to a list.

List:
(1,1)

Then you use this to check surrounding indexes. So if there is a pawn on 0,0 you add that one as well.

List
(1,1)
(0,0)

And you keep doing that until there are no more pawns to be found surrounding the index you are checking. And if the list have 5 elements you know that there are 5 pawns.

However that will ofc not account for them being on a straight line etc. so you will have to make sure that is taken into account as well. And also you have to make sure that those pawns already on the list is not check vs again.

But in theory I think that should solve it.
• Use flood-fill with 8 direction detection as proposed by R0J0:

http://dl.dropbox.com/u/5426011/example ... chain.capx

I use his method for columns puzzle prototype.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• Thanks a lot for your super fast answers ! I am going to try your methods as soon as possible and see if I achieve to fix my problem.

By the way here is an extract of what I tried to do first, just in case there would be a way to make it work with that kind of system by picking the right pawns (even if I think that way won't work..) : imageshack.com/a/img901/8311/4l3GGc.jpg

On that screenshot sBlackPawn is a sprite and fBlacksPawns is a Family, the global number is just here to see if something is detected.