{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-26T00:14:02.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-26T00: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":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":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:\"checkerz\"","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:\"checkerz\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"checkerz\"","","\"","checkerz","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1400\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b12c0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f3d8d7bf8c8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1680\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b15e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1540\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f3d8f3b14a0\u003e":"tag:\"checkerz\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b14a0\u003e":"tag:\"checkerz\""},"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:\"checkerz\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"checkerz\"","","\"","checkerz","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1400\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b12c0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f3d8d7bf8c8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1680\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b15e0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f3d8f3b1540\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f3d8f3b14a0\u003e":"tag:\"checkerz\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f3d8f3b14a0\u003e":"tag:\"checkerz\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":727,"difficulty_rating":"unrated"}]}}