5 queens

subeen tamim.shahriar at gmail.com
Sat Dec 22 22:58:10 EST 2007


Hi,

The problem you are trying to solve is a very famous and common
problem which can be solved by backtracking. Please try google with 8
queens problem or n queens problem.

>
> I designed in JavaScript a small program on my website called 5
> queens.
> (http://www.cf29.com/design/dame5_eng.php)
>
> The goal is to control all the chess board with five queens that do
> not attack each other. I found "manually" many solutions to this
> problem (184 until now) and wanted to create a Python script to find
> them all. As I am new to Python, I struggle a lot.
>
> I found a way to create:
> - a board where each square is defined by its row, column and if it is
> controlled or not
> - a function that tells which squares are controlled by a queen on a
> particular square
> - a function that counts how many squares are controlled
> - a function that can reset all squares control to 0
> - a function that can place 5 queens safely on the board
> - I can find the first solution and register it in a list
>
> My problem starts now. How can I find the next solution and append it
> to the list? Has anyone tried to do a such script? If anyone is
> interested to help I can show what I've done so far.

Try to generate the next permutation and check if it's a valid
solution. Need to use recursion for this.

regards,
Subeen.



More information about the Python-list mailing list