Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
% Load in the routines that play the game and check move validity
tic
urlwrite('http://rmatlabtest.appspot.com/Chezz_Shell.m','Chezz_Shell.m') ;
urlwrite('http://rmatlabtest.appspot.com/ghost_white.m','ghost_white.m')
urlwrite('http://rmatlabtest.appspot.com/computer_move020.m','computer_move.m')
urlwrite('http://rmatlabtest.appspot.com/mov_chk.m','mov_chk.m')
rehash path
toc
ans =
/users/msssystem9/ghost_white.m
ans =
/users/msssystem9/computer_move.m
ans =
/users/msssystem9/mov_chk.m
[Warning: Function license has the same name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function mex has the same name as a MATLAB builtin. We suggest you rename the function to
avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function home has the same name as a MATLAB builtin. We suggest you rename the function to
avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function keyboard has the same name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function more has the same name as a MATLAB builtin. We suggest you rename the function to
avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function pause has the same name as a MATLAB builtin. We suggest you rename the function to
avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
[Warning: Function simulink has the same name as a MATLAB builtin. We suggest you rename the function
to avoid a potential name conflict.]
[> In verifyCode>evaluateCode at 231
In verifyCode at 40
In fevalJSON at 14]
Elapsed time is 0.620526 seconds.
|
2 | Fail |
%%
% Play Two Chezz games
% Player must win Twice to Pass
global pmvout1 pmvout2
tic
wins=0; % player wins
b=zeros(8);% P 1/7 R 2/8 N 3/9 B 4/10 Q 5/11 K 6/12
b(2,:)=7;
b(1,:)=[8 9 10 11 12 10 9 8]; % Player 7:12
b(7,:)=1;
b(8,:)=b(1,:)-6; % Computer 1:6
b_orig=b;
%mv=zeros(1,3); % [from to promo)]
%computer_wht=0; % 0 Computer plays wht
%computer_wht=1; % 1 Computer plays black
pmv=zeros(1,3); % [from to promo)] Opponents last move
castle=[1 1 1 1 1 1];
% False move call to satisfy Cody Rqmt of TestSuite match Ref Solution
mv=player_move(b,pmv,castle)
for computer_wht=0:1
pmvout1=pmv; % Store game 1 moves
dbg=0;
game_over=false;
b=b_orig;
no_capture=0;
b_hist=zeros(102,8,8);
pmv=zeros(1,3); % [from to promo)] Opponents last move
castle=[1 1 1 1 1 1]; % History of if ever moved w/b Castles/kings
% idx 8 40 64 1 33 57
while ~game_over
mvP=zeros(1,3); % [from to type/promote)]
% Shell 0=Blk,1=Wht;Board;move,prev move;
% function (1 Play Comp, 2 Player, 3 Check mv)
% White move
if computer_wht==0
[mvP]=Chezz_Shell(0,b,mvP,pmv,castle,1); % 0 Wht,... 1 Computer
else
[mvP]=Chezz_Shell(0,b,mvP,pmv,castle,2); % 0 Wht 2 is player
end
[mv]=Chezz_Shell(0,b,mvP,pmv(end,:),castle,3); % 0 Wht,..., 3 Check
pmv=[pmv;mv(1:3)];
capture=false;
% Board changes only occur in Suite code
if mv(1)~=0 % Valid move determined by mv_chk
if mv(4)==0 % Normal moves and promotions
if b(mv(2))~=0,capture=true;end
b(mv(2))=b(mv(1)); % potential promotion
b(mv(1))=0;
if ismember(b(mv(2)),[1 7])
if ismember(mv(2),[1:8:57 8:8:64])
b(mv(2))=mv(3); % Place promoted selection
end
end
else % ep or castle by White
if mv(4)==1 % castle 0-0 or 0-0-0
b(mv(1))=0;
b(mv(2))=6;
if mv(2)==24
b(8)=0;b(32)=2;
else
b(64)=0;b(48)=2;
end
end % castle
if mv(4)==2 % ep
capture=true;
b(mv(1))=0;
b(mv(2))=1; % White Pawn
b(mv(2)+1)=0; % Take pawn that passed
end % end ep
end % move implemented
end % end move
%b % display board after move
if isempty(find(b==12,1))
% Game over : Black King Captured
game_over=true; % change to if comp=wht or blk for win
if computer_wht==1 % Blk Computer King; Player is Wht captured Blk King
wins=wins+1;
end
continue;
end
castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);
if ~capture
no_capture=no_capture+1;
if no_capture>100
fprintf('Draw 100 moves no capture\n');
game_over=true;
end % move is b and w
b_hist(no_capture,:,:)=b;
else
no_capture=1;
b_hist=b_hist*0;
b_hist(no_capture,:,:)=b;
end
% Black Move
mvP=zeros(1,4); % [from to type/promote specials(castle=1/ep=2)]
if computer_wht==0
[mvP]=Chezz_Shell(1,b,mvP,pmv,castle,2); % 2 Blk,... 2 is player
else
[mvP]=Chezz_Shell(1,b,mvP,pmv,castle,1); % 2 Blk 1 is Computer
end
[mv]=Chezz_Shell(1,b,mvP,pmv(end,:),castle,3); % 2 Blk,..., 3 Check
pmv=[pmv;mv(1:3)];
capture=false;
% Board changes only occur in Suite code
if mv(1)~=0 % Valid move determined by mv_chk
if mv(4)==0 % Normal moves and promotions
if b(mv(2))~=0,capture=true;end
b(mv(2))=b(mv(1)); % potential promotion
b(mv(1))=0;
if ismember(b(mv(2)),[1 7])
if ismember(mv(2),[1:8:57 8:8:64])
b(mv(2))=mv(3); % Place promoted selection
end
end
else % ep or castle by Black
if mv(4)==1 % castle 0-0 or 0-0-0
b(mv(1))=0;
b(mv(2))=12;
if mv(2)==49 % Blk 0-0
b(57)=0;b(41)=8;
else % Blk 0-0-0
b(1)=0;b(25)=8;
end
end % castle
if mv(4)==2 % ep by Black
capture=true;
b(mv(1))=0;
b(mv(2))=mv(3);
% White passed black on prior move
b(mv(2)-1)=0;
end % end ep
end % move implemented
end % end move
% b
% figure(1);imagesc(b,[0 12]);axis equal;
if isempty(find(b==6,1))
% Game over : Blk captured White King
game_over=true;
if computer_wht==0 % Wht Computer King; Player is Blk captured Wht King
wins=wins+1;
end
continue
end
castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);
if ~capture
no_capture=no_capture+1;
if no_capture>100
fprintf('Draw 100 moves no capture\n');
game_over=true;
end % move is b and w
b_hist(no_capture,:,:)=b;
% Check for 3 position repetition
for i=1:no_capture-1
cdelta=0;
for j=i+1:no_capture
delta=(b_hist(i,:,:)-b_hist(j,:,:));
if sum(abs(delta(:)))==0
cdelta=cdelta+1;
end
end
if cdelta>=7 % repetitions 3 identical setups
fprintf('Game over due to repetition\n');
game_over=true;
end
end % rep check loop
else
no_capture=1;
b_hist=b_hist*0;
b_hist(no_capture,:,:)=b;
end % ~capture
end % While ~game_over
end % wht_blk
pmvout2=pmv;
wins
% Player must win Twice to Pass
toc
assert(isequal(wins,2))
Error: Assertion failed.
|
3 | Pass |
%%
global pmvout1 pmvout2
% Output moves for games
% Output game 2 moves
pmv=pmvout1;
for i=2:3:size(pmv,1)-3
fprintf('%2i %2i %2i %2i %2i %2i %2i %2i %2i \n',pmv(i,1:3),pmv(i+1,1:3),pmv(i+2,1:3));
end
fprintf('%2i %2i %2i\n',pmv(end-2,:));
fprintf('%2i %2i %2i\n',pmv(end-1,:));
fprintf('%2i %2i %2i\n',pmv(end,:));
% Output game 2 moves
pmv=pmvout2;
for i=2:3:size(pmv,1)-3
fprintf('%2i %2i %2i %2i %2i %2i %2i %2i %2i \n',pmv(i,1:3),pmv(i+1,1:3),pmv(i+2,1:3));
end
% repeat of moves
fprintf('%2i %2i %2i\n',pmv(end-2,:));
fprintf('%2i %2i %2i\n',pmv(end-1,:));
fprintf('%2i %2i %2i\n',pmv(end,:));
7 6 6 9 19 0 6 5 6
19 29 0 5 4 6 49 59 0
4 3 6 59 44 0 3 10 6
29 23 0 10 17 6 44 38 0
15 14 6 38 32 0 14 13 6
23 40 0 13 12 6 40 55 0
12 11 6 32 47 0 11 18 6
55 40 0 18 25 6 40 30 0
39 30 6 47 64 0 30 29 6
64 47 0 29 28 6 47 32 0
28 27 6 32 38 0 27 34 6
38 48 0 31 30 6 48 63 0
30 29 6 63 48 0 29 28 6
48 63 0 28 27 6 63 53 0
34 41 6 53 36 0 17 26 0
36 26 0 25 26 0 0 0 0
25 26 0
0 0 0
26 33 0
16 22 0 2 3 12 56 46 0
3 4 12 46 29 0 4 5 12
29 35 0 5 6 12 22 5 0
6 15 12 35 25 0 15 24 12
25 10 0 18 19 12 5 11 0
19 20 12 11 17 0 20 21 12
17 34 0 21 22 12 10 20 0
22 31 12
34 49 0
31 40 12
|
Given two strings, find the maximum overlap
461 Solvers
142 Solvers
284 Solvers
37 Solvers
30 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!