Click here to Skip to main content
15,946,988 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Can I have java code for 8 queen problem using genetic algorithm.

Please send all your spam to

thanks in advance
Updated 25-Sep-15 13:17pm
Matt T Heffron 25-Sep-15 18:32pm    
As Afzaal said, you need to do your own homework.
I'll give you 2 hints.
If I were going to do this I'd:
1. represent the genome as 64 Boolean values (only 8 can be true) representing the board state
2. the fitness function is based on how many queens are "safe"
PIEBALDconsult 25-Sep-15 19:21pm    
N-Queens is actually much easier than that. It's actually one-dimensional; not two-dimensional as people assume. Find the Permutations of N things taken N at a time.
Matt T Heffron 25-Sep-15 19:35pm    
I agree to both comments. As a homework assignment I assumed that use of genetic algorithm was required.
PIEBALDconsult 25-Sep-15 19:52pm    
"It's homework" is also the only valid reason to use recursion for factorials. But don't come here asking for code.
Matt T Heffron 25-Sep-15 19:53pm    

No, if that is your homework you need to do it yourself. We won't provide any code unless you show us what you did and where did it get your stuck. Here is the algorithm,[^] (See solutions) and you may want to have a look at a few PDFs provided in this Google search[^].
Share this answer
Sergey Alexandrovich Kryukov 25-Sep-15 21:06pm    
Again, fair enough, a 5.
Afzaal Ahmad Zeeshan 26-Sep-15 4:22am    
Thank you, Sergey.
Matt T Heffron 28-Sep-15 13:08pm    
Afzaal Ahmad Zeeshan 28-Sep-15 15:11pm    
Thank you, Matt.
Your Solution: Start working.

We do not do your homework !

By the way, try to define genetic algorithm. This wording covers many things. Which one is related to your question?

Because the spam comment shows bad spirit, no further advice provided.
Share this answer
Matt T Heffron 28-Sep-15 13:08pm    
Patrice T 28-Sep-15 13:31pm    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900