Problem 45239. Checkmate02
Solution Stats
Problem Comments

6 Comments
Asif,
I think that several of the problem solutions need review.
1. In problem 2, 'Kf7' should not be in the solution since it is adjacent to 'Ke7'. Isn't the correct result {'Kh7',''Kg7','Kf5'}?
2. In problem 7, the king could take any of the knights. Is the solution listed as pos = [] because there are 3 knights on the board? If so, why is the solution to problem 9 listed as 'checkmate'? If not, a solution to problem 9 would be {'Ka3','Ka2'}. Similar questions apply
to problem 8.
3. Why is 'Kc7' not in the solution of problem 3?
I'm afraid I have a lot to learn about chess!
William,
thanks man. There was a bug in my code regarding the other king. i've corrected it. so
3. solution of 3  {Kc7,Kb8}.
1. solution of 2  {kg7,kf5} .. but not kh7  look out!!! there is a rook in the columnh.
2. In prob7, the king is not currently in check.so he is not obliged to move. thats why empty.
2. in prob9, yes the king can take out one of the knights & avoid check. Initially when i wrote this code, i didn't take into account the possibility of the king taking out another piece of the opponent. that would complicate the situation further. I kept it for 'checkmate03'.
Asif,
Thanks for the clarifications.
In problem 2, I was aware of the rook at h3, but there is also a pawn at h5 that makes Kh7 a legitimate solution I think (one that is harder to detect programmatically). As in problem 9, it complicates the solution a little more than you intended.
william,
yes u're right.
my bad..i didn't see that pawn..there is a lot to look into i guess
The problem should state that the king is black since Kd5 is not a valid movement for a white king in the first test. And shouldn't the possible moves for the king follow an order? Or else the function "isequal" will fail if the order of the movements does not match. Test #1 uses CW ordering, and Test#3 uses CCW ordering, for instance. And increasing and decreasing indexes also do not work.
Test #10 is wrong. It should return an empty list since the King is not in check (& if he were, Kg5 would also be a valid movement). Tests #8 and #9 are inconsistent because both boards have black kings who are in check and cannot escape, but one returns [] and the other 'checkmate' (assuming the king cannot take other pieces).
Solution Comments

2 Comments
It shows all kids that just because a code works does not mean it is correct. It is possible to create all kinds of code, even the ones that reproduce the wrong answers someone made. If you have a board at home, set up test number 10 and check the valid positions.
And that's the problem with using code to verify code (For people dreaming of complete automation), we can only guarantee that our code has the same errors as the original code, not that the original code is correct.
Problem Recent Solvers5
Suggested Problems

Which values occur exactly three times?
4527 Solvers

Count from 0 to N^M in base N.
231 Solvers

1347 Solvers

Are all the three given point in the same line?
353 Solvers

86 Solvers
More from this Author165
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!