N-queens minimum and knights and bishops: Difference between revisions
N-queens minimum and knights and bishops (view source)
Revision as of 15:17, 13 May 2022
, 2 years ago→{{header|Wren}}: Incorporated latest Go improvement.
(→{{header|Go}}: Improvement for knights.) |
(→{{header|Wren}}: Incorporated latest Go improvement.) |
||
Line 1,629:
This was originally based on the Java code [https://www.geeksforgeeks.org/minimum-queens-required-to-cover-all-the-squares-of-a-chess-board/ here] which uses a backtracking algorithm and which I extended to deal with bishops and knights as well as queens when translating to Wren. I then used the more efficient way for checking the diagonals described [https://www.geeksforgeeks.org/n-queen-problem-using-branch-and-bound/ here] and have now incorporated the improvements made to the Go version.
Although far quicker than it was originally (it now gets to 7 knights in less than a minute), it struggles after that and needs north of
<lang ecmascript>import "./fmt" for Fmt
Line 1,709:
}
if (countSoFar <= maxCount) {
var si = (piece == "K") ? (ti-2).max(0) : ti
var sj = (piece == "K") ? (tj-2).max(0) : tj
for (i in si...n) {
for (j in sj...n) {
Line 1,858:
. . . . . . . . . .
Took
</pre>
|