This problem is driving me crazy... Place N bishops on NxN board in a way, where all squares would be occupied or attacked with at least one of them.
Could anyone help me out with an algorithm for solving this problem?
This problem is driving me crazy... Place N bishops on NxN board in a way, where all squares would be occupied or attacked with at least one of them.
Could anyone help me out with an algorithm for solving this problem?
_ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _ _ _ _ _ ♗ _ _ _ _
There is a minimum and a maximum solution for this problem it isn't as trivial.
Check this BishopsProblem or more detailed
I'm sure you will easily find an example in c.
Why backtrack? Use the small number of solutions to obtain a proof.
Even a greedy algorithm will suffice: Count the number of squares reachable from each square. Pick a square with the greatest reach that doesn't overlap with a previously picked reach. Repeat.
Ambiguity generates horizontal, vertical, and side-of-center variations.
N bishops is only enough to reach each square with exactly one bishop. If you picked squares with overlapping reach, the final tally of reachable squares would be lower. Hmm, maybe you need to quantify how much lower for any given bad square. Sounds doable.
For such a huge problem space, brute-force backtracking doesn't sound promising.
I'm assuming you're asking for some optimizations, since the backtracking algorithm is what it is.
First thing to notice is that you can separate the black and white - you take the sum of B_i * W_j
where i + j = N
. You can also visualize the diagonals as a simple grid (with constraints) as it'll likely make the code tighter and maybe easier to understand. Another optimization is noticing that the color does not necessarily matter -- the results for some blacks can be used for some whites. Figure out when this happen and when it doesn't.
Hope this is a good enough boost -- should be sufficient for some smallish N's.