Problem 45239. Checkmate-02
This is an extension of the problem https://www.mathworks.com/matlabcentral/cody/problems/45238-checkmate
If the king is in check, examine the next move of the king. List all those possible moves by which king can avoid the check by the next move.
Otherwise 'checkmate'.
- r = king's location
- p = position of opponent's pieces
- if the king is currently not in check, then he doesn't need to move. so return empty.
- for simplicity, assume that the king cannot take out opponent's pieces.
Solution Stats
Problem Comments
-
6 Comments
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
Show commentsGroup

Number theory
- 44 Problems
- 21 Finishers
- Pseudo-vampire number
- Pell numbers
- Frugal number
- Be happy
- Bell Triangle
- find nth even fibonacci number
- Cantor counting
- check whether a number is a pentatope number
- generate nth pentatope number
- Fangs of a vampire number
- Find all vampire fangs
- Balanced number
- Mandelbrot Numbers
- Parasitic numbers
- Woodall number
- Kaprekar numbers
- Project Euler: Problem 4, Palindromic numbers
- Fangs of pseudo-vampire number
- Project Euler: Problem 9, Pythagorean numbers
- Mersenne Primes
- Sophie Germain prime
- Determine if input is a Narcissistic number
- Determine if input is a perfect number
- Ordinal numbers
- Lychrel Number Test (Inspired by Project Euler Problem 55)
- Circular Primes (based on Project Euler, problem 35)
- Largest Twin Primes
- Golomb's self-describing sequence (based on Euler 341)
- Is it an Armstrong number?
- Champernowne Constant
- Last non-zero digit
- Generate a Parasitic Number
- Smith numbers
- Evil Number
- Armstrong Number
- Polite numbers. Politeness.
- Polite numbers. N-th polite number.
- Narcissistic number ?
- Is this number Munchhausen?
- P-smooth numbers
- Iccanobif numbers 1
- Amicable numbers
- Extra safe primes
- Pentagonal Numbers
Problem Recent Solvers8
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!