This is really cool. I wish the pieces were off the board at the start though. I’d much prefer to build up a solution iteratively than try to fix a broken one.
I totally agree. This was the technical limitation of the library that I was using (chessboardjs). If pieces are off board, there is no easy way to limit the number of pieces that you add to the board. Finding a better solution is on my todo list.
Do you think there’s a way to “rate” a particular solution? I’m wondering about how to gauge “efficiency” in placing the pieces. Fewest “wasted” threat squares maybe?
I am not sure what this question has to do with the previous comment and why it is not asked in a separate thead! am I missing a point in your question?
Back to your question. There are two types of solutions:
1- Perfect solution, you get a green notification when you find the solution, in which other squares with no number have zero threats. Pressing the 'solution' button reveal the perfect solution
2- Imperfect solution, you get a yellow notification when you find one, in which other squares with no number may be under one or more threats.
As a simple example, for the puzzle below placing pawn on c2 is an imperfect solution but placing it on a2 is the perfect solution.
This is something that bugged me for a long time. There are many other challenging algorithmic questions that I will share in a separate blog post later (e.g. writing a efficient solver). If you have any idea how to do that I would love to hear about that.
I have actually used SAT solver before but I have no idea how to translate this into a SAT problem. I know it is too much to ask you to do it for me but maybe you can give me a hint (or link) on how to translate problems that deal with numbers into boolean expression that can be solved by a SAT solver.
I’m not an expert in it either, but this problem is similar to both the N-queens problem and Sudoku, both of which can be solved via SAT, so tutorials for those should be a good start. Good luck!
Thanks for you comment. I am working on it now.
1- Perfect solution, you get a green notification when you find the one, in which other squares with no number have zero threats. Pressing the 'solution' button reveal the perfect solution
2- Imperfect solution, you get a yellow notification when you find one, in which other squares with no number may be under one or more threats.
A bit confusing so for now I try not to be strict about imperfect solutions.
joke aside, there can be:
1- any arbitrary number of pieces on the board
2- pawns in the first and last rows
3- missing king
4- missing opposite color pieces