5个皇后 [英] 5 queens

查看:107
本文介绍了5个皇后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


我用JavaScript设计了一个名为5

queens的小程序。

http://www.cf29.com/design/dame5_eng.php


我们的目标是控制所有五个皇后的棋盘,这些棋王不会互相攻击。我发现手动这个问题很多解决方案(直到现在才有184个)并想创建一个Python脚本来查找

。因为我是Python的新手,所以我很挣扎。


我找到了一种创建方法:

- 每个方块由其行定义的板,列,如果它是

控制或不是

- 一个函数,告诉哪个方块由一个女王控制在

特定方格

- 一个计算控制了多少个方格的函数

- 一个可以将所有方块控制重置为0的函数
- 一个可以放置的函数安全地登上5个皇后

- 我可以找到第一个解决方案并将其注册在一个列表中


我的问题现在就开始了。如何找到下一个解决方案并将其附加到列表中?
?有没有人试过这样的剧本?如果有人有兴趣帮我展示我到目前为止做了什么。

Greetings,

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.

推荐答案

cf29写道:
cf29 wrote:

问候,


我用JavaScript设计了一个名为5

的小程序皇后。
Greetings,

I designed in JavaScript a small program on my website called 5
queens.



...


有没有人试过这样的剧本?如果有人是

...

Has anyone tried to do a such script? If anyone is


有兴趣帮助我展示我到目前为止所做的事情。
interested to help I can show what I''ve done so far.



Tim Peters在标准库中的test_generators中有8个皇后的解决方案

测试套件(参见:Lib / test / test_generators.py )


HTH


Michael

Tim Peters has a solution to 8 queens in test_generators in the standard library
test suite (see: Lib/test/test_generators.py)

HTH

Michael


12月23日,上午8:05,Dennis Lee Bieber< wlfr ... @ ix.netcom.comwrote:
On Dec 23, 8:05 am, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:

星期六,2007年12月22日11:36:07 -0800 (PST),cf29< fcharlypil ... @ gmail.com>

在comp.lang.python中声明了以下内容:
On Sat, 22 Dec 2007 11:36:07 -0800 (PST), cf29 <fcharlypil...@gmail.com>
declaimed the following in comp.lang.python:

问候,
Greetings,


我在JavaScript上设计了一个名为5

queens的小程序。
I designed in JavaScript a small program on my website called 5
queens.



只有5个?经典的算法是在标准的8x8主板上使用8-queens,

我记得...


Only 5? The classic algorithm is 8-queens on a standard 8x8 board,
as I recall...



经典*问题*是& 8个女王不会互相攻击。

The classic *problem* is "8 queens don''t attack each other".


>
http://en.wikipedia.org/wiki/Eight_q...ght_queens_puz ...
>
http://en.wikipedia.org/wiki/Eight_q...ght_queens_puz...



然后键入Ctrl-F其次是统治。正如OP所说,他的目标

是用五个皇后控制所有国际象棋棋盘,而不是互相攻击

and then type Ctrl-F followed by domination. As the OP says, his "goal
is to control all the chess board with five queens that do
not attack each other"


>
>

我的问题现在开始了。如何找到下一个解决方案并将其附加到列表中?
?有没有人试过这样的剧本?如果有人有兴趣帮助我可以展示我到目前为止所做的事情。
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.



你的问题与Python无关。这是一个设计算法的练习 - 算法是语言中立的。


None of your problems are Python related. This is an exercise in
designing an algorithm -- algorithms are language neutral.



的确如此。维基百科文章提供了几条关于如何避免经典问题的蛮力解决方案的线索 - 其中一些应该是适用于OP问题的

Indeed. The Wikipedia article has several clues on how to avoid a
brute-force solution to the classic problem -- some of these should be
applicable to the OP''s problem.


12月22日,11:05 * pm,Dennis Lee Bieber< wlfr ... @ ix.netcom.comwrote:
On Dec 22, 11:05*pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:

* * * *只有5个?经典的算法是在标准的8x8主板上使用8-queens,

我记得......
* * * * Only 5? The classic algorithm is 8-queens on a standard 8x8 board,
as I recall...



这是一个不同的问题。你必须用

控制所有的方格只有5个皇后。

在8个皇后问题中你必须放8个安全皇后。

我也在我的网站 http://www.cf29。 com / design / dame_eng.php

我知道维基百科8皇后解决方案,这就是我发现Python的方式。我想了解更多关于它的尝试修改这个脚本的5个女王问题。它帮助我尽可能地用我的5个皇后脚本完成了我的b $ b,但是8个皇后脚本只考虑了等于行数的

数量的皇后。在5皇后问题中,

有8行,其中3行是空的。


它可能与Python无关,所以可能是我的留言

错位了。无论如何,谢谢你的帮助。

This is a different problem. You have to control all the squares with
only 5 queens.
In the 8 queens problem you have to put 8 "safe queens".
I also have it on my website at http://www.cf29.com/design/dame_eng.php

I know about the Wikipedia 8 queens solution and it is how I
discovered Python. I wanted to learn more about it to try to modify
this script for the 5 queens problem. It helped me to go as far as I
did with my 5 queens script but the 8 queens script only considers a
number of queens equal to the number of rows. In the 5 queens problem,
there are 8 rows and 3 of them are empty.

It may be not particularly related to Python so may be my message is
misplaced. Thanks for the help anyway.


这篇关于5个皇后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆