1,105,295 Community Members

Array of rectangles in another rectangle

Member Avatar
Ben Ashton
Newbie Poster
16 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Momerath
Senior Poster
3,827 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 662 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

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.

Member Avatar
Ben Ashton
Newbie Poster
16 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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!

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

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

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

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.

Member Avatar
Ben Ashton
Newbie Poster
16 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

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
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article