{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":715,"title":"Chezz_015 : Simplified chess","description":"Chezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\r\n\r\nSimplified the rules to implement rapid move check. Normal Chess moves like \"a4\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\r\n\r\nChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\r\n\r\n\r\n*Inputs:* (b,pmv,castle)\r\n\r\nPlayer always appears to be White. However, Black may apparently move first.\r\n\r\nb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\r\n\r\npmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\r\n\r\ncastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\r\n\r\n\r\n\r\n*Output:* mv  [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\r\n\r\n\r\n\r\nThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\r\n\r\n*Passing:* Player must Win both games\r\n\r\n*Evolution:* Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\r\n\r\n\r\nChezz_015: Pawn Serial Attack - Will capture and Promote\r\n\r\nLink update 12/27/12","description_html":"\u003cp\u003eChezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\u003c/p\u003e\u003cp\u003eSimplified the rules to implement rapid move check. Normal Chess moves like \"a4\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\u003c/p\u003e\u003cp\u003eChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\u003c/p\u003e\u003cp\u003e\u003cb\u003eInputs:\u003c/b\u003e (b,pmv,castle)\u003c/p\u003e\u003cp\u003ePlayer always appears to be White. However, Black may apparently move first.\u003c/p\u003e\u003cp\u003eb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\u003c/p\u003e\u003cp\u003epmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\u003c/p\u003e\u003cp\u003ecastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e mv  [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\u003c/p\u003e\u003cp\u003eThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\u003c/p\u003e\u003cp\u003e\u003cb\u003ePassing:\u003c/b\u003e Player must Win both games\u003c/p\u003e\u003cp\u003e\u003cb\u003eEvolution:\u003c/b\u003e Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\u003c/p\u003e\u003cp\u003eChezz_015: Pawn Serial Attack - Will capture and Promote\u003c/p\u003e\u003cp\u003eLink update 12/27/12\u003c/p\u003e","function_template":"function mv=player_move(b,pmv,castle)\r\n% Author: Richard Z\r\n% Bot name: First Pawn Attack\r\n% Chezz_015\r\n% http://tinyurl.com/matlab-chezz-Cmove015\r\n%\r\n% 0-wht 1-Blk; board 8x8, opponents last move, \r\n% castle vector(8 40 64 1 33 57) 0=has moved, 1=eligible\r\n mv=zeros(1,3); % [from to promo] \r\n % mv =[39 37 0] is e4\r\n % pmv (opponents last move) is used for en passant\r\n % [0 0 0] is invalid move or first move of game\r\n % castle is used to castle yourself or see if opponent may castle\r\n \r\n pieces=1:6;\r\n enemy=7:12;\r\n\r\n pv=find(b==1);\r\n no_move=true;\r\n ptr=0;\r\n \r\n % loop thru pawns types; capture L/R or Move up\r\n \r\n while no_move\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(pv),break;end\r\n  [r c]=ind2sub([8 8],pv(ptr));\r\n  if ismember(r,[1 8]),continue;end % end row for a P\r\n  if c==1\r\n   if ismember(b(pv(ptr)+7),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)+7 6];\r\n    return;\r\n   end\r\n  end\r\n  if c==8\r\n   if ismember(b(pv(ptr)-9),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)-9 6];\r\n    return;\r\n   end\r\n  end\r\n  if c\u003c8 \u0026\u0026 c\u003e1\r\n   if ismember(b(pv(ptr)+7),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)+7 6];\r\n    return;\r\n   end\r\n   if ismember(b(pv(ptr)-9),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)-9 6];\r\n    return;\r\n   end\r\n  end\r\n  \r\n  % Move fwd\r\n  if b(pv(ptr)-1)==0\r\n   mv=[pv(ptr) pv(ptr)-1 6];\r\n   return;\r\n  end\r\n  \r\n end % while no move\r\n\r\nend % End of Computer Champion Bot","test_suite":"%%\r\n% Load in the routines that play the game and check move validity\r\ntic\r\nurlwrite('http://rmatlabtest.appspot.com/Chezz_Shell.m','Chezz_Shell.m') ;\r\nurlwrite('http://rmatlabtest.appspot.com/ghost_white.m','ghost_white.m') \r\nurlwrite('http://rmatlabtest.appspot.com/computer_move015.m','computer_move.m') \r\nurlwrite('http://rmatlabtest.appspot.com/mov_chk.m','mov_chk.m') \r\nrehash path\r\ntoc\r\n%%\r\n% Play Two Chezz games\r\n% Player must win Twice to Pass\r\nglobal pmvout1 pmvout2\r\ntic\r\n wins=0; % player wins\r\n b=zeros(8);% P 1/7 R 2/8 N 3/9 B 4/10 Q 5/11 K 6/12 \r\n b(2,:)=7;\r\n b(1,:)=[8 9 10 11 12 10 9 8]; % Player 7:12\r\n b(7,:)=1;\r\n b(8,:)=b(1,:)-6; % Computer 1:6\r\n b_orig=b;\r\n \r\n %mv=zeros(1,3); % [from to promo)]  \r\n %computer_wht=0; % 0 Computer plays wht\r\n %computer_wht=1; % 1 Computer plays black\r\n \r\n pmv=zeros(1,3); % [from to promo)] Opponents last move\r\n castle=[1 1 1 1 1 1];\r\n % False move call to satisfy Cody Rqmt of TestSuite match Ref Solution\r\n mv=player_move(b,pmv,castle)\r\n  \r\n for computer_wht=0:1\r\n  pmvout1=pmv; % Store game 1 moves\r\n  \r\n  dbg=0;\r\n  game_over=false;\r\n  b=b_orig;\r\n  no_capture=0;\r\n  b_hist=zeros(102,8,8);\r\n  pmv=zeros(1,3); % [from to promo)] Opponents last move\r\n  castle=[1 1 1 1 1 1]; % History of if ever moved w/b Castles/kings\r\n %  idx 8 40 64  1 33 57\r\n \r\n while ~game_over\r\n  mvP=zeros(1,3); % [from to type/promote)] \r\n  % Shell 0=Blk,1=Wht;Board;move,prev move;\r\n  % function (1 Play Comp, 2 Player, 3 Check mv)\r\n  \r\n  % White move\r\n  if computer_wht==0\r\n   [mvP]=Chezz_Shell(0,b,mvP,pmv,castle,1); % 0 Wht,... 1 Computer\r\n  else\r\n   [mvP]=Chezz_Shell(0,b,mvP,pmv,castle,2); % 0 Wht  2 is player\r\n  end\r\n  \r\n  \r\n  [mv]=Chezz_Shell(0,b,mvP,pmv(end,:),castle,3); % 0 Wht,..., 3 Check\r\n  pmv=[pmv;mv(1:3)];\r\n  capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk\r\n   if mv(4)==0 % Normal moves and promotions\r\n    if b(mv(2))~=0,capture=true;end\r\n     b(mv(2))=b(mv(1)); % potential promotion\r\n     b(mv(1))=0;\r\n     if ismember(b(mv(2)),[1 7])\r\n      if ismember(mv(2),[1:8:57 8:8:64])\r\n       b(mv(2))=mv(3); % Place promoted selection\r\n      end\r\n     end\r\n     \r\n   else % ep or castle by White\r\n    if mv(4)==1 % castle 0-0 or 0-0-0\r\n      b(mv(1))=0;\r\n      b(mv(2))=6;\r\n      if mv(2)==24\r\n        b(8)=0;b(32)=2;  \r\n      else\r\n        b(64)=0;b(48)=2;\r\n      end    \r\n    end % castle\r\n    if mv(4)==2 % ep\r\n      capture=true;\r\n      b(mv(1))=0;\r\n      b(mv(2))=1; % White Pawn\r\n      b(mv(2)+1)=0; % Take pawn that passed\r\n    end % end ep\r\n   end % move implemented\r\n  end % end move\r\n  \r\n  %b % display board after move\r\n  \r\n  if isempty(find(b==12,1))\r\n   % Game over : Black King Captured\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer King; Player is Wht captured Blk King \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n   b_hist(no_capture,:,:)=b;\r\n  else\r\n   no_capture=1;\r\n   b_hist=b_hist*0;\r\n   b_hist(no_capture,:,:)=b;\r\n  end\r\n   \r\n  % Black Move\r\n  mvP=zeros(1,4); % [from to type/promote specials(castle=1/ep=2)] \r\n if computer_wht==0\r\n   [mvP]=Chezz_Shell(1,b,mvP,pmv,castle,2); % 2 Blk,... 2 is player\r\n  else\r\n   [mvP]=Chezz_Shell(1,b,mvP,pmv,castle,1); % 2 Blk  1 is Computer\r\n end\r\n  \r\n  [mv]=Chezz_Shell(1,b,mvP,pmv(end,:),castle,3); % 2 Blk,..., 3 Check\r\n  \r\n pmv=[pmv;mv(1:3)];\r\n capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk\r\n   if mv(4)==0 % Normal moves and promotions\r\n    if b(mv(2))~=0,capture=true;end\r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(b(mv(2)),[1 7])\r\n     if ismember(mv(2),[1:8:57 8:8:64])\r\n      b(mv(2))=mv(3); % Place promoted selection\r\n     end\r\n    end\r\n   else % ep or castle by Black\r\n    if mv(4)==1 % castle 0-0 or 0-0-0\r\n      b(mv(1))=0;\r\n      b(mv(2))=12;\r\n      if mv(2)==49 % Blk 0-0\r\n        b(57)=0;b(41)=8;  \r\n      else % Blk 0-0-0\r\n        b(1)=0;b(25)=8;\r\n      end    \r\n    end % castle\r\n    if mv(4)==2 % ep by Black\r\n      capture=true;\r\n      b(mv(1))=0;\r\n      b(mv(2))=mv(3);\r\n    % White passed black on prior move\r\n      b(mv(2)-1)=0; \r\n    end % end ep\r\n   end % move implemented\r\n  end % end move\r\n  \r\n%   b\r\n%   figure(1);imagesc(b,[0 12]);axis equal;\r\n  \r\n  if isempty(find(b==6,1))\r\n   % Game over : Blk captured White King\r\n   game_over=true;\r\n   if computer_wht==0 % Wht Computer King; Player is Blk captured Wht King\r\n    wins=wins+1;\r\n   end\r\n   continue\r\n  end\r\n  \r\n  castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n   b_hist(no_capture,:,:)=b;\r\n   % Check for 3 position repetition\r\n   for i=1:no_capture-1\r\n    cdelta=0;\r\n    for j=i+1:no_capture\r\n     delta=(b_hist(i,:,:)-b_hist(j,:,:));\r\n     if sum(abs(delta(:)))==0\r\n      cdelta=cdelta+1;\r\n     end\r\n    end\r\n    if cdelta\u003e=7 % repetitions 3 identical setups\r\n     fprintf('Game over due to repetition\\n');\r\n     game_over=true;\r\n    end\r\n   end % rep check loop \r\n  else\r\n   no_capture=1;\r\n   b_hist=b_hist*0;\r\n   b_hist(no_capture,:,:)=b;\r\n  end % ~capture\r\n  \r\n end % While ~game_over\r\n \r\n end % wht_blk\r\n\r\npmvout2=pmv;\r\nwins\r\n \r\n% Player must win Twice to Pass\r\ntoc\r\nassert(isequal(wins,2))\r\n\r\n%%\r\nglobal pmvout1 pmvout2\r\n% Output moves for games\r\n\r\n% Output game 2 moves\r\npmv=pmvout1;\r\n   for i=2:3:size(pmv,1)-3\r\n    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));\r\n   end\r\n   fprintf('%2i %2i %2i\\n',pmv(end-2,:));\r\n   fprintf('%2i %2i %2i\\n',pmv(end-1,:));\r\n   fprintf('%2i %2i %2i\\n',pmv(end,:));\r\n \r\n% Output game 2 moves\r\npmv=pmvout2;\r\n for i=2:3:size(pmv,1)-3\r\n  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));\r\n  end\r\n% repeat of moves\r\n fprintf('%2i %2i %2i\\n',pmv(end-2,:));\r\n fprintf('%2i %2i %2i\\n',pmv(end-1,:));\r\n fprintf('%2i %2i %2i\\n',pmv(end,:));","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2012-12-27T22:40:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-24T04:58:57.000Z","updated_at":"2012-12-27T22:50:08.000Z","published_at":"2012-05-24T05:15:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimplified the rules to implement rapid move check. Normal Chess moves like \\\"a4\\\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInputs:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (b,pmv,castle)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlayer always appears to be White. However, Black may apparently move first.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003epmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ecastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e mv [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ePassing:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Player must Win both games\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEvolution:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz_015: Pawn Serial Attack - Will capture and Promote\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLink update 12/27/12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":727,"title":"Checkerz_000 Kamikazi Kings","description":"Checkerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\r\n\r\nThe setup requires the player to copy the entire template into his solution.\r\n\r\nThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\r\n\r\nThe player writes his Bot under the player_move routine.\r\n\r\nThe player will always appear to be playing as White.\r\nThe players pieces are 1-Pawn and 2-King.\r\n\r\nThe Computer pieces will appear as 3-Pawn and 4-King.\r\n\r\nThe board is a standard 8x8 with empty squares as 0.\r\n\r\nThe player move is an array index from-to. eg mv=[8 15].  Value range 1 to 64.\r\n\r\nThe routine find_jumps will provide all potential jumps.\r\n\r\nIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\r\n\r\nAn invalid move or a missed jump is a Loss.\r\n\r\n*Input:* Board  8x8 array \r\n\r\n*Output:* Move  [index_from  index_to]\r\n\r\nTo Pass requires Winning Twice. Once as first move and once as second move.\r\n\r\n100 No-capture move series is a Draw\r\n\r\nMoves will be displayed\r\n\r\nCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.","description_html":"\u003cp\u003eCheckerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\u003c/p\u003e\u003cp\u003eThe setup requires the player to copy the entire template into his solution.\u003c/p\u003e\u003cp\u003eThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\u003c/p\u003e\u003cp\u003eThe player writes his Bot under the player_move routine.\u003c/p\u003e\u003cp\u003eThe player will always appear to be playing as White.\r\nThe players pieces are 1-Pawn and 2-King.\u003c/p\u003e\u003cp\u003eThe Computer pieces will appear as 3-Pawn and 4-King.\u003c/p\u003e\u003cp\u003eThe board is a standard 8x8 with empty squares as 0.\u003c/p\u003e\u003cp\u003eThe player move is an array index from-to. eg mv=[8 15].  Value range 1 to 64.\u003c/p\u003e\u003cp\u003eThe routine find_jumps will provide all potential jumps.\u003c/p\u003e\u003cp\u003eIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\u003c/p\u003e\u003cp\u003eAn invalid move or a missed jump is a Loss.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Board  8x8 array\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Move  [index_from  index_to]\u003c/p\u003e\u003cp\u003eTo Pass requires Winning Twice. Once as first move and once as second move.\u003c/p\u003e\u003cp\u003e100 No-capture move series is a Draw\u003c/p\u003e\u003cp\u003eMoves will be displayed\u003c/p\u003e\u003cp\u003eCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.\u003c/p\u003e","function_template":"function mv = Checkerz_Shell(wht_blk,b,mv,ptr)\r\n % Copy this into Players function entry\r\n %figure(1);imagesc(b,[-2 4]);axis equal\r\n %pause(0.1)\r\n \r\n % Remap routine so Engines always think they are White\r\n bv=zeros(8,8); % form of 8x8\r\n bv(1:64)=1:64;\r\n %pmap=(1:4); % [WP WK BP BK]\r\n if wht_blk==1 % Invert Player Perspective\r\n  [b,mv,bv]=ghost_white(b,mv,bv);\r\n end\r\n \r\n % Call Algorithm - White based\r\n % Un-Map to Black if required\r\n \r\n switch ptr\r\n     case {1}\r\n         mv=computer_move(b);\r\n% Self play\r\n% mv=player_move(b);\r\n     case {2}\r\n         mv=player_move(b);\r\n     case {3}\r\n         mv=mov_chk(b,mv);\r\n end % switch ptr\r\n \r\n %Remap mv to Black or leave unchanged if White\r\n if ismember(mv(1),1:64),mv(1)=bv(mv(1));end\r\n if ismember(mv(2),1:64),mv(2)=bv(mv(2));end\r\n \r\nend % Checkerz_Shell\r\n\r\nfunction [b,mv,bv]=ghost_white(b,mv,bv)\r\n% Map Blk to Wht to process \r\n  bv=rot90(rot90(bv)); % Board re-map\r\n  pmap=[3 4 1 2]; % Piece re-map to WP WK BP BK\r\n  \r\n  b=rot90(rot90(b));\r\n  v=find(b\u003e0);\r\n  b(v)=pmap(b(v));\r\n  \r\n  v=find(mv(1:2)\u003e0);\r\n  mv(v)=bv(mv(v));\r\n  \r\nend\r\n\r\nfunction [jv]=find_jumps(b)\r\n jv=[];\r\n P=find(b==1);\r\n K=find(b==2);\r\n \r\n Pjv=ones(64,2);\r\n Pjv = bsxfun(@times, Pjv, [-18 14]); % TL TR\r\n Pjv(1:18,:)=bsxfun(@times,Pjv(1:18,:),[0 1]);\r\n Pjv(2:8:58,:)=bsxfun(@times,Pjv(2:8:58,:),[0 0]);\r\n Pjv(50:64,:)=bsxfun(@times,Pjv(50:64,:),[1 0]);\r\n Pjv([1:2:7 10:2:16 17:2:23],:)=bsxfun(@times,Pjv([1:2:7 10:2:16 17:2:23],:),[0 0]);\r\n Pjv([26:2:32 33:2:39 42:2:48],:)=bsxfun(@times,Pjv([26:2:32 33:2:39 42:2:48],:),[0 0]);\r\n Pjv([49:2:55 58:2:64],:)=bsxfun(@times,Pjv([49:2:55 58:2:64],:),[0 0]);\r\n \r\n Kjv=ones(64,4);\r\n Kjv = bsxfun(@times, Kjv, [14 18 -14 -18]); % TR BR BL TL\r\n Kjv([2 9],:)=bsxfun(@times,Kjv([2 9],:),[0 1 0 0]);\r\n Kjv([4 6 11 13],:)=bsxfun(@times,Kjv([4 6 11 13],:),[1 1 0 0]);\r\n Kjv([8 15],:)=bsxfun(@times,Kjv([8 15],:),[1 0 0 0]);\r\n Kjv([18 25 34 41],:)=bsxfun(@times,Kjv([18 25 34 41],:),[0 1 1 0]);\r\n Kjv([24 31 40 47],:)=bsxfun(@times,Kjv([24 31 40 47],:),[1 0 0 1]);\r\n Kjv([50 57],:)=bsxfun(@times,Kjv([50 57],:),[0 0 1 0]);\r\n Kjv([52 54 59 61],:)=bsxfun(@times,Kjv([52 54 59 61],:),[0 0 1 1]);\r\n Kjv([56 63],:)=bsxfun(@times,Kjv([56 63],:),[0 0 0 1]);\r\n Kjv([1:2:7 10:2:16 17:2:23],:)=bsxfun(@times,Kjv([1:2:7 10:2:16 17:2:23],:),[0 0 0 0]);\r\n Kjv([26:2:32 33:2:39 42:2:48],:)=bsxfun(@times,Kjv([26:2:32 33:2:39 42:2:48],:),[0 0 0 0]);\r\n Kjv([49:2:55 58:2:64],:)=bsxfun(@times,Kjv([49:2:55 58:2:64],:),[0 0 0 0]);\r\n \r\n for i=1:length(P)\r\n  Pi=P(i);\r\n  for j=1:2\r\n   if Pjv(Pi,j)==0,continue;end\r\n   if b(Pi+Pjv(Pi,j))==0 \u0026\u0026 b(Pi+Pjv(Pi,j)/2)\u003e2\r\n    jv=[jv;Pi Pi+Pjv(Pi,j)];\r\n   end\r\n  end\r\n end\r\n \r\n \r\n \r\n for i=1:length(K)\r\n  Ki=K(i);\r\n  for j=1:4\r\n   if Kjv(Ki,j)==0,continue;end\r\n   if b(Ki+Kjv(Ki,j))==0 \u0026\u0026 b(Ki+Kjv(Ki,j)/2)\u003e2\r\n    jv=[jv;Ki K(i)+Kjv(Ki,j)];\r\n   end\r\n  end\r\n end\r\n\r\n \r\nend\r\n\r\n function mv=player_move(b)\r\n % Copy Checkerz_Shell, computer_move, and mov_chk functions into entry  \r\n % Create Player entry inside this function\r\n %\r\n % Author: Your Name\r\n % Bot name:  Your Bot's Nmae\r\n\r\n mv=[0 0]; % [from to] \r\n \r\n% Introduction function to avoid missing jumps\r\n% Player may modify. This is informational jumps only\r\n jv=find_jumps(b);\r\n if ~isempty(jv)\r\n  mv=jv(1,:); % Use the first jump\r\n  return\r\n end\r\n\r\n % End of Player entry\r\n end % End of Player Bot\r\n\r\nfunction mv=computer_move(b)\r\n% Author: Richard Z\r\n% Bot name: Kamikazi : Jump, Pmove, Kattack, Kmove \r\n% Checkerz_000\r\n mv=[0 0]; % [from to] \r\n \r\n jv=find_jumps(b);\r\n if ~isempty(jv)\r\n  mv=jv(1,:); % Use the first jump\r\n  return\r\n end\r\n\r\n % Pawn\r\n pv=find(b==1); % vector of Pawns\r\n %if ~isempty(pv),pv=pv(randperm(length(pv)));end\r\n ptr=0;\r\n while true % Pawn\r\n  pm=[-9 7];\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(pv),break;end\r\n  [r c]=ind2sub([8 8],pv(ptr));\r\n  if c==1, pm=pm.*[0 1];end\r\n  if c==8,pm=pm.*[1 0];end\r\n  \r\n  for i=1:2\r\n   if b(pv(ptr)+pm(i))==0\r\n    mv=[pv(ptr) pv(ptr)+pm(i)];\r\n    return\r\n   end\r\n  end\r\n end % while no move Pawn\r\n \r\n \r\n % No King capture move found\r\nmyk=find(b==2,1); % First King\r\nep=find(b\u003e2,1); %Find an enemy piece, Pawns or Kings\r\n[kr1 kc1]=ind2sub([8 8],myk);\r\n[er1 ec1]=ind2sub([8 8],ep);\r\nif er1\u003c=kr1 \u0026\u0026 ec1\u003e=kc1,king_mv=[7 9 -9 -7];end\r\nif er1\u003e=kr1 \u0026\u0026 ec1\u003e=kc1,king_mv=[9 7 -7 -9];end\r\nif er1\u003c=kr1 \u0026\u0026 ec1\u003c=kc1,king_mv=[-9 7 -7 9];end\r\nif er1\u003e=kr1 \u0026\u0026 ec1\u003c=kc1,king_mv=[-7 9 -9 7];end\r\nfor i=1:4\r\n if kr1==1 \u0026\u0026 ismember(king_mv(i),[-9 7]),continue;end\r\n if kr1==8 \u0026\u0026 ismember(king_mv(i),[-7 9]),continue;end\r\n if kc1==1 \u0026\u0026 ismember(king_mv(i),[-9 -7]),continue;end\r\n if kc1==8 \u0026\u0026 ismember(king_mv(i),[7 9]),continue;end\r\n if b(myk+king_mv(i))==0 % empty square\r\n  mv=[myk myk+king_mv(i)];\r\n  return; % path found\r\n end\r\nend\r\n \r\n% Can I get here if I have a King?\r\n % King\r\n kv=find(b==2); % vector of Kings\r\n %if ~isempty(pv),pv=pv(randperm(length(pv)));end\r\n ptr=0;\r\n while true % King\r\n  km=[7 9 -7 -9];\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(kv),break;end\r\n  [r c]=ind2sub([8 8],kv(ptr));\r\n  if c==1, km=km.*[1 1 0 0];end\r\n  if c==8, km=km.*[0 0 1 1];end\r\n  if r==1, km=km.*[0 1 1 0];end\r\n  if r==8, km=km.*[1 0 0 1];end\r\n  \r\n  \r\n  for i=1:4\r\n   if b(kv(ptr)+km(i))==0\r\n    mv=[kv(ptr) kv(ptr)+km(i)];\r\n    return\r\n   end\r\n  end\r\n end % while no move King\r\n \r\n \r\n% Hopefully don't get here as mv=[0 0] and we lose\r\n\r\nend % End of Computer Bot\r\n\r\nfunction mv_out=mov_chk(b,mv)\r\n % Improvement of mov_chk will be a separate Cody challenge\r\n % Must Copy into Solution Entry\r\n % Invalid move returns [0 0]\r\n mv_out=[0 0]; % default is Invalid\r\n \r\n % verify valid: Entry, Color, Possible capture\r\n if ~ismember(mv(1),1:64) || ~ismember(mv(2),1:64),return;end % Invalid mv\r\n if ~ismember(b(mv(1)),(1:2)),return;end % Moving Wrong team\r\n  % Must move to empty square\r\n if b(mv(2))~=0,return;end\r\n \r\n  \r\n delta=mv(2)-mv(1); % Movement vector\r\n if ~ismember(delta,[7 9 14 18 -7 -9 -14 -18]),return;end % Invalid mv\r\n \r\n msum=mv(1)+mv(2); % Jump midpoint if jump check\r\n \r\n  % use for move checks\r\n [r1 c1]=ind2sub([8 8],mv(1));\r\n [r2 c2]=ind2sub([8 8],mv(2));\r\n \r\n if abs(r1-r2)\u003e2,return;end % Invalid\r\n if abs(c1-c2)\u003e2,return;end % Invalid\r\n   \r\n jv=find_jumps(b);\r\n\r\n if ~isempty(jv)\r\n  if abs(delta)\u003c14,return;end % Jump not executed\r\n end\r\n \r\n \r\n if abs(delta)\u003e13 % Jump claimed\r\n  if b(msum/2)\u003c3,return;end % Invalid Jump -Own or Empty\r\n  \r\n  if b(mv(1))==1 \u0026\u0026 (delta==-18 ||delta==14)\r\n   mv_out=mv; % Valid move\r\n   return;\r\n  end % Legal P Jump\r\n  \r\n  if b(mv(1))==2 \u0026\u0026 (abs(delta)==18 || abs(delta)==14)\r\n   mv_out=mv; % Valid move\r\n   return;\r\n  end % Legal K Jump\r\n  \r\n  return; % Invalid Jump\r\n end % Jump\r\n \r\n % abs(delta)\u003c12 Regular move\r\n if b(mv(1))==1 \u0026\u0026 (delta==-9 ||delta==7)\r\n  mv_out=mv; % Valid move\r\n  return;\r\n end % Legal P mv\r\n \r\n if b(mv(1))==2 \u0026\u0026 (abs(delta)==9 || abs(delta) ==7)\r\n  mv_out=mv; % Valid move\r\n  return;\r\n end % Legal K mv\r\n \r\n mv_out=[0 0]; % Checks failed\r\nend\r\n","test_suite":"%%\r\n%Test Suite\r\ntic\r\n wins=0; % player wins\r\n b=zeros(8);% WP 1 BP 3  [WK 2 BK 4] \r\n b([2 9 11 18 25 27 34 41 43 50 57 59])=3;\r\n b([6 8 15 22 24 31 38 40 47 54 56 63])=1;\r\n b_orig=b;\r\n \r\n %mv=zeros(1,2); % [from to promo)]  \r\n %computer_wht=0; % 0 Computer plays wht\r\n %computer_wht=1; % 1 Computer plays black\r\n \r\n pmv=zeros(1,2); % Move History for record only\r\n  \r\n for computer_wht=0:1\r\n  if size(pmv,1)\u003e3\r\n   for i=1:4:size(pmv,1)-4\r\n    fprintf('%2i %2i %2i %2i %2i %2i %2i %2i\\n',pmv(i,1:2),pmv(i+1,1:2),pmv(i+2,1:2),pmv(i+3,1:2));\r\n   end\r\n   fprintf('%2i %2i\\n',pmv(end-3,:));\r\n   fprintf('%2i %2i\\n',pmv(end-2,:));\r\n   fprintf('%2i %2i\\n',pmv(end-1,:));\r\n   fprintf('%2i %2i\\n',pmv(end,:));\r\n % Output game 1 moves\r\n  end\r\n  %pmv % Output move history from Game 1\r\n  game_over=false;\r\n  b=b_orig; % Reset for second game\r\n  no_capture=0;\r\n  pmv=zeros(1,2); % [from to promo)] Opponents last move\r\n \r\n while ~game_over\r\n  mvP=zeros(1,2); % [from to] \r\n  % Shell 0=Blk,1=Wht;Board;move,prev move;\r\n  % function (1 Play Comp, 2 Player, 3 Check mv)\r\n  \r\n  % White move\r\n  if computer_wht==0\r\n   [mvP]=Checkerz_Shell(0,b,mvP,1); % 0 Wht,... 1 Computer\r\n  else\r\n   [mvP]=Checkerz_Shell(0,b,mvP,2); % 0 Wht  2 is player\r\n  end\r\n  \r\n  [mv]=Checkerz_Shell(0,b,mvP,3); % 0 Wht,..., 3 Check\r\n  \r\n  pmv=[pmv;mv(1:2)];\r\n  capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk \r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(mv(2),[9 25 41 57])\r\n     b(mv(2))=2; % Kinged\r\n    end\r\n    if abs(mv(1)-mv(2))\u003e9\r\n     % Piece jumped\r\n     capture=true;\r\n     b((mv(1)+mv(2))/2)=0;\r\n    end\r\n  end % end move\r\n  \r\n  if isempty(find(b\u003e2)) % White has captured All Blk Pieces\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer Loses; Player is Wht \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if mv(1)==0 % No legal move or missed jump\r\n   % Game over : White failed to move and Loses\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==0 % Wht Computer Loses; Player is Blk \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n    \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end %\r\n  else\r\n   no_capture=1;\r\n  end\r\n   \r\n  % Black Move\r\n  mvP=[0 0]; % [from to type/promote specials(castle=1/ep=2)] \r\n if computer_wht==0\r\n   [mvP]=Checkerz_Shell(1,b,mvP,2); % 2 Blk,... 2 is player\r\n  else\r\n   [mvP]=Checkerz_Shell(1,b,mvP,1); % 2 Blk  1 is Computer\r\n end\r\n  \r\n  [mv]=Checkerz_Shell(1,b,mvP,3); % 2 Blk,..., 3 Check\r\n  \r\n pmv=[pmv;mv(1:2)];\r\n \r\n capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk \r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(mv(2),[8 24 40 56])\r\n     b(mv(2))=4; % Kinged\r\n    end\r\n    if abs(mv(1)-mv(2))\u003e9\r\n     % Piece jumped\r\n     capture=true;\r\n     b((mv(1)+mv(2))/2)=0;\r\n    end\r\n  end % end move\r\n  \r\n  if isempty([find(b==1)' find(b==2)']) % Black has captured All Wht Pieces\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==0 % Wht Computer Loses; Player is Blk \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if mv(1)==0 % No legal move or missed jump by Black\r\n   % Game over : Black failed to move correctly and Loses\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer Loses; Player is Wht \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n  else\r\n   no_capture=1;\r\n  end % ~capture\r\n  \r\n end % While ~game_over\r\n \r\n end % wht_blk\r\n \r\n wins\r\n   if size(pmv,1)\u003e3\r\n    for i=1:4:size(pmv,1)-4\r\n     fprintf('%2i %2i %2i %2i %2i %2i %2i %2i\\n',pmv(i,1:2),pmv(i+1,1:2),pmv(i+2,1:2),pmv(i+3,1:2));\r\n    end\r\n    fprintf('%2i %2i\\n',pmv(end-3,:));\r\n    fprintf('%2i %2i\\n',pmv(end-2,:));\r\n    fprintf('%2i %2i\\n',pmv(end-1,:));\r\n    fprintf('%2i %2i\\n',pmv(end,:));\r\n % Output game 2 moves?\r\n  end\r\n \r\nwins\r\ntoc\r\n\r\n % Player must beat computer twice\r\n %assert(isequal(wins,2))\r\n \r\nPass=1;\r\nassert(isequal(Pass,1))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-30T03:08:30.000Z","updated_at":"2012-05-30T03:20:09.000Z","published_at":"2012-05-30T03:17:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheckerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe setup requires the player to copy the entire template into his solution.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player writes his Bot under the player_move routine.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player will always appear to be playing as White. The players pieces are 1-Pawn and 2-King.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Computer pieces will appear as 3-Pawn and 4-King.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe board is a standard 8x8 with empty squares as 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player move is an array index from-to. eg mv=[8 15]. Value range 1 to 64.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe routine find_jumps will provide all potential jumps.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn invalid move or a missed jump is a Loss.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Board 8x8 array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Move [index_from index_to]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo Pass requires Winning Twice. Once as first move and once as second move.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e100 No-capture move series is a Draw\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMoves will be displayed\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":715,"title":"Chezz_015 : Simplified chess","description":"Chezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\r\n\r\nSimplified the rules to implement rapid move check. Normal Chess moves like \"a4\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\r\n\r\nChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\r\n\r\n\r\n*Inputs:* (b,pmv,castle)\r\n\r\nPlayer always appears to be White. However, Black may apparently move first.\r\n\r\nb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\r\n\r\npmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\r\n\r\ncastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\r\n\r\n\r\n\r\n*Output:* mv  [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\r\n\r\n\r\n\r\nThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\r\n\r\n*Passing:* Player must Win both games\r\n\r\n*Evolution:* Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\r\n\r\n\r\nChezz_015: Pawn Serial Attack - Will capture and Promote\r\n\r\nLink update 12/27/12","description_html":"\u003cp\u003eChezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\u003c/p\u003e\u003cp\u003eSimplified the rules to implement rapid move check. Normal Chess moves like \"a4\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\u003c/p\u003e\u003cp\u003eChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\u003c/p\u003e\u003cp\u003e\u003cb\u003eInputs:\u003c/b\u003e (b,pmv,castle)\u003c/p\u003e\u003cp\u003ePlayer always appears to be White. However, Black may apparently move first.\u003c/p\u003e\u003cp\u003eb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\u003c/p\u003e\u003cp\u003epmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\u003c/p\u003e\u003cp\u003ecastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e mv  [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\u003c/p\u003e\u003cp\u003eThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\u003c/p\u003e\u003cp\u003e\u003cb\u003ePassing:\u003c/b\u003e Player must Win both games\u003c/p\u003e\u003cp\u003e\u003cb\u003eEvolution:\u003c/b\u003e Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\u003c/p\u003e\u003cp\u003eChezz_015: Pawn Serial Attack - Will capture and Promote\u003c/p\u003e\u003cp\u003eLink update 12/27/12\u003c/p\u003e","function_template":"function mv=player_move(b,pmv,castle)\r\n% Author: Richard Z\r\n% Bot name: First Pawn Attack\r\n% Chezz_015\r\n% http://tinyurl.com/matlab-chezz-Cmove015\r\n%\r\n% 0-wht 1-Blk; board 8x8, opponents last move, \r\n% castle vector(8 40 64 1 33 57) 0=has moved, 1=eligible\r\n mv=zeros(1,3); % [from to promo] \r\n % mv =[39 37 0] is e4\r\n % pmv (opponents last move) is used for en passant\r\n % [0 0 0] is invalid move or first move of game\r\n % castle is used to castle yourself or see if opponent may castle\r\n \r\n pieces=1:6;\r\n enemy=7:12;\r\n\r\n pv=find(b==1);\r\n no_move=true;\r\n ptr=0;\r\n \r\n % loop thru pawns types; capture L/R or Move up\r\n \r\n while no_move\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(pv),break;end\r\n  [r c]=ind2sub([8 8],pv(ptr));\r\n  if ismember(r,[1 8]),continue;end % end row for a P\r\n  if c==1\r\n   if ismember(b(pv(ptr)+7),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)+7 6];\r\n    return;\r\n   end\r\n  end\r\n  if c==8\r\n   if ismember(b(pv(ptr)-9),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)-9 6];\r\n    return;\r\n   end\r\n  end\r\n  if c\u003c8 \u0026\u0026 c\u003e1\r\n   if ismember(b(pv(ptr)+7),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)+7 6];\r\n    return;\r\n   end\r\n   if ismember(b(pv(ptr)-9),enemy) % capture\r\n    mv=[pv(ptr) pv(ptr)-9 6];\r\n    return;\r\n   end\r\n  end\r\n  \r\n  % Move fwd\r\n  if b(pv(ptr)-1)==0\r\n   mv=[pv(ptr) pv(ptr)-1 6];\r\n   return;\r\n  end\r\n  \r\n end % while no move\r\n\r\nend % End of Computer Champion Bot","test_suite":"%%\r\n% Load in the routines that play the game and check move validity\r\ntic\r\nurlwrite('http://rmatlabtest.appspot.com/Chezz_Shell.m','Chezz_Shell.m') ;\r\nurlwrite('http://rmatlabtest.appspot.com/ghost_white.m','ghost_white.m') \r\nurlwrite('http://rmatlabtest.appspot.com/computer_move015.m','computer_move.m') \r\nurlwrite('http://rmatlabtest.appspot.com/mov_chk.m','mov_chk.m') \r\nrehash path\r\ntoc\r\n%%\r\n% Play Two Chezz games\r\n% Player must win Twice to Pass\r\nglobal pmvout1 pmvout2\r\ntic\r\n wins=0; % player wins\r\n b=zeros(8);% P 1/7 R 2/8 N 3/9 B 4/10 Q 5/11 K 6/12 \r\n b(2,:)=7;\r\n b(1,:)=[8 9 10 11 12 10 9 8]; % Player 7:12\r\n b(7,:)=1;\r\n b(8,:)=b(1,:)-6; % Computer 1:6\r\n b_orig=b;\r\n \r\n %mv=zeros(1,3); % [from to promo)]  \r\n %computer_wht=0; % 0 Computer plays wht\r\n %computer_wht=1; % 1 Computer plays black\r\n \r\n pmv=zeros(1,3); % [from to promo)] Opponents last move\r\n castle=[1 1 1 1 1 1];\r\n % False move call to satisfy Cody Rqmt of TestSuite match Ref Solution\r\n mv=player_move(b,pmv,castle)\r\n  \r\n for computer_wht=0:1\r\n  pmvout1=pmv; % Store game 1 moves\r\n  \r\n  dbg=0;\r\n  game_over=false;\r\n  b=b_orig;\r\n  no_capture=0;\r\n  b_hist=zeros(102,8,8);\r\n  pmv=zeros(1,3); % [from to promo)] Opponents last move\r\n  castle=[1 1 1 1 1 1]; % History of if ever moved w/b Castles/kings\r\n %  idx 8 40 64  1 33 57\r\n \r\n while ~game_over\r\n  mvP=zeros(1,3); % [from to type/promote)] \r\n  % Shell 0=Blk,1=Wht;Board;move,prev move;\r\n  % function (1 Play Comp, 2 Player, 3 Check mv)\r\n  \r\n  % White move\r\n  if computer_wht==0\r\n   [mvP]=Chezz_Shell(0,b,mvP,pmv,castle,1); % 0 Wht,... 1 Computer\r\n  else\r\n   [mvP]=Chezz_Shell(0,b,mvP,pmv,castle,2); % 0 Wht  2 is player\r\n  end\r\n  \r\n  \r\n  [mv]=Chezz_Shell(0,b,mvP,pmv(end,:),castle,3); % 0 Wht,..., 3 Check\r\n  pmv=[pmv;mv(1:3)];\r\n  capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk\r\n   if mv(4)==0 % Normal moves and promotions\r\n    if b(mv(2))~=0,capture=true;end\r\n     b(mv(2))=b(mv(1)); % potential promotion\r\n     b(mv(1))=0;\r\n     if ismember(b(mv(2)),[1 7])\r\n      if ismember(mv(2),[1:8:57 8:8:64])\r\n       b(mv(2))=mv(3); % Place promoted selection\r\n      end\r\n     end\r\n     \r\n   else % ep or castle by White\r\n    if mv(4)==1 % castle 0-0 or 0-0-0\r\n      b(mv(1))=0;\r\n      b(mv(2))=6;\r\n      if mv(2)==24\r\n        b(8)=0;b(32)=2;  \r\n      else\r\n        b(64)=0;b(48)=2;\r\n      end    \r\n    end % castle\r\n    if mv(4)==2 % ep\r\n      capture=true;\r\n      b(mv(1))=0;\r\n      b(mv(2))=1; % White Pawn\r\n      b(mv(2)+1)=0; % Take pawn that passed\r\n    end % end ep\r\n   end % move implemented\r\n  end % end move\r\n  \r\n  %b % display board after move\r\n  \r\n  if isempty(find(b==12,1))\r\n   % Game over : Black King Captured\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer King; Player is Wht captured Blk King \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n   b_hist(no_capture,:,:)=b;\r\n  else\r\n   no_capture=1;\r\n   b_hist=b_hist*0;\r\n   b_hist(no_capture,:,:)=b;\r\n  end\r\n   \r\n  % Black Move\r\n  mvP=zeros(1,4); % [from to type/promote specials(castle=1/ep=2)] \r\n if computer_wht==0\r\n   [mvP]=Chezz_Shell(1,b,mvP,pmv,castle,2); % 2 Blk,... 2 is player\r\n  else\r\n   [mvP]=Chezz_Shell(1,b,mvP,pmv,castle,1); % 2 Blk  1 is Computer\r\n end\r\n  \r\n  [mv]=Chezz_Shell(1,b,mvP,pmv(end,:),castle,3); % 2 Blk,..., 3 Check\r\n  \r\n pmv=[pmv;mv(1:3)];\r\n capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk\r\n   if mv(4)==0 % Normal moves and promotions\r\n    if b(mv(2))~=0,capture=true;end\r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(b(mv(2)),[1 7])\r\n     if ismember(mv(2),[1:8:57 8:8:64])\r\n      b(mv(2))=mv(3); % Place promoted selection\r\n     end\r\n    end\r\n   else % ep or castle by Black\r\n    if mv(4)==1 % castle 0-0 or 0-0-0\r\n      b(mv(1))=0;\r\n      b(mv(2))=12;\r\n      if mv(2)==49 % Blk 0-0\r\n        b(57)=0;b(41)=8;  \r\n      else % Blk 0-0-0\r\n        b(1)=0;b(25)=8;\r\n      end    \r\n    end % castle\r\n    if mv(4)==2 % ep by Black\r\n      capture=true;\r\n      b(mv(1))=0;\r\n      b(mv(2))=mv(3);\r\n    % White passed black on prior move\r\n      b(mv(2)-1)=0; \r\n    end % end ep\r\n   end % move implemented\r\n  end % end move\r\n  \r\n%   b\r\n%   figure(1);imagesc(b,[0 12]);axis equal;\r\n  \r\n  if isempty(find(b==6,1))\r\n   % Game over : Blk captured White King\r\n   game_over=true;\r\n   if computer_wht==0 % Wht Computer King; Player is Blk captured Wht King\r\n    wins=wins+1;\r\n   end\r\n   continue\r\n  end\r\n  \r\n  castle=castle.*logical([b(8)==2 b(40) b(64)==2 b(1)==8 b(33) b(57)==8]);\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n   b_hist(no_capture,:,:)=b;\r\n   % Check for 3 position repetition\r\n   for i=1:no_capture-1\r\n    cdelta=0;\r\n    for j=i+1:no_capture\r\n     delta=(b_hist(i,:,:)-b_hist(j,:,:));\r\n     if sum(abs(delta(:)))==0\r\n      cdelta=cdelta+1;\r\n     end\r\n    end\r\n    if cdelta\u003e=7 % repetitions 3 identical setups\r\n     fprintf('Game over due to repetition\\n');\r\n     game_over=true;\r\n    end\r\n   end % rep check loop \r\n  else\r\n   no_capture=1;\r\n   b_hist=b_hist*0;\r\n   b_hist(no_capture,:,:)=b;\r\n  end % ~capture\r\n  \r\n end % While ~game_over\r\n \r\n end % wht_blk\r\n\r\npmvout2=pmv;\r\nwins\r\n \r\n% Player must win Twice to Pass\r\ntoc\r\nassert(isequal(wins,2))\r\n\r\n%%\r\nglobal pmvout1 pmvout2\r\n% Output moves for games\r\n\r\n% Output game 2 moves\r\npmv=pmvout1;\r\n   for i=2:3:size(pmv,1)-3\r\n    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));\r\n   end\r\n   fprintf('%2i %2i %2i\\n',pmv(end-2,:));\r\n   fprintf('%2i %2i %2i\\n',pmv(end-1,:));\r\n   fprintf('%2i %2i %2i\\n',pmv(end,:));\r\n \r\n% Output game 2 moves\r\npmv=pmvout2;\r\n for i=2:3:size(pmv,1)-3\r\n  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));\r\n  end\r\n% repeat of moves\r\n fprintf('%2i %2i %2i\\n',pmv(end-2,:));\r\n fprintf('%2i %2i %2i\\n',pmv(end-1,:));\r\n fprintf('%2i %2i %2i\\n',pmv(end,:));","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":"2012-12-27T22:40:04.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-24T04:58:57.000Z","updated_at":"2012-12-27T22:50:08.000Z","published_at":"2012-05-24T05:15:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz:...A simplified Chess game. Two game match with future multiple skill levels via evolutionary upgrades.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimplified the rules to implement rapid move check. Normal Chess moves like \\\"a4\\\", Castling, and En Passant are accepted. Moves are simple vectors [idx_from idx_to promo] where promo is for pawns reaching the 8th rank. Piece names are numeric 1-6 White (P,R,N,B,Q,K) and Black is 7-12. Board empty space is 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz unique rules: 1) To Win must remove opponent's King.. 2) Lose Turn if try an impossible move.. 3) Checks are ignored - allow move into check, castle out of check, castle thru/into check.. 4) Pawn promote to any piece, including opponent and vacuum.. 5) Six position repetition is a Draw..6) 50 moves No captures is a Draw..\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInputs:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (b,pmv,castle)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlayer always appears to be White. However, Black may apparently move first.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eb (8x8) array with empty=0, White Pieces 1-6, Blk Pieces 7-12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003epmv [from to promo] vector of both players moves (needed for en passant option). Illegal move creates a [0 0 0] pmv value. Size [2*moves,3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ecastle: 6 pt logical vector to show castling options. 1 if piece is eligible. Positions are [8 40 64 1 33 57] for [WQR WK WKR BQR BK BKR]. . . eg castle mv [40 56 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e mv [from to pawn_new_type] where from/to are 1-64 and pawn_new is 0 thru 12 if pawn is on final row.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test Suite will oversee two games with the Player as Black(moving second) and then as White.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ePassing:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Player must Win both games\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eEvolution:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Winning player algorithms will be hosted as Chezz_xyz based on their wins over other Chezz algorithms. Champions and the basis will be fully credited in Chezz updates. Champions must be able to play self and Not Cody timeout.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChezz_015: Pawn Serial Attack - Will capture and Promote\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLink update 12/27/12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":727,"title":"Checkerz_000 Kamikazi Kings","description":"Checkerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\r\n\r\nThe setup requires the player to copy the entire template into his solution.\r\n\r\nThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\r\n\r\nThe player writes his Bot under the player_move routine.\r\n\r\nThe player will always appear to be playing as White.\r\nThe players pieces are 1-Pawn and 2-King.\r\n\r\nThe Computer pieces will appear as 3-Pawn and 4-King.\r\n\r\nThe board is a standard 8x8 with empty squares as 0.\r\n\r\nThe player move is an array index from-to. eg mv=[8 15].  Value range 1 to 64.\r\n\r\nThe routine find_jumps will provide all potential jumps.\r\n\r\nIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\r\n\r\nAn invalid move or a missed jump is a Loss.\r\n\r\n*Input:* Board  8x8 array \r\n\r\n*Output:* Move  [index_from  index_to]\r\n\r\nTo Pass requires Winning Twice. Once as first move and once as second move.\r\n\r\n100 No-capture move series is a Draw\r\n\r\nMoves will be displayed\r\n\r\nCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.","description_html":"\u003cp\u003eCheckerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\u003c/p\u003e\u003cp\u003eThe setup requires the player to copy the entire template into his solution.\u003c/p\u003e\u003cp\u003eThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\u003c/p\u003e\u003cp\u003eThe player writes his Bot under the player_move routine.\u003c/p\u003e\u003cp\u003eThe player will always appear to be playing as White.\r\nThe players pieces are 1-Pawn and 2-King.\u003c/p\u003e\u003cp\u003eThe Computer pieces will appear as 3-Pawn and 4-King.\u003c/p\u003e\u003cp\u003eThe board is a standard 8x8 with empty squares as 0.\u003c/p\u003e\u003cp\u003eThe player move is an array index from-to. eg mv=[8 15].  Value range 1 to 64.\u003c/p\u003e\u003cp\u003eThe routine find_jumps will provide all potential jumps.\u003c/p\u003e\u003cp\u003eIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\u003c/p\u003e\u003cp\u003eAn invalid move or a missed jump is a Loss.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e Board  8x8 array\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e Move  [index_from  index_to]\u003c/p\u003e\u003cp\u003eTo Pass requires Winning Twice. Once as first move and once as second move.\u003c/p\u003e\u003cp\u003e100 No-capture move series is a Draw\u003c/p\u003e\u003cp\u003eMoves will be displayed\u003c/p\u003e\u003cp\u003eCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.\u003c/p\u003e","function_template":"function mv = Checkerz_Shell(wht_blk,b,mv,ptr)\r\n % Copy this into Players function entry\r\n %figure(1);imagesc(b,[-2 4]);axis equal\r\n %pause(0.1)\r\n \r\n % Remap routine so Engines always think they are White\r\n bv=zeros(8,8); % form of 8x8\r\n bv(1:64)=1:64;\r\n %pmap=(1:4); % [WP WK BP BK]\r\n if wht_blk==1 % Invert Player Perspective\r\n  [b,mv,bv]=ghost_white(b,mv,bv);\r\n end\r\n \r\n % Call Algorithm - White based\r\n % Un-Map to Black if required\r\n \r\n switch ptr\r\n     case {1}\r\n         mv=computer_move(b);\r\n% Self play\r\n% mv=player_move(b);\r\n     case {2}\r\n         mv=player_move(b);\r\n     case {3}\r\n         mv=mov_chk(b,mv);\r\n end % switch ptr\r\n \r\n %Remap mv to Black or leave unchanged if White\r\n if ismember(mv(1),1:64),mv(1)=bv(mv(1));end\r\n if ismember(mv(2),1:64),mv(2)=bv(mv(2));end\r\n \r\nend % Checkerz_Shell\r\n\r\nfunction [b,mv,bv]=ghost_white(b,mv,bv)\r\n% Map Blk to Wht to process \r\n  bv=rot90(rot90(bv)); % Board re-map\r\n  pmap=[3 4 1 2]; % Piece re-map to WP WK BP BK\r\n  \r\n  b=rot90(rot90(b));\r\n  v=find(b\u003e0);\r\n  b(v)=pmap(b(v));\r\n  \r\n  v=find(mv(1:2)\u003e0);\r\n  mv(v)=bv(mv(v));\r\n  \r\nend\r\n\r\nfunction [jv]=find_jumps(b)\r\n jv=[];\r\n P=find(b==1);\r\n K=find(b==2);\r\n \r\n Pjv=ones(64,2);\r\n Pjv = bsxfun(@times, Pjv, [-18 14]); % TL TR\r\n Pjv(1:18,:)=bsxfun(@times,Pjv(1:18,:),[0 1]);\r\n Pjv(2:8:58,:)=bsxfun(@times,Pjv(2:8:58,:),[0 0]);\r\n Pjv(50:64,:)=bsxfun(@times,Pjv(50:64,:),[1 0]);\r\n Pjv([1:2:7 10:2:16 17:2:23],:)=bsxfun(@times,Pjv([1:2:7 10:2:16 17:2:23],:),[0 0]);\r\n Pjv([26:2:32 33:2:39 42:2:48],:)=bsxfun(@times,Pjv([26:2:32 33:2:39 42:2:48],:),[0 0]);\r\n Pjv([49:2:55 58:2:64],:)=bsxfun(@times,Pjv([49:2:55 58:2:64],:),[0 0]);\r\n \r\n Kjv=ones(64,4);\r\n Kjv = bsxfun(@times, Kjv, [14 18 -14 -18]); % TR BR BL TL\r\n Kjv([2 9],:)=bsxfun(@times,Kjv([2 9],:),[0 1 0 0]);\r\n Kjv([4 6 11 13],:)=bsxfun(@times,Kjv([4 6 11 13],:),[1 1 0 0]);\r\n Kjv([8 15],:)=bsxfun(@times,Kjv([8 15],:),[1 0 0 0]);\r\n Kjv([18 25 34 41],:)=bsxfun(@times,Kjv([18 25 34 41],:),[0 1 1 0]);\r\n Kjv([24 31 40 47],:)=bsxfun(@times,Kjv([24 31 40 47],:),[1 0 0 1]);\r\n Kjv([50 57],:)=bsxfun(@times,Kjv([50 57],:),[0 0 1 0]);\r\n Kjv([52 54 59 61],:)=bsxfun(@times,Kjv([52 54 59 61],:),[0 0 1 1]);\r\n Kjv([56 63],:)=bsxfun(@times,Kjv([56 63],:),[0 0 0 1]);\r\n Kjv([1:2:7 10:2:16 17:2:23],:)=bsxfun(@times,Kjv([1:2:7 10:2:16 17:2:23],:),[0 0 0 0]);\r\n Kjv([26:2:32 33:2:39 42:2:48],:)=bsxfun(@times,Kjv([26:2:32 33:2:39 42:2:48],:),[0 0 0 0]);\r\n Kjv([49:2:55 58:2:64],:)=bsxfun(@times,Kjv([49:2:55 58:2:64],:),[0 0 0 0]);\r\n \r\n for i=1:length(P)\r\n  Pi=P(i);\r\n  for j=1:2\r\n   if Pjv(Pi,j)==0,continue;end\r\n   if b(Pi+Pjv(Pi,j))==0 \u0026\u0026 b(Pi+Pjv(Pi,j)/2)\u003e2\r\n    jv=[jv;Pi Pi+Pjv(Pi,j)];\r\n   end\r\n  end\r\n end\r\n \r\n \r\n \r\n for i=1:length(K)\r\n  Ki=K(i);\r\n  for j=1:4\r\n   if Kjv(Ki,j)==0,continue;end\r\n   if b(Ki+Kjv(Ki,j))==0 \u0026\u0026 b(Ki+Kjv(Ki,j)/2)\u003e2\r\n    jv=[jv;Ki K(i)+Kjv(Ki,j)];\r\n   end\r\n  end\r\n end\r\n\r\n \r\nend\r\n\r\n function mv=player_move(b)\r\n % Copy Checkerz_Shell, computer_move, and mov_chk functions into entry  \r\n % Create Player entry inside this function\r\n %\r\n % Author: Your Name\r\n % Bot name:  Your Bot's Nmae\r\n\r\n mv=[0 0]; % [from to] \r\n \r\n% Introduction function to avoid missing jumps\r\n% Player may modify. This is informational jumps only\r\n jv=find_jumps(b);\r\n if ~isempty(jv)\r\n  mv=jv(1,:); % Use the first jump\r\n  return\r\n end\r\n\r\n % End of Player entry\r\n end % End of Player Bot\r\n\r\nfunction mv=computer_move(b)\r\n% Author: Richard Z\r\n% Bot name: Kamikazi : Jump, Pmove, Kattack, Kmove \r\n% Checkerz_000\r\n mv=[0 0]; % [from to] \r\n \r\n jv=find_jumps(b);\r\n if ~isempty(jv)\r\n  mv=jv(1,:); % Use the first jump\r\n  return\r\n end\r\n\r\n % Pawn\r\n pv=find(b==1); % vector of Pawns\r\n %if ~isempty(pv),pv=pv(randperm(length(pv)));end\r\n ptr=0;\r\n while true % Pawn\r\n  pm=[-9 7];\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(pv),break;end\r\n  [r c]=ind2sub([8 8],pv(ptr));\r\n  if c==1, pm=pm.*[0 1];end\r\n  if c==8,pm=pm.*[1 0];end\r\n  \r\n  for i=1:2\r\n   if b(pv(ptr)+pm(i))==0\r\n    mv=[pv(ptr) pv(ptr)+pm(i)];\r\n    return\r\n   end\r\n  end\r\n end % while no move Pawn\r\n \r\n \r\n % No King capture move found\r\nmyk=find(b==2,1); % First King\r\nep=find(b\u003e2,1); %Find an enemy piece, Pawns or Kings\r\n[kr1 kc1]=ind2sub([8 8],myk);\r\n[er1 ec1]=ind2sub([8 8],ep);\r\nif er1\u003c=kr1 \u0026\u0026 ec1\u003e=kc1,king_mv=[7 9 -9 -7];end\r\nif er1\u003e=kr1 \u0026\u0026 ec1\u003e=kc1,king_mv=[9 7 -7 -9];end\r\nif er1\u003c=kr1 \u0026\u0026 ec1\u003c=kc1,king_mv=[-9 7 -7 9];end\r\nif er1\u003e=kr1 \u0026\u0026 ec1\u003c=kc1,king_mv=[-7 9 -9 7];end\r\nfor i=1:4\r\n if kr1==1 \u0026\u0026 ismember(king_mv(i),[-9 7]),continue;end\r\n if kr1==8 \u0026\u0026 ismember(king_mv(i),[-7 9]),continue;end\r\n if kc1==1 \u0026\u0026 ismember(king_mv(i),[-9 -7]),continue;end\r\n if kc1==8 \u0026\u0026 ismember(king_mv(i),[7 9]),continue;end\r\n if b(myk+king_mv(i))==0 % empty square\r\n  mv=[myk myk+king_mv(i)];\r\n  return; % path found\r\n end\r\nend\r\n \r\n% Can I get here if I have a King?\r\n % King\r\n kv=find(b==2); % vector of Kings\r\n %if ~isempty(pv),pv=pv(randperm(length(pv)));end\r\n ptr=0;\r\n while true % King\r\n  km=[7 9 -7 -9];\r\n  ptr=ptr+1;\r\n  if ptr\u003elength(kv),break;end\r\n  [r c]=ind2sub([8 8],kv(ptr));\r\n  if c==1, km=km.*[1 1 0 0];end\r\n  if c==8, km=km.*[0 0 1 1];end\r\n  if r==1, km=km.*[0 1 1 0];end\r\n  if r==8, km=km.*[1 0 0 1];end\r\n  \r\n  \r\n  for i=1:4\r\n   if b(kv(ptr)+km(i))==0\r\n    mv=[kv(ptr) kv(ptr)+km(i)];\r\n    return\r\n   end\r\n  end\r\n end % while no move King\r\n \r\n \r\n% Hopefully don't get here as mv=[0 0] and we lose\r\n\r\nend % End of Computer Bot\r\n\r\nfunction mv_out=mov_chk(b,mv)\r\n % Improvement of mov_chk will be a separate Cody challenge\r\n % Must Copy into Solution Entry\r\n % Invalid move returns [0 0]\r\n mv_out=[0 0]; % default is Invalid\r\n \r\n % verify valid: Entry, Color, Possible capture\r\n if ~ismember(mv(1),1:64) || ~ismember(mv(2),1:64),return;end % Invalid mv\r\n if ~ismember(b(mv(1)),(1:2)),return;end % Moving Wrong team\r\n  % Must move to empty square\r\n if b(mv(2))~=0,return;end\r\n \r\n  \r\n delta=mv(2)-mv(1); % Movement vector\r\n if ~ismember(delta,[7 9 14 18 -7 -9 -14 -18]),return;end % Invalid mv\r\n \r\n msum=mv(1)+mv(2); % Jump midpoint if jump check\r\n \r\n  % use for move checks\r\n [r1 c1]=ind2sub([8 8],mv(1));\r\n [r2 c2]=ind2sub([8 8],mv(2));\r\n \r\n if abs(r1-r2)\u003e2,return;end % Invalid\r\n if abs(c1-c2)\u003e2,return;end % Invalid\r\n   \r\n jv=find_jumps(b);\r\n\r\n if ~isempty(jv)\r\n  if abs(delta)\u003c14,return;end % Jump not executed\r\n end\r\n \r\n \r\n if abs(delta)\u003e13 % Jump claimed\r\n  if b(msum/2)\u003c3,return;end % Invalid Jump -Own or Empty\r\n  \r\n  if b(mv(1))==1 \u0026\u0026 (delta==-18 ||delta==14)\r\n   mv_out=mv; % Valid move\r\n   return;\r\n  end % Legal P Jump\r\n  \r\n  if b(mv(1))==2 \u0026\u0026 (abs(delta)==18 || abs(delta)==14)\r\n   mv_out=mv; % Valid move\r\n   return;\r\n  end % Legal K Jump\r\n  \r\n  return; % Invalid Jump\r\n end % Jump\r\n \r\n % abs(delta)\u003c12 Regular move\r\n if b(mv(1))==1 \u0026\u0026 (delta==-9 ||delta==7)\r\n  mv_out=mv; % Valid move\r\n  return;\r\n end % Legal P mv\r\n \r\n if b(mv(1))==2 \u0026\u0026 (abs(delta)==9 || abs(delta) ==7)\r\n  mv_out=mv; % Valid move\r\n  return;\r\n end % Legal K mv\r\n \r\n mv_out=[0 0]; % Checks failed\r\nend\r\n","test_suite":"%%\r\n%Test Suite\r\ntic\r\n wins=0; % player wins\r\n b=zeros(8);% WP 1 BP 3  [WK 2 BK 4] \r\n b([2 9 11 18 25 27 34 41 43 50 57 59])=3;\r\n b([6 8 15 22 24 31 38 40 47 54 56 63])=1;\r\n b_orig=b;\r\n \r\n %mv=zeros(1,2); % [from to promo)]  \r\n %computer_wht=0; % 0 Computer plays wht\r\n %computer_wht=1; % 1 Computer plays black\r\n \r\n pmv=zeros(1,2); % Move History for record only\r\n  \r\n for computer_wht=0:1\r\n  if size(pmv,1)\u003e3\r\n   for i=1:4:size(pmv,1)-4\r\n    fprintf('%2i %2i %2i %2i %2i %2i %2i %2i\\n',pmv(i,1:2),pmv(i+1,1:2),pmv(i+2,1:2),pmv(i+3,1:2));\r\n   end\r\n   fprintf('%2i %2i\\n',pmv(end-3,:));\r\n   fprintf('%2i %2i\\n',pmv(end-2,:));\r\n   fprintf('%2i %2i\\n',pmv(end-1,:));\r\n   fprintf('%2i %2i\\n',pmv(end,:));\r\n % Output game 1 moves\r\n  end\r\n  %pmv % Output move history from Game 1\r\n  game_over=false;\r\n  b=b_orig; % Reset for second game\r\n  no_capture=0;\r\n  pmv=zeros(1,2); % [from to promo)] Opponents last move\r\n \r\n while ~game_over\r\n  mvP=zeros(1,2); % [from to] \r\n  % Shell 0=Blk,1=Wht;Board;move,prev move;\r\n  % function (1 Play Comp, 2 Player, 3 Check mv)\r\n  \r\n  % White move\r\n  if computer_wht==0\r\n   [mvP]=Checkerz_Shell(0,b,mvP,1); % 0 Wht,... 1 Computer\r\n  else\r\n   [mvP]=Checkerz_Shell(0,b,mvP,2); % 0 Wht  2 is player\r\n  end\r\n  \r\n  [mv]=Checkerz_Shell(0,b,mvP,3); % 0 Wht,..., 3 Check\r\n  \r\n  pmv=[pmv;mv(1:2)];\r\n  capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk \r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(mv(2),[9 25 41 57])\r\n     b(mv(2))=2; % Kinged\r\n    end\r\n    if abs(mv(1)-mv(2))\u003e9\r\n     % Piece jumped\r\n     capture=true;\r\n     b((mv(1)+mv(2))/2)=0;\r\n    end\r\n  end % end move\r\n  \r\n  if isempty(find(b\u003e2)) % White has captured All Blk Pieces\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer Loses; Player is Wht \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if mv(1)==0 % No legal move or missed jump\r\n   % Game over : White failed to move and Loses\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==0 % Wht Computer Loses; Player is Blk \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n    \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end %\r\n  else\r\n   no_capture=1;\r\n  end\r\n   \r\n  % Black Move\r\n  mvP=[0 0]; % [from to type/promote specials(castle=1/ep=2)] \r\n if computer_wht==0\r\n   [mvP]=Checkerz_Shell(1,b,mvP,2); % 2 Blk,... 2 is player\r\n  else\r\n   [mvP]=Checkerz_Shell(1,b,mvP,1); % 2 Blk  1 is Computer\r\n end\r\n  \r\n  [mv]=Checkerz_Shell(1,b,mvP,3); % 2 Blk,..., 3 Check\r\n  \r\n pmv=[pmv;mv(1:2)];\r\n \r\n capture=false;\r\n  % Board changes only occur in Suite code\r\n  if mv(1)~=0 % Valid move determined by mv_chk \r\n    b(mv(2))=b(mv(1)); % potential promotion\r\n    b(mv(1))=0;\r\n    if ismember(mv(2),[8 24 40 56])\r\n     b(mv(2))=4; % Kinged\r\n    end\r\n    if abs(mv(1)-mv(2))\u003e9\r\n     % Piece jumped\r\n     capture=true;\r\n     b((mv(1)+mv(2))/2)=0;\r\n    end\r\n  end % end move\r\n  \r\n  if isempty([find(b==1)' find(b==2)']) % Black has captured All Wht Pieces\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==0 % Wht Computer Loses; Player is Blk \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if mv(1)==0 % No legal move or missed jump by Black\r\n   % Game over : Black failed to move correctly and Loses\r\n   game_over=true; % change to if comp=wht or blk for win\r\n   if computer_wht==1 % Blk Computer Loses; Player is Wht \r\n    wins=wins+1;\r\n   end\r\n   continue;\r\n  end\r\n  \r\n  if ~capture\r\n   no_capture=no_capture+1;\r\n   if no_capture\u003e100\r\n       fprintf('Draw 100 moves no capture\\n');\r\n       game_over=true;\r\n   end % move is b and w\r\n  else\r\n   no_capture=1;\r\n  end % ~capture\r\n  \r\n end % While ~game_over\r\n \r\n end % wht_blk\r\n \r\n wins\r\n   if size(pmv,1)\u003e3\r\n    for i=1:4:size(pmv,1)-4\r\n     fprintf('%2i %2i %2i %2i %2i %2i %2i %2i\\n',pmv(i,1:2),pmv(i+1,1:2),pmv(i+2,1:2),pmv(i+3,1:2));\r\n    end\r\n    fprintf('%2i %2i\\n',pmv(end-3,:));\r\n    fprintf('%2i %2i\\n',pmv(end-2,:));\r\n    fprintf('%2i %2i\\n',pmv(end-1,:));\r\n    fprintf('%2i %2i\\n',pmv(end,:));\r\n % Output game 2 moves?\r\n  end\r\n \r\nwins\r\ntoc\r\n\r\n % Player must beat computer twice\r\n %assert(isequal(wins,2))\r\n \r\nPass=1;\r\nassert(isequal(Pass,1))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":3,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-30T03:08:30.000Z","updated_at":"2012-05-30T03:20:09.000Z","published_at":"2012-05-30T03:17:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheckerz: A simplified single jump checkers game between a computer bot and a player bot. Multiple jumps are not allowed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe setup requires the player to copy the entire template into his solution.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe template includes a Shell routine that call the Player, Computer, and the Jump Check routines for move validation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player writes his Bot under the player_move routine.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player will always appear to be playing as White. The players pieces are 1-Pawn and 2-King.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Computer pieces will appear as 3-Pawn and 4-King.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe board is a standard 8x8 with empty squares as 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe player move is an array index from-to. eg mv=[8 15]. Value range 1 to 64.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe routine find_jumps will provide all potential jumps.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf a jump(s) may occur then one must be used. eg mv=[8 22] which jumps a piece on 15.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAn invalid move or a missed jump is a Loss.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Board 8x8 array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Move [index_from index_to]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo Pass requires Winning Twice. Once as first move and once as second move.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e100 No-capture move series is a Draw\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMoves will be displayed\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheckerz_000 Kamikazi_Kings: Random Pawn moves and Kings will hunt the enemy.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"mulit-call\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"mulit-call\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mulit-call\"","","\"","mulit-call","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdd46d43840\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdd46d437a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdd46d42e40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdd46d43ac0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdd46d43a20\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdd46d43980\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdd46d438e0\u003e":"tag:\"mulit-call\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdd46d438e0\u003e":"tag:\"mulit-call\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"mulit-call\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"mulit-call\"","","\"","mulit-call","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdd46d43840\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdd46d437a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdd46d42e40\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdd46d43ac0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdd46d43a20\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdd46d43980\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdd46d438e0\u003e":"tag:\"mulit-call\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdd46d438e0\u003e":"tag:\"mulit-call\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":715,"difficulty_rating":"unrated"},{"id":727,"difficulty_rating":"unrated"}]}}