Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
PIEBALDconsult10-Dec-11 8:21
mvePIEBALDconsult10-Dec-11 8:21 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen10-Dec-11 13:16
professionalEddy Vluggen10-Dec-11 13:16 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Addy Tas11-Dec-11 1:49
Addy Tas11-Dec-11 1:49 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen11-Dec-11 12:27
professionalEddy Vluggen11-Dec-11 12:27 
QuestionCall to REST WCF service creating a file instead of string Pin
nitin_ion10-Dec-11 1:09
nitin_ion10-Dec-11 1:09 
AnswerRe: Call to REST WCF service creating a file instead of string Pin
Richard MacCutchan10-Dec-11 2:54
mveRichard MacCutchan10-Dec-11 2:54 
Question8 queens in c# Pin
Member 84662349-Dec-11 21:34
Member 84662349-Dec-11 21:34 
AnswerRe: 8 queens in c# PinPopular
Luc Pattyn10-Dec-11 0:15
sitebuilderLuc Pattyn10-Dec-11 0:15 
Hi,

1.
in general there are many ways to organize things, many bad ways, some good ones, maybe one or several excellent ones. In this instance, your fundamental question is: should there be a Queen class, and if so what would be its role? To solve that question, think about it both ways.

With a full-fledged Queen class, each Queen instance would represent one chess piece, it would know where it is, paint itself, but having 8 Queen instances would not directly help at solving the problem, as they need to know each other's position in order to solve the problem, i.e. the problem is not at the level of the individual Queen.

Without a Queen class, the Board would need to know there are 8 queens, with their positions. It would have to figure out a set of positions that satisfies the requirements, then paint the 32 white and 32 black squares and the 8 queens.

Thirdly, one could opt for a way in the middle; a limited Queen class could take care of painting the symbol, and maybe help in deciding which squares are attacked by it.

And finally, one could even create a Square class, where a board is just a collection of 64 instances of Square, each square knowing where it is and painting itself (and not doing anything else, as board squares are really stupid).

Now it is up to you to choose. All these approaches are valid, one could be simpler than another, and one could be more academic.

2.
Member 8466234 wrote:
I ... get confused when trying to type the code in.


That is indicative of a lack of "design". You should sit down and think about your approach before you start typing anything. Come up with an architecture, don't try and put bricks one on top of another until you happen to have the house you wanted to build. Make a plan first.

3.
On coding style: you have chosen not to have a Square class, which is fine as painting the 64 cells at once isn't hard at all. You did surprise me a lot by having that as a BackgroundPaint though. If the class is Board, then painting itself is a regular Paint IMO, not a background. But it is still OK.

Yhe names you have chosen for identifiers are really confusing; your paint is a Brush, why not call it brush then? your color is the entire Graphics object, so it is NOT a color. If you have a cat, would you call it "Dog"?

Finally your isBlack manipulations seem correct, however I would do it slightly different, probably like so:
graphics.FillRectangle((i+j)%2==0?Brushes.Black:Brushes.Gray), new Rectangle(...));

that would not need a separate variable, but more importantly it would not rely on sequential painting of the cells, each cell now calculates its color on its own, i.e. less error prone without significantly adding to the calculation cost.

4.
You're not the first one to attempt the 8 queens problem. The internet holds hundreds of attempts. There are some articles on the subject here at CodeProject. Did you look at any of them? Are you familiar with the CodeProject search facilities? Did you consider asking Google? You would get a number examples (of different quality levels) that could guide and insipre you.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 14:04
Member 846623410-Dec-11 14:04 
AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 14:29
sitebuilderLuc Pattyn10-Dec-11 14:29 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 15:31
Member 846623410-Dec-11 15:31 
AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 22:10
sitebuilderLuc Pattyn10-Dec-11 22:10 
AnswerRe: 8 queens in c# Pin
PIEBALDconsult10-Dec-11 2:46
mvePIEBALDconsult10-Dec-11 2:46 
QuestionTimezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
devvvy8-Dec-11 17:06
devvvy8-Dec-11 17:06 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
Richard MacCutchan8-Dec-11 22:28
mveRichard MacCutchan8-Dec-11 22:28 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
jschell9-Dec-11 11:23
jschell9-Dec-11 11:23 
QuestionList<T>.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 15:42
Firo Atrum Ventus8-Dec-11 15:42 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
PIEBALDconsult8-Dec-11 16:06
mvePIEBALDconsult8-Dec-11 16:06 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 16:19
Firo Atrum Ventus8-Dec-11 16:19 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
Luc Pattyn8-Dec-11 22:02
sitebuilderLuc Pattyn8-Dec-11 22:02 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 4:58
Firo Atrum Ventus9-Dec-11 4:58 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
BobJanova8-Dec-11 22:37
BobJanova8-Dec-11 22:37 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 5:07
Firo Atrum Ventus9-Dec-11 5:07 
QuestionPorting VS 2005 => 2010: "Could not load file or assembly..." [SOLVED] Pin
Alan Balkany8-Dec-11 12:14
Alan Balkany8-Dec-11 12:14 
AnswerRe: Porting VS 2005 => 2010: "Could not load file or assembly..." Pin
Richard MacCutchan8-Dec-11 22:22
mveRichard MacCutchan8-Dec-11 22:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.