Hello

I am making a piece of software that reads a board of difference pieces and then puts them into an array for management. I am at the point where I have got a rectangle around the whole board and am researching what the quickest and most effective way to locate each piece and store it in an array would be. The way in which I find the pieces is through searching a region for a small BMP for each different piece. The whole board it 6x12 and it has 7 different types of pieces.

Method 1:
Make a small rectangle for each piece position and then scan then scan them one by one - it would only be scanning a very small area, but would be doing it (6x12) 72 times each time the board had to be refreshed.

Method 2:
Scan 6 or 12 times for each column or row picking each piece as it goes along and storing it in an array. This would scan a much bigger area but only have to do it either 6 or 12 times each time it had to be refreshed.

Does anyone have any insight on which was would be the best? or even better have another method that would be even more effective?

Thank you

The methods you describe are exactly the same in effort, so it doesn't matter which you use. Personally, I'd go with the first one.

What I'd look for is the smallest area I can search that indicates a different piece rather than trying to match the entire piece image. Depending on how long a search takes, you might consider using parallel tasks.

You might also consider building a quad tree and use that to find and match the images.

I have been having a look at this quad tree stuff and it seems like if done properly, it could be a really good way in getting this to run fast. I am struggling to find some good sources on how it all really works though, do you know of any tutorials/guides on how to setup a quad tree and use it?

Thanks again!

I googled this,c# quad tree tutorial, and came up with this link, and that's just the first one.

Perhaps I'm not understanding your design properly, but I thimk you are making way to difficult.

You have 7 types of pieces that are represented by an image.

You make a 6 x 12 grid out comprised of multiple copies of the original 7 pieces.

Why not make a Piece Class that includes: Image, Piece Type, and Coordinates?

This is simple enough to manage. No need for image comparisons as piece stores it's identity.

But then I'm probably simplifying this to much.

I do have a piece class, but when a piece is used it changes into another random piece so the indentity cannot be constant, there must be a way to rescan the board and pick up the new pieces

couldn't you make the different types of pieces properties of the same class? then instead of randomely changing the piece just change the properties of it so it looks different. a typed array or a database could store the different sets of properties. as for finding them you could use the `controls` collection and `linq` which allows very specific searches.

You