Cody

Problem 45239. Checkmate-02

Solution 2068834

Submitted on 25 Dec 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
r = 'Kd4'; p={'Qe3','Rh3','Nc1','c6'}; pos = {'Kd5','Kc4'}; assert(isequal(checkmate_2(r,p),pos))

2   Pass
r = 'Kg6'; p={'Qe3','Rh3','Nc1','c6','Ke7','h5'}; pos = {'Kg7','Kf5'}; assert(isequal(checkmate_2(r,p),pos))

3   Pass
r = 'Kc8'; p={'Qe3','Rh3','Nc1','c6','Ke7','h5','Ba6'}; pos = {'Kc7','Kb8'}; assert(isequal(checkmate_2(r,p),pos))

4   Pass
r = 'Kh1'; p={'Qa3','Rb3','Nf2','c6','Kf7','h5','Ba6'}; pos = {'Kh2','Kg2','Kg1'}; assert(isequal(checkmate_2(r,p),pos))

5   Pass
r = 'Kg6'; p={'Qe3','Rh3','Nc1','c6'}; pos = []; assert(isequal(checkmate_2(r,p),pos))

6   Pass
r = 'Kd4'; p={'Rh2','Na1','d1'}; pos = []; assert(isequal(checkmate_2(r,p),pos))

7   Pass
r = 'Kb2'; p={'Na2','Na1','Na3'}; pos = []; assert(isequal(checkmate_2(r,p),pos))

8   Pass
r = 'Kb2'; p={'Na2','Na1','Na3','c1','c3'}; pos = []; assert(isequal(checkmate_2(r,p),pos))

9   Pass
r = 'Kb2'; p={'Na2','Na1','Na3','Bg7' }; pos = 'checkmate'; assert(isequal(checkmate_2(r,p),pos))

10   Pass
r = 'Kg6'; p={'Nf5','Rg1','g4','Qe2','Bf1','Kc3' }; pos = {'Kh7','Kf7','Kf6'}; assert(isequal(checkmate_2(r,p),pos))

11   Pass
r = 'Ka1'; p={'Qa3','Rb3','Nf2','c6','Kf7','h5','Ba6'}; pos = 'checkmate'; assert(isequal(checkmate_2(r,p),pos))

12   Fail
filetext = fileread('checkmate_2.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp() forbidden') assert(isempty(strfind(filetext, 'regexprep')),'regexprep() forbidden') assert(isempty(strfind(filetext, 'strfind')),'strfind() forbidden') assert(isempty(strfind(filetext, 'strcmp')),'strcmp() forbidden')

strcmp() forbidden

Suggested Problems

More from this Author149

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!