{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.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":"2025-12-14T00: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":700,"title":"Monty Hall","description":"The classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens. \r\n\r\nThe contestant picks a Door: 1 2 or 3.\r\n\r\nMonty then reveals a Door that is Not the winner.\r\n\r\nAs the contestant do you stay with your original Door or swap to the other Door?\r\n\r\nYour routine will be called twice. \r\n\r\nThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\r\n\r\nThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\r\n\r\nYou may now choose Door 1 (no change) or switch to the available door denoted by the zero. \r\n\r\nReturn an Integer 1, 2, or 3\r\n\r\nExample:\r\n\r\nInput [0 0 0]\r\n\r\nOutput 2\r\n\r\nInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\r\n\r\nOutput 1  % This selects Door 1, swapping from Door 2\r\n\r\nThe Test engine will determine if your final selection is a Winner\r\n\r\nThe routine will run the game 100 times calling your function twice for every game.\r\n\r\nYour Strategy \"Passes\" if it wins \u003e 50% of the time.\r\n\r\nThis is the first in a series of planned interactive Games.\r\n\r\nThis example is also to demonstrate Cody multi-call interactivity capability.\r\n\r\n\r\nLet's Make a Deal","description_html":"\u003cp\u003eThe classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/p\u003e\u003cp\u003eThe contestant picks a Door: 1 2 or 3.\u003c/p\u003e\u003cp\u003eMonty then reveals a Door that is Not the winner.\u003c/p\u003e\u003cp\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/p\u003e\u003cp\u003eYour routine will be called twice.\u003c/p\u003e\u003cp\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/p\u003e\u003cp\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/p\u003e\u003cp\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/p\u003e\u003cp\u003eReturn an Integer 1, 2, or 3\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput [0 0 0]\u003c/p\u003e\u003cp\u003eOutput 2\u003c/p\u003e\u003cp\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/p\u003e\u003cp\u003eOutput 1  % This selects Door 1, swapping from Door 2\u003c/p\u003e\u003cp\u003eThe Test engine will determine if your final selection is a Winner\u003c/p\u003e\u003cp\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/p\u003e\u003cp\u003eYour Strategy \"Passes\" if it wins \u003e 50% of the time.\u003c/p\u003e\u003cp\u003eThis is the first in a series of planned interactive Games.\u003c/p\u003e\u003cp\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/p\u003e\u003cp\u003eLet's Make a Deal\u003c/p\u003e","function_template":"function y = Monty(doors)\r\n% First call will see doors=[0 0 0]\r\n% Second call will see a permutation of [0 1 2], depending on first response\r\n% In the second call the \"2\" denotes a revealed Losing door\r\n  y = 1;\r\nend","test_suite":"%%\r\nwin=0;\r\nPass=0;\r\nfor i=1:100\r\n    \r\n prize=randi(3);\r\n doors=[0 0 0];\r\n \r\n pick=Monty(doors);\r\n \r\n pick=floor(pick);\r\n if pick\u003c1 || pick\u003e3\r\n  win=0;\r\n  break;\r\n else\r\n  doors(pick)=1;\r\n end\r\n \r\n if pick==prize\r\n % Random select from other doors\r\n  if rand\u003e0.5\r\n   doors(find(doors==0,1))=2;\r\n  else\r\n   doors(find(doors==0,1,'last'))=2;\r\n  end\r\n else % \r\n % Pick other and not prize door\r\n  reveal=setxor(prize,setxor(pick,[1 2 3]));\r\n  doors(reveal)=2;\r\n end\r\n \r\n pick=Monty(doors);\r\n\r\n pick=floor(pick);\r\n if pick==prize\r\n  win=win+1;\r\n end\r\n \r\n \r\nend % Monty Loops\r\nwin % Display number of wins\r\nif win\u003e50,Pass=1;end\r\nassert(isequal(Pass,1))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T08:52:15.000Z","updated_at":"2026-03-24T13:29:28.000Z","published_at":"2012-05-19T08:52:15.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eThe classic Monty Hall \\\"Let's Make a Deal\\\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe contestant picks a Door: 1 2 or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMonty then reveals a Door that is Not the winner.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour routine will be called twice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an Integer 1, 2, or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 0 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 1 % This selects Door 1, swapping from Door 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test engine will determine if your final selection is a Winner\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Strategy \\\"Passes\\\" if it wins \u003e 50% of the time.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first in a series of planned interactive 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's Make a Deal\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":701,"title":"Play Tic-Tac-Toe: Easy Bots","description":"Interactive Tic-Tac-Toe game versus the test suite algorithms.\r\n\r\nThe contest will be 50 games of Computer first and 50 games of Player first.\r\n\r\nThe tic-tac-bots are not strong and are named Up, Down, and Random.\r\n\r\nInitial board is zeros(3).\r\nComputer moves are 1s and Player moves are 2s.\r\n\r\nPlayer output is an integer 1:9 to identify array position\r\n\r\n1 4 7\r\n\r\n2 5 8\r\n\r\n3 6 9\r\n\r\nExamples:\r\n\r\nInput: [1 0 0;0 0 0;0 0 0]  % Computer first case\r\n\r\nOutput: 5\r\n\r\nYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\r\n\r\nSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\r\n\r\n.\r\n\r\nPassing Score is 66 Wins out of 100 games.\r\n\r\nIt may be possible to score 100 Wins against the tic-tac-bots.\r\n\r\nYour Total Wins will be displayed.\r\n\r\nA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\r\n\r\n","description_html":"\u003cp\u003eInteractive Tic-Tac-Toe game versus the test suite algorithms.\u003c/p\u003e\u003cp\u003eThe contest will be 50 games of Computer first and 50 games of Player first.\u003c/p\u003e\u003cp\u003eThe tic-tac-bots are not strong and are named Up, Down, and Random.\u003c/p\u003e\u003cp\u003eInitial board is zeros(3).\r\nComputer moves are 1s and Player moves are 2s.\u003c/p\u003e\u003cp\u003ePlayer output is an integer 1:9 to identify array position\u003c/p\u003e\u003cp\u003e1 4 7\u003c/p\u003e\u003cp\u003e2 5 8\u003c/p\u003e\u003cp\u003e3 6 9\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cp\u003eInput: [1 0 0;0 0 0;0 0 0]  % Computer first case\u003c/p\u003e\u003cp\u003eOutput: 5\u003c/p\u003e\u003cp\u003eYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\u003c/p\u003e\u003cp\u003eSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\u003c/p\u003e\u003cp\u003e.\u003c/p\u003e\u003cp\u003ePassing Score is 66 Wins out of 100 games.\u003c/p\u003e\u003cp\u003eIt may be possible to score 100 Wins against the tic-tac-bots.\u003c/p\u003e\u003cp\u003eYour Total Wins will be displayed.\u003c/p\u003e\u003cp\u003eA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\u003c/p\u003e","function_template":"function p = tic_tac_toe(x)\r\n  p = 1;\r\nend","test_suite":"%%\r\n%Tic-Tac-Toe \r\n%Demonstration of Multi-Call with adaptive response\r\n\r\nwins=0;\r\nPass=0;\r\nfor i=1:50 % Computer First;  51-100 will be Player First\r\n x=zeros(3);\r\n while true % exit on win or filled board\r\n  if i\u003c16 % Up bot\r\n   p=find(x==0,1);\r\n  elseif i\u003c31 % Down bot\r\n   p=find(x==0,1,'last');\r\n  else % 31 thru 50 % random bot\r\n   found=0;\r\n   while ~found\r\n    p=floor(9*rand)+1;\r\n    if x(p)==0,break;end\r\n   end\r\n  end\r\n  % Implement Computer move and Check for Win\r\n  x(p)=1;\r\n  wt=x;\r\n  wt(wt==2)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==3);\r\n  if win,break;end % Computer Wins on its move\r\n  \r\n  % Draw check Post computer move (9th move)\r\n  if sum(x(:))\u003e=13,break;end\r\n  \r\n  % Implement player move and Check for Win\r\n  p=tic_tac_toe(x);\r\n  p=p(1);\r\n  if x(p)~=0,break;end % Invalid move - Game over\r\n  x(p)=2;\r\n  wt=x;\r\n  wt(wt==1)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==6);\r\n  if win\r\n   wins=wins+1;\r\n   break;\r\n  end % Player Wins on their move\r\n  \r\n  \r\n end % gameover while 1:50\r\nend % Games 1:50\r\n\r\n% Output wins against Computer first\r\nwins\r\n\r\nfor i=51:100 % Player First;  51-100 Player First\r\n x=zeros(3);\r\n while true % exit on win or filled board\r\n  % Implement player move and Check for Win\r\n  p=tic_tac_toe(x);\r\n  p=p(1);\r\n  if x(p)~=0,break;end % Invalid move - Game over\r\n  x(p)=2;\r\n  wt=x;\r\n  wt(wt==1)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==6);\r\n  if win\r\n   wins=wins+1;\r\n   break;\r\n  end % Player Wins on their move   \r\n  \r\n  % Draw check Post computer move (9th move)\r\n  if sum(x(:))\u003e=13,break;end\r\n     \r\n  if i\u003c66 % Up bot\r\n   p=find(x==0,1);\r\n  elseif i\u003c81 % Down bot\r\n   p=find(x==0,1,'last');\r\n  else % 31 thru 50 % random bot\r\n   found=0;\r\n   while ~found\r\n    p=floor(9*rand)+1;\r\n    if x(p)==0,break;end\r\n   end\r\n  end\r\n  % Implement Computer move and Check for Win\r\n  x(p)=1;\r\n  wt=x;\r\n  wt(wt==2)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==3);\r\n  if win,break;end % Computer Wins on its move\r\n   \r\n end % gameover while 51:100\r\nend % Games 51:100\r\n\r\nwins\r\n\r\nif wins\u003e65,Pass=1;end\r\nassert(isequal(Pass,1))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2012-06-03T19:49:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T15:10:18.000Z","updated_at":"2026-01-03T17:04:22.000Z","published_at":"2012-05-19T16:47:46.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInteractive Tic-Tac-Toe game versus the test suite algorithms.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe contest will be 50 games of Computer first and 50 games of Player 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe tic-tac-bots are not strong and are named Up, Down, and Random.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInitial board is zeros(3). Computer moves are 1s and Player moves are 2s.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlayer output is an integer 1:9 to identify array position\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 4 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 5 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3 6 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: [1 0 0;0 0 0;0 0 0] % Computer first case\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePassing Score is 66 Wins out of 100 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt may be possible to score 100 Wins against the tic-tac-bots.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Total Wins 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\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":714,"title":"Chezz_000 : 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_000: Makes no moves or captures - The weakest player possible\r\n\r\nLinks updated 12/27/12\r\n\r\n","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_000: Makes no moves or captures - The weakest player possible\u003c/p\u003e\u003cp\u003eLinks updated 12/27/12\u003c/p\u003e","function_template":"function mv=player_move(b,pmv,castle)\r\n% Author: Richard Z\r\n% Bot name: Do Nothing\r\n% Chezz_000\r\n%Chezz_000 bot is no legal moves mv=[0 0 0]\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% example: mv =[39 37 0] is e4\r\n% pmv (move,from to promo) is used for en passant\r\n% [0 0 0] is invalid move or first move of game\r\n% castle vector is used to castle yourself or see if opponent may castle\r\n \r\n% This is the computer's algorithm - Going for a draw\r\n mv=zeros(1,3); % [from to promo] \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_move000.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":2,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2012-12-27T22:34:39.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-24T02:22:59.000Z","updated_at":"2025-02-01T14:24:16.000Z","published_at":"2012-05-24T04:50:47.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_000: Makes no moves or captures - The weakest player possible\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\u003eLinks updated 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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":700,"title":"Monty Hall","description":"The classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens. \r\n\r\nThe contestant picks a Door: 1 2 or 3.\r\n\r\nMonty then reveals a Door that is Not the winner.\r\n\r\nAs the contestant do you stay with your original Door or swap to the other Door?\r\n\r\nYour routine will be called twice. \r\n\r\nThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\r\n\r\nThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\r\n\r\nYou may now choose Door 1 (no change) or switch to the available door denoted by the zero. \r\n\r\nReturn an Integer 1, 2, or 3\r\n\r\nExample:\r\n\r\nInput [0 0 0]\r\n\r\nOutput 2\r\n\r\nInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\r\n\r\nOutput 1  % This selects Door 1, swapping from Door 2\r\n\r\nThe Test engine will determine if your final selection is a Winner\r\n\r\nThe routine will run the game 100 times calling your function twice for every game.\r\n\r\nYour Strategy \"Passes\" if it wins \u003e 50% of the time.\r\n\r\nThis is the first in a series of planned interactive Games.\r\n\r\nThis example is also to demonstrate Cody multi-call interactivity capability.\r\n\r\n\r\nLet's Make a Deal","description_html":"\u003cp\u003eThe classic Monty Hall \"Let's Make a Deal\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/p\u003e\u003cp\u003eThe contestant picks a Door: 1 2 or 3.\u003c/p\u003e\u003cp\u003eMonty then reveals a Door that is Not the winner.\u003c/p\u003e\u003cp\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/p\u003e\u003cp\u003eYour routine will be called twice.\u003c/p\u003e\u003cp\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 3.\u003c/p\u003e\u003cp\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/p\u003e\u003cp\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/p\u003e\u003cp\u003eReturn an Integer 1, 2, or 3\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput [0 0 0]\u003c/p\u003e\u003cp\u003eOutput 2\u003c/p\u003e\u003cp\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/p\u003e\u003cp\u003eOutput 1  % This selects Door 1, swapping from Door 2\u003c/p\u003e\u003cp\u003eThe Test engine will determine if your final selection is a Winner\u003c/p\u003e\u003cp\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/p\u003e\u003cp\u003eYour Strategy \"Passes\" if it wins \u003e 50% of the time.\u003c/p\u003e\u003cp\u003eThis is the first in a series of planned interactive Games.\u003c/p\u003e\u003cp\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/p\u003e\u003cp\u003eLet's Make a Deal\u003c/p\u003e","function_template":"function y = Monty(doors)\r\n% First call will see doors=[0 0 0]\r\n% Second call will see a permutation of [0 1 2], depending on first response\r\n% In the second call the \"2\" denotes a revealed Losing door\r\n  y = 1;\r\nend","test_suite":"%%\r\nwin=0;\r\nPass=0;\r\nfor i=1:100\r\n    \r\n prize=randi(3);\r\n doors=[0 0 0];\r\n \r\n pick=Monty(doors);\r\n \r\n pick=floor(pick);\r\n if pick\u003c1 || pick\u003e3\r\n  win=0;\r\n  break;\r\n else\r\n  doors(pick)=1;\r\n end\r\n \r\n if pick==prize\r\n % Random select from other doors\r\n  if rand\u003e0.5\r\n   doors(find(doors==0,1))=2;\r\n  else\r\n   doors(find(doors==0,1,'last'))=2;\r\n  end\r\n else % \r\n % Pick other and not prize door\r\n  reveal=setxor(prize,setxor(pick,[1 2 3]));\r\n  doors(reveal)=2;\r\n end\r\n \r\n pick=Monty(doors);\r\n\r\n pick=floor(pick);\r\n if pick==prize\r\n  win=win+1;\r\n end\r\n \r\n \r\nend % Monty Loops\r\nwin % Display number of wins\r\nif win\u003e50,Pass=1;end\r\nassert(isequal(Pass,1))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T08:52:15.000Z","updated_at":"2026-03-24T13:29:28.000Z","published_at":"2012-05-19T08:52:15.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eThe classic Monty Hall \\\"Let's Make a Deal\\\" final showcase puzzle pits the contestant against three Doors. Behind one Door are dream prizes and behind the other two are Donkeys and Chickens.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe contestant picks a Door: 1 2 or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMonty then reveals a Door that is Not the winner.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs the contestant do you stay with your original Door or swap to the other Door?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour routine will be called twice.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first time it will see [0 0 0]. You are to select a Door: return an Integer 1,2 or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second time your function will see [1 2 0] or [1 0 2],if you had selected door number 1. The 2 denotes a revealed Losing Door.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may now choose Door 1 (no change) or switch to the available door denoted by the zero.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn an Integer 1, 2, or 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 0 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput [0 1 2] % Your first selection is denoted by 1. 2 is a losing Door\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput 1 % This selects Door 1, swapping from Door 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Test engine will determine if your final selection is a Winner\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe routine will run the game 100 times calling your function twice for every game.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Strategy \\\"Passes\\\" if it wins \u003e 50% of the time.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the first in a series of planned interactive 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis example is also to demonstrate Cody multi-call interactivity capability.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's Make a Deal\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":701,"title":"Play Tic-Tac-Toe: Easy Bots","description":"Interactive Tic-Tac-Toe game versus the test suite algorithms.\r\n\r\nThe contest will be 50 games of Computer first and 50 games of Player first.\r\n\r\nThe tic-tac-bots are not strong and are named Up, Down, and Random.\r\n\r\nInitial board is zeros(3).\r\nComputer moves are 1s and Player moves are 2s.\r\n\r\nPlayer output is an integer 1:9 to identify array position\r\n\r\n1 4 7\r\n\r\n2 5 8\r\n\r\n3 6 9\r\n\r\nExamples:\r\n\r\nInput: [1 0 0;0 0 0;0 0 0]  % Computer first case\r\n\r\nOutput: 5\r\n\r\nYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\r\n\r\nSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\r\n\r\n.\r\n\r\nPassing Score is 66 Wins out of 100 games.\r\n\r\nIt may be possible to score 100 Wins against the tic-tac-bots.\r\n\r\nYour Total Wins will be displayed.\r\n\r\nA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\r\n\r\n","description_html":"\u003cp\u003eInteractive Tic-Tac-Toe game versus the test suite algorithms.\u003c/p\u003e\u003cp\u003eThe contest will be 50 games of Computer first and 50 games of Player first.\u003c/p\u003e\u003cp\u003eThe tic-tac-bots are not strong and are named Up, Down, and Random.\u003c/p\u003e\u003cp\u003eInitial board is zeros(3).\r\nComputer moves are 1s and Player moves are 2s.\u003c/p\u003e\u003cp\u003ePlayer output is an integer 1:9 to identify array position\u003c/p\u003e\u003cp\u003e1 4 7\u003c/p\u003e\u003cp\u003e2 5 8\u003c/p\u003e\u003cp\u003e3 6 9\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cp\u003eInput: [1 0 0;0 0 0;0 0 0]  % Computer first case\u003c/p\u003e\u003cp\u003eOutput: 5\u003c/p\u003e\u003cp\u003eYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\u003c/p\u003e\u003cp\u003eSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\u003c/p\u003e\u003cp\u003e.\u003c/p\u003e\u003cp\u003ePassing Score is 66 Wins out of 100 games.\u003c/p\u003e\u003cp\u003eIt may be possible to score 100 Wins against the tic-tac-bots.\u003c/p\u003e\u003cp\u003eYour Total Wins will be displayed.\u003c/p\u003e\u003cp\u003eA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\u003c/p\u003e","function_template":"function p = tic_tac_toe(x)\r\n  p = 1;\r\nend","test_suite":"%%\r\n%Tic-Tac-Toe \r\n%Demonstration of Multi-Call with adaptive response\r\n\r\nwins=0;\r\nPass=0;\r\nfor i=1:50 % Computer First;  51-100 will be Player First\r\n x=zeros(3);\r\n while true % exit on win or filled board\r\n  if i\u003c16 % Up bot\r\n   p=find(x==0,1);\r\n  elseif i\u003c31 % Down bot\r\n   p=find(x==0,1,'last');\r\n  else % 31 thru 50 % random bot\r\n   found=0;\r\n   while ~found\r\n    p=floor(9*rand)+1;\r\n    if x(p)==0,break;end\r\n   end\r\n  end\r\n  % Implement Computer move and Check for Win\r\n  x(p)=1;\r\n  wt=x;\r\n  wt(wt==2)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==3);\r\n  if win,break;end % Computer Wins on its move\r\n  \r\n  % Draw check Post computer move (9th move)\r\n  if sum(x(:))\u003e=13,break;end\r\n  \r\n  % Implement player move and Check for Win\r\n  p=tic_tac_toe(x);\r\n  p=p(1);\r\n  if x(p)~=0,break;end % Invalid move - Game over\r\n  x(p)=2;\r\n  wt=x;\r\n  wt(wt==1)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==6);\r\n  if win\r\n   wins=wins+1;\r\n   break;\r\n  end % Player Wins on their move\r\n  \r\n  \r\n end % gameover while 1:50\r\nend % Games 1:50\r\n\r\n% Output wins against Computer first\r\nwins\r\n\r\nfor i=51:100 % Player First;  51-100 Player First\r\n x=zeros(3);\r\n while true % exit on win or filled board\r\n  % Implement player move and Check for Win\r\n  p=tic_tac_toe(x);\r\n  p=p(1);\r\n  if x(p)~=0,break;end % Invalid move - Game over\r\n  x(p)=2;\r\n  wt=x;\r\n  wt(wt==1)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==6);\r\n  if win\r\n   wins=wins+1;\r\n   break;\r\n  end % Player Wins on their move   \r\n  \r\n  % Draw check Post computer move (9th move)\r\n  if sum(x(:))\u003e=13,break;end\r\n     \r\n  if i\u003c66 % Up bot\r\n   p=find(x==0,1);\r\n  elseif i\u003c81 % Down bot\r\n   p=find(x==0,1,'last');\r\n  else % 31 thru 50 % random bot\r\n   found=0;\r\n   while ~found\r\n    p=floor(9*rand)+1;\r\n    if x(p)==0,break;end\r\n   end\r\n  end\r\n  % Implement Computer move and Check for Win\r\n  x(p)=1;\r\n  wt=x;\r\n  wt(wt==2)=0;\r\n  win=any([sum(wt) sum(wt,2)' trace(wt) trace(fliplr(wt))]==3);\r\n  if win,break;end % Computer Wins on its move\r\n   \r\n end % gameover while 51:100\r\nend % Games 51:100\r\n\r\nwins\r\n\r\nif wins\u003e65,Pass=1;end\r\nassert(isequal(Pass,1))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":"2012-06-03T19:49:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-19T15:10:18.000Z","updated_at":"2026-01-03T17:04:22.000Z","published_at":"2012-05-19T16:47:46.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInteractive Tic-Tac-Toe game versus the test suite algorithms.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe contest will be 50 games of Computer first and 50 games of Player 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe tic-tac-bots are not strong and are named Up, Down, and Random.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInitial board is zeros(3). Computer moves are 1s and Player moves are 2s.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlayer output is an integer 1:9 to identify array position\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1 4 7\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e2 5 8\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e3 6 9\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExamples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: [1 0 0;0 0 0;0 0 0] % Computer first case\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYields : [1 0 0; 0 2 0;0 0 0] with computer then picking position 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSecond Input: [1 0 0;1 2 0;0 0 0] with computer's second move shown\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePassing Score is 66 Wins out of 100 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIt may be possible to score 100 Wins against the tic-tac-bots.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour Total Wins 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA follow-on problem will be 100 Tic-Tac-Toe Games: Never Lose Challenge\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":714,"title":"Chezz_000 : 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_000: Makes no moves or captures - The weakest player possible\r\n\r\nLinks updated 12/27/12\r\n\r\n","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_000: Makes no moves or captures - The weakest player possible\u003c/p\u003e\u003cp\u003eLinks updated 12/27/12\u003c/p\u003e","function_template":"function mv=player_move(b,pmv,castle)\r\n% Author: Richard Z\r\n% Bot name: Do Nothing\r\n% Chezz_000\r\n%Chezz_000 bot is no legal moves mv=[0 0 0]\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% example: mv =[39 37 0] is e4\r\n% pmv (move,from to promo) is used for en passant\r\n% [0 0 0] is invalid move or first move of game\r\n% castle vector is used to castle yourself or see if opponent may castle\r\n \r\n% This is the computer's algorithm - Going for a draw\r\n mv=zeros(1,3); % [from to promo] \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_move000.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":2,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":"2012-12-27T22:34:39.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-24T02:22:59.000Z","updated_at":"2025-02-01T14:24:16.000Z","published_at":"2012-05-24T04:50:47.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_000: Makes no moves or captures - The weakest player possible\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\u003eLinks updated 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\"}]}"}],"term":"tag:\"multiple calls\"","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:\"multiple calls\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"multiple calls\"","","\"","multiple calls","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f19424544c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f1942454428\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f1942453b68\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f1942454748\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19424546a8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f1942454608\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f1942454568\u003e":"tag:\"multiple calls\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f1942454568\u003e":"tag:\"multiple calls\""},"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":"search","password":"J3bGPZzQ7asjJcCk","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:\"multiple calls\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"multiple calls\"","","\"","multiple calls","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f19424544c8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f1942454428\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f1942453b68\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f1942454748\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19424546a8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f1942454608\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f1942454568\u003e":"tag:\"multiple calls\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f1942454568\u003e":"tag:\"multiple calls\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":700,"difficulty_rating":"easy"},{"id":701,"difficulty_rating":"easy-medium"},{"id":714,"difficulty_rating":"unrated"}]}}