{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":650,"title":"Steal, Share, or Catch","description":"You, I, and a few other characters are going to play a game of *Steal, Share or Catch*.  We are going to play it 10,000 times vs. each of the characters.  \r\n\r\nThe rules of the game are this:\r\n\r\n* There are two points available each round\r\n* We will both choose to either Steal, Share, or Catch\r\n\r\n* If we both choose Share, we both get one point.\r\n* If one chooses Steal and the other Share, the Stealer gets two points.\r\n* If one chooses Steal and the other Catch, the Catcher gets two points.\r\n* Any other combination, no one is awarded points.\r\n\r\nYou are to write an algorithm that will return either\r\n\r\n* -1: Steal\r\n*  0: Share\r\n*  1: Catch\r\n\r\nTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\r\n\r\n  [-1\r\n    1\r\n    1\r\n    0]\r\n\r\nMeaning that the first round there was a Steal, then two Catches, then a share.\r\n\r\nThe characters you will play against are:\r\n\r\n* Evil  (always steals)\r\n* Good  (always shares)\r\n* Chaos (randomly chooses)\r\n* Doug  (Something more complicated)\r\n\r\nAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\r\n\r\nThe scores to beat are:\r\n\r\n  terribleScore   =     0; % works\r\n  badScore        = 23000; % good  strategy scores this\r\n  okScore         = 26000; % evil  strategy scores this\r\n  decentScore     = 29000; % chaos strategy scores this\r\n  greatScore      = 42000; % doug  strategy scores this\r\n\r\nIf you can make a winning solution here, it might be added to the  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions Tournament of Champions\u003e version of this problem.  E-mail me if you want yours added.","description_html":"\u003cp\u003eYou, I, and a few other characters are going to play a game of \u003cb\u003eSteal, Share or Catch\u003c/b\u003e.  We are going to play it 10,000 times vs. each of the characters.\u003c/p\u003e\u003cp\u003eThe rules of the game are this:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThere are two points available each round\u003c/li\u003e\u003cli\u003eWe will both choose to either Steal, Share, or Catch\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003eIf we both choose Share, we both get one point.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/li\u003e\u003cli\u003eAny other combination, no one is awarded points.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are to write an algorithm that will return either\u003c/p\u003e\u003cul\u003e\u003cli\u003e-1: Steal\u003c/li\u003e\u003cli\u003e0: Share\u003c/li\u003e\u003cli\u003e1: Catch\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[-1\r\n  1\r\n  1\r\n  0]\r\n\u003c/pre\u003e\u003cp\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/p\u003e\u003cp\u003eThe characters you will play against are:\u003c/p\u003e\u003cul\u003e\u003cli\u003eEvil  (always steals)\u003c/li\u003e\u003cli\u003eGood  (always shares)\u003c/li\u003e\u003cli\u003eChaos (randomly chooses)\u003c/li\u003e\u003cli\u003eDoug  (Something more complicated)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\u003c/p\u003e\u003cp\u003eThe scores to beat are:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\u003c/pre\u003e\u003cp\u003eIf you can make a winning solution here, it might be added to the  \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\"\u003eTournament of Champions\u003c/a\u003e version of this problem.  E-mail me if you want yours added.\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\nrehash path\r\n\r\n%%\r\n\r\na        = runPair(@StealShareCatch, @chaos);\r\na(end+1) = runPair(@StealShareCatch, @good);\r\na(end+1) = runPair(@StealShareCatch, @evil);\r\na(end+1) = runPair(@StealShareCatch, @doug)\r\nyourScore = sum(a)\r\n\r\nterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\r\n\r\nassert(yourScore \u003e terribleScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e badScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e okScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e decentScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e greatScore, 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":"2012-05-02T20:36:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-02T15:42:59.000Z","updated_at":"2025-06-28T09:34:20.000Z","published_at":"2012-05-02T19:40:23.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\u003eYou, I, and a few other characters are going to play a game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSteal, Share or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We are going to play it 10,000 times vs. each of the characters.\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 rules of the game are this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two points available each round\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe will both choose to either Steal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we both choose Share, we both get one point.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny other combination, no one is awarded points.\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\u003eYou are to write an algorithm that will return either\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e-1: Steal\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e0: Share\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1: Catch\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 help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been. These histories are in the form of:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[-1\\n  1\\n  1\\n  0]]]\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\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 characters you will play against are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil (always steals)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood (always shares)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChaos (randomly chooses)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDoug (Something more complicated)\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\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against. Maybe in a different Cody problem though.\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 scores to beat are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[terribleScore   =     0; % works\\nbadScore        = 23000; % good  strategy scores this\\nokScore         = 26000; % evil  strategy scores this\\ndecentScore     = 29000; % chaos strategy scores this\\ngreatScore      = 42000; % doug  strategy scores this]]\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you can make a winning solution here, it might be added to the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTournament of Champions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e version of this problem. E-mail me if you want yours added.\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":653,"title":"Steal, Share, or Catch: Tournament of Champions","description":"I am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\r\n\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch Steal, Share, or Catch\u003e is explained in the link.\r\n\r\nThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\r\n\r\n* Good\r\n* Evil\r\n* Chaos\r\n* Doug\r\n\r\nYou will face\r\n\r\n* Vincent\r\n* Sean\r\n* James\r\n* Exploiter\r\n* Philipp\r\n* Bert\r\n* Amro\r\n\r\nExploiter recognizes the strategies of many of the above characters, and plays well against them.  \r\n\r\nIs this cheating?  Maybe, but \u003chttp://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against security through obscurity\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\r\n\r\nI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\r\n\r\n\r\nIf you made something and want to see it here, just call my attention to it.\r\n\r\nWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!","description_html":"\u003cp\u003eI am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\"\u003eSteal, Share, or Catch\u003c/a\u003e is explained in the link.\u003c/p\u003e\u003cp\u003eThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGood\u003c/li\u003e\u003cli\u003eEvil\u003c/li\u003e\u003cli\u003eChaos\u003c/li\u003e\u003cli\u003eDoug\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou will face\u003c/p\u003e\u003cul\u003e\u003cli\u003eVincent\u003c/li\u003e\u003cli\u003eSean\u003c/li\u003e\u003cli\u003eJames\u003c/li\u003e\u003cli\u003eExploiter\u003c/li\u003e\u003cli\u003ePhilipp\u003c/li\u003e\u003cli\u003eBert\u003c/li\u003e\u003cli\u003eAmro\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/p\u003e\u003cp\u003eIs this cheating?  Maybe, but \u003ca href = \"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\"\u003esecurity through obscurity\u003c/a\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\u003c/p\u003e\u003cp\u003eI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\u003c/p\u003e\u003cp\u003eIf you made something and want to see it here, just call my attention to it.\u003c/p\u003e\u003cp\u003eWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n\r\n%%\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\n%%\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('sean.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = sean(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    if isempty(theirHist)');\r\nfprintf(fh, '%s \\n', '        [~,choice] = histc(rand,0:0.33:1);');\r\nfprintf(fh, '%s \\n', '        choice = choice-2;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        [~, idx] = max(histc(theirHist,[-1 0 1]));');\r\nfprintf(fh, '%s \\n', '        choice = [1 0 -1];');\r\nfprintf(fh, '%s \\n', '        choice = choice(idx);');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('vincent.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = vincent(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if all(theirHist == -1)');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 0);');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 1);');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', 'choice = 0;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('james.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = james(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if(length(theirHist)\u003c2)');\r\nfprintf(fh, '%s \\n', '  choice = 0;');\r\nfprintf(fh, '%s \\n', 'elseif( theirHist(end-1:end) == -1 )');\r\nfprintf(fh, '%s \\n', '  choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '  choice = theirHist(end);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('dougExploiter.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = dougExploiter(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'threshID = 3;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c threshID');\r\nfprintf(fh, '%s \\n', '    out = 0;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if     isGood(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = -1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'elseif isEvil(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    switch myHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %I stole so he wil steal');\r\nfprintf(fh, '%s \\n', '            out =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %I shared so he will share');\r\nfprintf(fh, '%s \\n', '            out = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %I caught so he will catch');\r\nfprintf(fh, '%s \\n', '            out =  0; %Induce a share');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '  ');\r\nfprintf(fh, '%s \\n', 'else %general unexploitable strategy');\r\nfprintf(fh, '%s \\n', '    out = dougGeneral(myHist, theirHist);');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isGood(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == 0);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isEvil(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == -1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'window = 4;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c window');\r\nfprintf(fh, '%s \\n', '    flag = false;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '    theirRecent = theirHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       myRecent =    myHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       ');\r\nfprintf(fh, '%s \\n', '    flag = isequal(myRecent(1:end-1), theirRecent(2:end));');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'num = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'perShare = nnz(theirHist ==  0)/num;');\r\nfprintf(fh, '%s \\n', 'perSteal = nnz(theirHist == -1)/num;');\r\nfprintf(fh, '%s \\n', 'perCatch = nnz(theirHist ==  1)/num;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'thresh = 0.05;');\r\nfprintf(fh, '%s \\n', 'target = 0.33;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'difference = [perShare perSteal perCatch] - target;');\r\nfprintf(fh, '%s \\n', 'flag = all(abs(difference) \u003c thresh);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'function out = dougGeneral(histA, histB)');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    ');\r\nfclose(fh);\r\n%%\r\nfh=fopen('JamesE.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = jamesE(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if length(theirHist)\u003e10');\r\nfprintf(fh, '%s \\n', '    [yourguess yourcounts]=hist(theirHist(end-9:end),-1:1);');\r\nfprintf(fh, '%s \\n', '    [countmax countval]=max(yourguess);');\r\nfprintf(fh, '%s \\n', '    yourpopguess=yourcounts(countval);');\r\nfprintf(fh, '%s \\n', '    if yourpopguess==-1');\r\nfprintf(fh, '%s \\n', '        choice=1;');\r\nfprintf(fh, '%s \\n', '    elseif yourpopguess==0');\r\nfprintf(fh, '%s \\n', '        choice=-1;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        choice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '\tchoice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('philipp.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = philipp(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histLength = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'window = histLength-1;');\r\nfprintf(fh, '%s \\n', 'if histLength \u003e 10');\r\nfprintf(fh, '%s \\n', '    window = randi([5 10]);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', ' if isempty(yourHist)');\r\nfprintf(fh, '%s \\n', '     % No choices made yet');\r\nfprintf(fh, '%s \\n', '     choice = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', ' else');\r\nfprintf(fh, '%s \\n', '     switch mode(theirHist(end-window:end))');\r\nfprintf(fh, '%s \\n', '         case -1');\r\nfprintf(fh, '%s \\n', '             choice = 1;');\r\nfprintf(fh, '%s \\n', '         case 0');\r\nfprintf(fh, '%s \\n', '             choice = -1;');\r\nfprintf(fh, '%s \\n', '         case 1');\r\nfprintf(fh, '%s \\n', '             choice = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '         otherwise');\r\nfprintf(fh, '%s \\n', '             choice = 0;');\r\nfprintf(fh, '%s \\n', '     end');\r\nfprintf(fh, '%s \\n', ' end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('bert.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = bert(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(theirHist)\u003e2');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    %check for tit4Tat stratagy');\r\nfprintf(fh, '%s \\n', '    isTit4Tat = isequal(yourHist(end-2:end-1), theirHist(end-1:end));');\r\nfprintf(fh, '%s \\n', '    count=histc(theirHist,-1:1);');\r\nfprintf(fh, '%s \\n', '    stealPercent = count(1)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    sharePercent = count(2)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    catPercent = count(3)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    choice = -theirHist(end); %general behavior ');\r\nfprintf(fh, '%s \\n', '    if isTit4Tat %check for tit4tat');\r\nfprintf(fh, '%s \\n', '        switch yourHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %he wil steal');\r\nfprintf(fh, '%s \\n', '            choice =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %he will share');\r\nfprintf(fh, '%s \\n', '            choice = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %he will catch');\r\nfprintf(fh, '%s \\n', '            choice =  0;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        end');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if choice == -1 %dont steal if the last was catch');\r\nfprintf(fh, '%s \\n', '        choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if rand(1)\u003e0.9 %random behavior to pass exploiters test');\r\nfprintf(fh, '%s \\n', '     choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if stealPercent \u003e 0.7   %if they steal often, I catch     ');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    elseif sharePercent \u003e0.7 %if they share often, I steal');\r\nfprintf(fh, '%s \\n', '        choice = -1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if numel(theirHist)\u003e9000 %for the last 1000 round, steal');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('amro.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = amro(histA, histB)');\r\nfprintf(fh, '%s \\n', '\t% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '\t% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '\t%-1 steal');\r\nfprintf(fh, '%s \\n', '\t% 0 share');\r\nfprintf(fh, '%s \\n', '\t% 1 catch');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\tif rand\u003c0.01 || isempty(histB)\t% if starting (or flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: random move or \"share\"');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.925');\r\nfprintf(fh, '%s \\n', '\t\t\tout = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = -1;');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\telseif rand\u003c0.01\t\t\t\t% flipCoin');\r\nfprintf(fh, '%s \\n', '\t\t% repeat his last move');\r\nfprintf(fh, '%s \\n', '\t\tout = histB(end);');\r\nfprintf(fh, '%s \\n', '\telse');\r\nfprintf(fh, '%s \\n', '\t\t% in the first/last X moves (+flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.4 \u0026\u0026 numel(histB)\u003e9900');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.1 \u0026\u0026 numel(histB)\u003c15');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% check if player B has been repeating my moves (tit4tat)');\r\nfprintf(fh, '%s \\n', '\t\tn = 2;');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.9 \u0026\u0026 numel(histA)\u003en');\r\nfprintf(fh, '%s \\n', '\t\t\tif isequal(histA(end-n:end-1), histB(end-n+1:end))');\r\nfprintf(fh, '%s \\n', '\t\t\t\t% predict his next move based on my previous move');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = [1 -1 0];');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = out( histB(end)+2 );');\r\nfprintf(fh, '%s \\n', '\t\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% frequency of moves over entire history of player B');\r\nfprintf(fh, '%s \\n', '\t\tfreq = histc(histB,-1:1) ./ numel(histB);');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: all history or last N only');\r\nfprintf(fh, '%s \\n', '\t\tmaxNum = randi([7 10]);');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.98 \u0026\u0026 numel(histB)\u003emaxNum');\r\nfprintf(fh, '%s \\n', '\t\t\thistB = histB(end-maxNum+1:end);');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% most frequent move in possibly filtered history');\r\nfprintf(fh, '%s \\n', '\t\t%idx = mode(histB)+2;');\r\nfprintf(fh, '%s \\n', '\t\t[~,idx] = max( histc(histB,-1:1) );');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% counter move');\r\nfprintf(fh, '%s \\n', '\t\tout = [1 0 0];\t\t% steal-\u003ecatch, share-\u003eshare, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\tif freq(2)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(2) = -1; end\t% adjust if he shares alot');\r\nfprintf(fh, '%s \\n', '\t\tif freq(1)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(3) = 1; end\t% adjust if he catches alot');\r\nfprintf(fh, '%s \\n', '\t\t%{');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c freq(1)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 1];\t% steal-\u003ecatch, share-\u003eshare, catch-\u003ecatch');\r\nfprintf(fh, '%s \\n', '\t\telseif rand \u003c freq(2)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 -1 0];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 randi([0 1])];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003erandom');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t%}');\r\nfprintf(fh, '%s \\n', '\t\tout = out(idx);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\t% check if I am repeating myself in the last N moves');\r\nfprintf(fh, '%s \\n', '\t%{');\r\nfprintf(fh, '%s \\n', '\tn = 50;');\r\nfprintf(fh, '%s \\n', '\tif numel(histA)\u003e=n \u0026\u0026 all(histA(end-n+1:end)==out)');\r\nfprintf(fh, '%s \\n', '\t\tout = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t%}');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nrehash path\r\n%%\r\n\r\nfh = @StealShareCatch;\r\n\r\na        = runPair(fh, @chaos)\r\na(end+1) = runPair(fh, @evil)\r\na(end+1) = runPair(fh, @StealShareCatch)\r\na(end+1) = runPair(fh, @good)\r\na(end+1) = runPair(fh, @doug)\r\na(end+1) = runPair(fh, @sean)\r\na(end+1) = runPair(fh, @james)\r\na(end+1) = runPair(fh, @vincent)\r\na(end+1) = runPair(fh, @JamesE)\r\na(end+1) = runPair(fh, @philipp)\r\na(end+1) = runPair(fh, @bert)\r\na(end+1) = runPair(fh, @amro)\r\n\r\nyourScore = sum(a)\r\n\r\nScore =      0; % works\r\nScore =  80219; % Vincent\r\nScore =  84000; % Sean\r\nScore =  93000; % james\r\nScore = 104000; % doug\r\nScore = 118000; % JamesE\r\nScore = 120000; % stealShareCatch\r\nScore = 122000; % philipp\r\nScore = 125000; % bert\r\nScore = 135000; % amro\r\n\r\n\r\n\r\nassert(yourScore \u003e Score(end), 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2012-07-10T13:37:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-03T17:58:45.000Z","updated_at":"2013-04-17T13:38:44.000Z","published_at":"2012-05-03T18:29:26.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\u003eI am no longer supporting this problem. No changes will be made to put more entries in the test suite, but have fun playing anyways!\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSteal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is explained in the link.\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\u003eThis problem is the \\\"Tournament of Champions\\\". If you make a passing entry in the original, from time to time I will move entries over to this Cody problem. You will no longer be playing against only easy characters:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChaos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDoug\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\u003eYou will face\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVincent\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSean\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eJames\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExploiter\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePhilipp\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBert\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAmro\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\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\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\u003eIs this cheating? Maybe, but\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esecurity through obscurity\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is questionable! Take a look at Exploiter, it is the reference solution to this problem.\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\u003eI will update the test suite and cast of characters and winning score as we go. I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time. It will be a matter of beating the test score more than getting lowest complexity!\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 you made something and want to see it here, just call my attention to it.\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\u003eWinner is determined by score, not by length. As of 6/28/2012 on my machine Amro is the current winner at 136K!\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":650,"title":"Steal, Share, or Catch","description":"You, I, and a few other characters are going to play a game of *Steal, Share or Catch*.  We are going to play it 10,000 times vs. each of the characters.  \r\n\r\nThe rules of the game are this:\r\n\r\n* There are two points available each round\r\n* We will both choose to either Steal, Share, or Catch\r\n\r\n* If we both choose Share, we both get one point.\r\n* If one chooses Steal and the other Share, the Stealer gets two points.\r\n* If one chooses Steal and the other Catch, the Catcher gets two points.\r\n* Any other combination, no one is awarded points.\r\n\r\nYou are to write an algorithm that will return either\r\n\r\n* -1: Steal\r\n*  0: Share\r\n*  1: Catch\r\n\r\nTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\r\n\r\n  [-1\r\n    1\r\n    1\r\n    0]\r\n\r\nMeaning that the first round there was a Steal, then two Catches, then a share.\r\n\r\nThe characters you will play against are:\r\n\r\n* Evil  (always steals)\r\n* Good  (always shares)\r\n* Chaos (randomly chooses)\r\n* Doug  (Something more complicated)\r\n\r\nAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\r\n\r\nThe scores to beat are:\r\n\r\n  terribleScore   =     0; % works\r\n  badScore        = 23000; % good  strategy scores this\r\n  okScore         = 26000; % evil  strategy scores this\r\n  decentScore     = 29000; % chaos strategy scores this\r\n  greatScore      = 42000; % doug  strategy scores this\r\n\r\nIf you can make a winning solution here, it might be added to the  \u003chttp://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions Tournament of Champions\u003e version of this problem.  E-mail me if you want yours added.","description_html":"\u003cp\u003eYou, I, and a few other characters are going to play a game of \u003cb\u003eSteal, Share or Catch\u003c/b\u003e.  We are going to play it 10,000 times vs. each of the characters.\u003c/p\u003e\u003cp\u003eThe rules of the game are this:\u003c/p\u003e\u003cul\u003e\u003cli\u003eThere are two points available each round\u003c/li\u003e\u003cli\u003eWe will both choose to either Steal, Share, or Catch\u003c/li\u003e\u003c/ul\u003e\u003cul\u003e\u003cli\u003eIf we both choose Share, we both get one point.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/li\u003e\u003cli\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/li\u003e\u003cli\u003eAny other combination, no one is awarded points.\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou are to write an algorithm that will return either\u003c/p\u003e\u003cul\u003e\u003cli\u003e-1: Steal\u003c/li\u003e\u003cli\u003e0: Share\u003c/li\u003e\u003cli\u003e1: Catch\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eTo help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been.  These histories are in the form of:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[-1\r\n  1\r\n  1\r\n  0]\r\n\u003c/pre\u003e\u003cp\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\u003c/p\u003e\u003cp\u003eThe characters you will play against are:\u003c/p\u003e\u003cul\u003e\u003cli\u003eEvil  (always steals)\u003c/li\u003e\u003cli\u003eGood  (always shares)\u003c/li\u003e\u003cli\u003eChaos (randomly chooses)\u003c/li\u003e\u003cli\u003eDoug  (Something more complicated)\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against.  Maybe in a different Cody problem though.\u003c/p\u003e\u003cp\u003eThe scores to beat are:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\u003c/pre\u003e\u003cp\u003eIf you can make a winning solution here, it might be added to the  \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\"\u003eTournament of Champions\u003c/a\u003e version of this problem.  E-mail me if you want yours added.\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\nrehash path\r\n\r\n%%\r\n\r\na        = runPair(@StealShareCatch, @chaos);\r\na(end+1) = runPair(@StealShareCatch, @good);\r\na(end+1) = runPair(@StealShareCatch, @evil);\r\na(end+1) = runPair(@StealShareCatch, @doug)\r\nyourScore = sum(a)\r\n\r\nterribleScore   =     0; % works\r\nbadScore        = 23000; % good  strategy scores this\r\nokScore         = 26000; % evil  strategy scores this\r\ndecentScore     = 29000; % chaos strategy scores this\r\ngreatScore      = 42000; % doug  strategy scores this\r\n\r\n\r\nassert(yourScore \u003e terribleScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e badScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e okScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e decentScore, 'Score: %d', yourScore)\r\n\r\nassert(yourScore \u003e greatScore, 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":79,"test_suite_updated_at":"2012-05-02T20:36:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-02T15:42:59.000Z","updated_at":"2025-06-28T09:34:20.000Z","published_at":"2012-05-02T19:40:23.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\u003eYou, I, and a few other characters are going to play a game of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eSteal, Share or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. We are going to play it 10,000 times vs. each of the characters.\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 rules of the game are this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThere are two points available each round\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWe will both choose to either Steal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we both choose Share, we both get one point.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Share, the Stealer gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf one chooses Steal and the other Catch, the Catcher gets two points.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAny other combination, no one is awarded points.\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\u003eYou are to write an algorithm that will return either\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e-1: Steal\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e0: Share\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e1: Catch\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 help you make your choice, you will have a history vector that shows what your choices have been so far, and what the opponent's choices have been. These histories are in the form of:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[[-1\\n  1\\n  1\\n  0]]]\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMeaning that the first round there was a Steal, then two Catches, then a share.\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 characters you will play against are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil (always steals)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood (always shares)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChaos (randomly chooses)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDoug (Something more complicated)\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\u003eAs this problem runs, I will take the better entries and add them into the cast of characters that you play against. Maybe in a different Cody problem though.\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 scores to beat are:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[terribleScore   =     0; % works\\nbadScore        = 23000; % good  strategy scores this\\nokScore         = 26000; % evil  strategy scores this\\ndecentScore     = 29000; % chaos strategy scores this\\ngreatScore      = 42000; % doug  strategy scores this]]\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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you can make a winning solution here, it might be added to the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/653-steal-share-or-catch-tournament-of-champions\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eTournament of Champions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e version of this problem. E-mail me if you want yours added.\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":653,"title":"Steal, Share, or Catch: Tournament of Champions","description":"I am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\r\n\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch Steal, Share, or Catch\u003e is explained in the link.\r\n\r\nThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\r\n\r\n* Good\r\n* Evil\r\n* Chaos\r\n* Doug\r\n\r\nYou will face\r\n\r\n* Vincent\r\n* Sean\r\n* James\r\n* Exploiter\r\n* Philipp\r\n* Bert\r\n* Amro\r\n\r\nExploiter recognizes the strategies of many of the above characters, and plays well against them.  \r\n\r\nIs this cheating?  Maybe, but \u003chttp://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against security through obscurity\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\r\n\r\nI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\r\n\r\n\r\nIf you made something and want to see it here, just call my attention to it.\r\n\r\nWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!","description_html":"\u003cp\u003eI am no longer supporting this problem.  No changes will be made to put more entries in the test suite, but have fun playing anyways!\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\"\u003eSteal, Share, or Catch\u003c/a\u003e is explained in the link.\u003c/p\u003e\u003cp\u003eThis problem is the \"Tournament of Champions\".  If you make a passing entry in the original, from time to time I will move entries over to this Cody problem.  You will no longer be playing against only easy characters:\u003c/p\u003e\u003cul\u003e\u003cli\u003eGood\u003c/li\u003e\u003cli\u003eEvil\u003c/li\u003e\u003cli\u003eChaos\u003c/li\u003e\u003cli\u003eDoug\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eYou will face\u003c/p\u003e\u003cul\u003e\u003cli\u003eVincent\u003c/li\u003e\u003cli\u003eSean\u003c/li\u003e\u003cli\u003eJames\u003c/li\u003e\u003cli\u003eExploiter\u003c/li\u003e\u003cli\u003ePhilipp\u003c/li\u003e\u003cli\u003eBert\u003c/li\u003e\u003cli\u003eAmro\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\u003c/p\u003e\u003cp\u003eIs this cheating?  Maybe, but \u003ca href = \"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\"\u003esecurity through obscurity\u003c/a\u003e is questionable!  Take a look at Exploiter, it is the reference solution to this problem.\u003c/p\u003e\u003cp\u003eI will update the test suite and cast of characters and winning score as we go.  I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time.  It will be a matter of beating the test score more than getting lowest complexity!\u003c/p\u003e\u003cp\u003eIf you made something and want to see it here, just call my attention to it.\u003c/p\u003e\u003cp\u003eWinner is determined by score, not by length.  As of 6/28/2012 on my machine Amro is the current winner at 136K!\u003c/p\u003e","function_template":"function choice = StealShareCatch(yourHist, theirHist)\r\n% This function will be called 10,000 times.\r\n% the hist vectors will start as [], and get longer each time through.\r\n%-1 steal\r\n% 0 share\r\n% 1 catch\r\n\r\n%stealVal = 2; What you get if you steal and they share\r\n%catchVal = 2; What you get if you catch and they steal\r\n%shareVal = 1; What you both get if both share\r\n%Otherwise no one gets anything!\r\n  choice = 0;\r\nend","test_suite":"% THIS IS A HACK TO GET CODE ON THE PATH\r\n% IGNORE THIS FIRST 'TEST'\r\n%\r\n%\r\nfh=fopen('doug.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = doug(histA, histB)');\r\nfprintf(fh, '%s \\n', '% A is self');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n\r\n%%\r\nfh=fopen('runPair.m','wt');\r\nfprintf(fh, '%s \\n', 'function [scoreA, scoreB] = runPair(fhA, fhB);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'n = 10000;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histA = [];');\r\nfprintf(fh, '%s \\n', 'histB = [];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'scoreA = 0;');\r\nfprintf(fh, '%s \\n', 'scoreB = 0;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'stealVal = 2;');\r\nfprintf(fh, '%s \\n', 'catchVal = 2;');\r\nfprintf(fh, '%s \\n', 'shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'for i = 1: n;');\r\nfprintf(fh, '%s \\n', '    histA(end+1,1) = fhA(histA,  histB         );');\r\nfprintf(fh, '%s \\n', '    histB(end+1,1) = fhB(histB,  histA(1:end-1)); %modified one not sent!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    switch histA(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %a steal');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + stealVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + catchVal;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'') ');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 0 %a share');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + stealVal;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + shareVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB + shareVal;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        case 1 %a catch');\r\nfprintf(fh, '%s \\n', '            switch histB(end)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            case -1 %b steal');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA + catchVal;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 0 %b share');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            case 1 %b catch');\r\nfprintf(fh, '%s \\n', '                scoreA = scoreA;');\r\nfprintf(fh, '%s \\n', '                scoreB = scoreB;');\r\nfprintf(fh, '%s \\n', '            otherwise');\r\nfprintf(fh, '%s \\n', '                error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '            end');\r\nfprintf(fh, '%s \\n', '        otherwise');\r\nfprintf(fh, '%s \\n', '            error(''This can not happen'')');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '');\r\nfclose(fh);\r\n%%\r\nfh=fopen('evil.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = evil(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = -1;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('good.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = good(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('chaos.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = chaos(histA, histB)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2;');\r\nfprintf(fh, '%s \\n', '%catchVal = 2;');\r\nfprintf(fh, '%s \\n', '%shareVal = 1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = ceil(rand*3)-2;');\r\nfclose(fh);\r\n%%\r\nfh=fopen('sean.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = sean(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    if isempty(theirHist)');\r\nfprintf(fh, '%s \\n', '        [~,choice] = histc(rand,0:0.33:1);');\r\nfprintf(fh, '%s \\n', '        choice = choice-2;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        [~, idx] = max(histc(theirHist,[-1 0 1]));');\r\nfprintf(fh, '%s \\n', '        choice = [1 0 -1];');\r\nfprintf(fh, '%s \\n', '        choice = choice(idx);');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('vincent.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = vincent(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if all(theirHist == -1)');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 0);');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', 'elseif all(theirHist == 1);');\r\nfprintf(fh, '%s \\n', 'choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', 'choice = 0;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('james.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = james(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'if(length(theirHist)\u003c2)');\r\nfprintf(fh, '%s \\n', '  choice = 0;');\r\nfprintf(fh, '%s \\n', 'elseif( theirHist(end-1:end) == -1 )');\r\nfprintf(fh, '%s \\n', '  choice = 1;');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '  choice = theirHist(end);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('dougExploiter.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = dougExploiter(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'threshID = 3;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c threshID');\r\nfprintf(fh, '%s \\n', '    out = 0;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if     isGood(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = -1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'elseif isEvil(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '    switch myHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %I stole so he wil steal');\r\nfprintf(fh, '%s \\n', '            out =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %I shared so he will share');\r\nfprintf(fh, '%s \\n', '            out = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %I caught so he will catch');\r\nfprintf(fh, '%s \\n', '            out =  0; %Induce a share');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'elseif isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '    out = 1;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', '  ');\r\nfprintf(fh, '%s \\n', 'else %general unexploitable strategy');\r\nfprintf(fh, '%s \\n', '    out = dougGeneral(myHist, theirHist);');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isGood(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == 0);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isEvil(in)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'flag = all(in == -1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isTitForTat(myHist, theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'window = 4;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(myHist) \u003c window');\r\nfprintf(fh, '%s \\n', '    flag = false;');\r\nfprintf(fh, '%s \\n', '    return');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '    theirRecent = theirHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       myRecent =    myHist(end-(window-1):end);');\r\nfprintf(fh, '%s \\n', '       ');\r\nfprintf(fh, '%s \\n', '    flag = isequal(myRecent(1:end-1), theirRecent(2:end));');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'function flag = isChaos(theirHist)');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'num = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'perShare = nnz(theirHist ==  0)/num;');\r\nfprintf(fh, '%s \\n', 'perSteal = nnz(theirHist == -1)/num;');\r\nfprintf(fh, '%s \\n', 'perCatch = nnz(theirHist ==  1)/num;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'thresh = 0.05;');\r\nfprintf(fh, '%s \\n', 'target = 0.33;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'difference = [perShare perSteal perCatch] - target;');\r\nfprintf(fh, '%s \\n', 'flag = all(abs(difference) \u003c thresh);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', 'function out = dougGeneral(histA, histB)');\r\nfprintf(fh, '%s \\n', 'memoryThresh = 10;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histB = [zeros(memoryThresh,1); histB];');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'recentB = histB(end-(memoryThresh-1) : end);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'numStealB = nnz(recentB == -1);');\r\nfprintf(fh, '%s \\n', 'numShareB = nnz(recentB ==  0);');\r\nfprintf(fh, '%s \\n', 'numCatchB = nnz(recentB ==  1);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'percentStealB = (numStealB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentShareB = (numShareB/memoryThresh);');\r\nfprintf(fh, '%s \\n', 'percentCatchB = (numCatchB/memoryThresh);');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'out = 0; %default to share');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '            rollDice = rand;');\r\nfprintf(fh, '%s \\n', 'percentCatchStealers = 0.9;');\r\nfprintf(fh, '%s \\n', 'if (rollDice \u003c percentStealB)');\r\nfprintf(fh, '%s \\n', '    rollDice = rand;');\r\nfprintf(fh, '%s \\n', '    if (rollDice \u003c percentCatchStealers)');\r\nfprintf(fh, '%s \\n', '        out =  1; % catch');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        out = -1; % steal');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '    ');\r\nfclose(fh);\r\n%%\r\nfh=fopen('JamesE.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = jamesE(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if length(theirHist)\u003e10');\r\nfprintf(fh, '%s \\n', '    [yourguess yourcounts]=hist(theirHist(end-9:end),-1:1);');\r\nfprintf(fh, '%s \\n', '    [countmax countval]=max(yourguess);');\r\nfprintf(fh, '%s \\n', '    yourpopguess=yourcounts(countval);');\r\nfprintf(fh, '%s \\n', '    if yourpopguess==-1');\r\nfprintf(fh, '%s \\n', '        choice=1;');\r\nfprintf(fh, '%s \\n', '    elseif yourpopguess==0');\r\nfprintf(fh, '%s \\n', '        choice=-1;');\r\nfprintf(fh, '%s \\n', '    else');\r\nfprintf(fh, '%s \\n', '        choice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'else');\r\nfprintf(fh, '%s \\n', '\tchoice=floor(3*rand)-1;');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('philipp.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = philipp(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'histLength = numel(theirHist);');\r\nfprintf(fh, '%s \\n', 'window = histLength-1;');\r\nfprintf(fh, '%s \\n', 'if histLength \u003e 10');\r\nfprintf(fh, '%s \\n', '    window = randi([5 10]);');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', ' if isempty(yourHist)');\r\nfprintf(fh, '%s \\n', '     % No choices made yet');\r\nfprintf(fh, '%s \\n', '     choice = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', ' else');\r\nfprintf(fh, '%s \\n', '     switch mode(theirHist(end-window:end))');\r\nfprintf(fh, '%s \\n', '         case -1');\r\nfprintf(fh, '%s \\n', '             choice = 1;');\r\nfprintf(fh, '%s \\n', '         case 0');\r\nfprintf(fh, '%s \\n', '             choice = -1;');\r\nfprintf(fh, '%s \\n', '         case 1');\r\nfprintf(fh, '%s \\n', '             choice = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '         otherwise');\r\nfprintf(fh, '%s \\n', '             choice = 0;');\r\nfprintf(fh, '%s \\n', '     end');\r\nfprintf(fh, '%s \\n', ' end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('bert.m','wt');\r\nfprintf(fh, '%s \\n', 'function choice = bert(yourHist, theirHist)');\r\nfprintf(fh, '%s \\n', '% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '%-1 steal');\r\nfprintf(fh, '%s \\n', '% 0 share');\r\nfprintf(fh, '%s \\n', '% 1 catch');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', '%stealVal = 2; What you get if you steal and they share');\r\nfprintf(fh, '%s \\n', '%catchVal = 2; What you get if you catch and they steal');\r\nfprintf(fh, '%s \\n', '%shareVal = 1; What you both get if both share');\r\nfprintf(fh, '%s \\n', '%Otherwise no one gets anything!');\r\nfprintf(fh, '%s \\n', 'choice = -1;');\r\nfprintf(fh, '%s \\n', '');\r\nfprintf(fh, '%s \\n', 'if numel(theirHist)\u003e2');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    %check for tit4Tat stratagy');\r\nfprintf(fh, '%s \\n', '    isTit4Tat = isequal(yourHist(end-2:end-1), theirHist(end-1:end));');\r\nfprintf(fh, '%s \\n', '    count=histc(theirHist,-1:1);');\r\nfprintf(fh, '%s \\n', '    stealPercent = count(1)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    sharePercent = count(2)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    catPercent = count(3)/numel(theirHist);');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    choice = -theirHist(end); %general behavior ');\r\nfprintf(fh, '%s \\n', '    if isTit4Tat %check for tit4tat');\r\nfprintf(fh, '%s \\n', '        switch yourHist(end)');\r\nfprintf(fh, '%s \\n', '        case -1 %he wil steal');\r\nfprintf(fh, '%s \\n', '            choice =  1; %catch');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  0 %he will share');\r\nfprintf(fh, '%s \\n', '            choice = -1;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        case  1 %he will catch');\r\nfprintf(fh, '%s \\n', '            choice =  0;');\r\nfprintf(fh, '%s \\n', '            return');\r\nfprintf(fh, '%s \\n', '        end');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if choice == -1 %dont steal if the last was catch');\r\nfprintf(fh, '%s \\n', '        choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if rand(1)\u003e0.9 %random behavior to pass exploiters test');\r\nfprintf(fh, '%s \\n', '     choice = 0;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    ');\r\nfprintf(fh, '%s \\n', '    if stealPercent \u003e 0.7   %if they steal often, I catch     ');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    elseif sharePercent \u003e0.7 %if they share often, I steal');\r\nfprintf(fh, '%s \\n', '        choice = -1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', '    if numel(theirHist)\u003e9000 %for the last 1000 round, steal');\r\nfprintf(fh, '%s \\n', '        choice = 1;');\r\nfprintf(fh, '%s \\n', '    end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nfh=fopen('amro.m','wt');\r\nfprintf(fh, '%s \\n', 'function out = amro(histA, histB)');\r\nfprintf(fh, '%s \\n', '\t% This function will be called 10,000 times.');\r\nfprintf(fh, '%s \\n', '\t% the hist vectors will start as [], and get longer each time through.');\r\nfprintf(fh, '%s \\n', '\t%-1 steal');\r\nfprintf(fh, '%s \\n', '\t% 0 share');\r\nfprintf(fh, '%s \\n', '\t% 1 catch');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\tif rand\u003c0.01 || isempty(histB)\t% if starting (or flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: random move or \"share\"');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.925');\r\nfprintf(fh, '%s \\n', '\t\t\tout = randi([-1 1]);');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = -1;');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\telseif rand\u003c0.01\t\t\t\t% flipCoin');\r\nfprintf(fh, '%s \\n', '\t\t% repeat his last move');\r\nfprintf(fh, '%s \\n', '\t\tout = histB(end);');\r\nfprintf(fh, '%s \\n', '\telse');\r\nfprintf(fh, '%s \\n', '\t\t% in the first/last X moves (+flipCoin)');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.4 \u0026\u0026 numel(histB)\u003e9900');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.1 \u0026\u0026 numel(histB)\u003c15');\r\nfprintf(fh, '%s \\n', '\t\t\tout = 1;\t% catch');\r\nfprintf(fh, '%s \\n', '\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% check if player B has been repeating my moves (tit4tat)');\r\nfprintf(fh, '%s \\n', '\t\tn = 2;');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c 0.9 \u0026\u0026 numel(histA)\u003en');\r\nfprintf(fh, '%s \\n', '\t\t\tif isequal(histA(end-n:end-1), histB(end-n+1:end))');\r\nfprintf(fh, '%s \\n', '\t\t\t\t% predict his next move based on my previous move');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = [1 -1 0];');\r\nfprintf(fh, '%s \\n', '\t\t\t\tout = out( histB(end)+2 );');\r\nfprintf(fh, '%s \\n', '\t\t\t\treturn');\r\nfprintf(fh, '%s \\n', '\t\t\tend');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% frequency of moves over entire history of player B');\r\nfprintf(fh, '%s \\n', '\t\tfreq = histc(histB,-1:1) ./ numel(histB);');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% flipCoin: all history or last N only');\r\nfprintf(fh, '%s \\n', '\t\tmaxNum = randi([7 10]);');\r\nfprintf(fh, '%s \\n', '\t\tif rand\u003c0.98 \u0026\u0026 numel(histB)\u003emaxNum');\r\nfprintf(fh, '%s \\n', '\t\t\thistB = histB(end-maxNum+1:end);');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% most frequent move in possibly filtered history');\r\nfprintf(fh, '%s \\n', '\t\t%idx = mode(histB)+2;');\r\nfprintf(fh, '%s \\n', '\t\t[~,idx] = max( histc(histB,-1:1) );');\r\nfprintf(fh, '%s \\n', '\t\t');\r\nfprintf(fh, '%s \\n', '\t\t% counter move');\r\nfprintf(fh, '%s \\n', '\t\tout = [1 0 0];\t\t% steal-\u003ecatch, share-\u003eshare, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\tif freq(2)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(2) = -1; end\t% adjust if he shares alot');\r\nfprintf(fh, '%s \\n', '\t\tif freq(1)\u003e0.7 \u0026\u0026 rand\u003c0.995, out(3) = 1; end\t% adjust if he catches alot');\r\nfprintf(fh, '%s \\n', '\t\t%{');\r\nfprintf(fh, '%s \\n', '\t\tif rand \u003c freq(1)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 1];\t% steal-\u003ecatch, share-\u003eshare, catch-\u003ecatch');\r\nfprintf(fh, '%s \\n', '\t\telseif rand \u003c freq(2)');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 -1 0];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003eshare');\r\nfprintf(fh, '%s \\n', '\t\telse');\r\nfprintf(fh, '%s \\n', '\t\t\tout = [1 0 randi([0 1])];\t% steal-\u003ecatch, share-\u003esteal, catch-\u003erandom');\r\nfprintf(fh, '%s \\n', '\t\tend');\r\nfprintf(fh, '%s \\n', '\t\t%}');\r\nfprintf(fh, '%s \\n', '\t\tout = out(idx);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t');\r\nfprintf(fh, '%s \\n', '\t% check if I am repeating myself in the last N moves');\r\nfprintf(fh, '%s \\n', '\t%{');\r\nfprintf(fh, '%s \\n', '\tn = 50;');\r\nfprintf(fh, '%s \\n', '\tif numel(histA)\u003e=n \u0026\u0026 all(histA(end-n+1:end)==out)');\r\nfprintf(fh, '%s \\n', '\t\tout = randi([0 1]);');\r\nfprintf(fh, '%s \\n', '\tend');\r\nfprintf(fh, '%s \\n', '\t%}');\r\nfprintf(fh, '%s \\n', 'end');\r\nfclose(fh);\r\n%%\r\nrehash path\r\n%%\r\n\r\nfh = @StealShareCatch;\r\n\r\na        = runPair(fh, @chaos)\r\na(end+1) = runPair(fh, @evil)\r\na(end+1) = runPair(fh, @StealShareCatch)\r\na(end+1) = runPair(fh, @good)\r\na(end+1) = runPair(fh, @doug)\r\na(end+1) = runPair(fh, @sean)\r\na(end+1) = runPair(fh, @james)\r\na(end+1) = runPair(fh, @vincent)\r\na(end+1) = runPair(fh, @JamesE)\r\na(end+1) = runPair(fh, @philipp)\r\na(end+1) = runPair(fh, @bert)\r\na(end+1) = runPair(fh, @amro)\r\n\r\nyourScore = sum(a)\r\n\r\nScore =      0; % works\r\nScore =  80219; % Vincent\r\nScore =  84000; % Sean\r\nScore =  93000; % james\r\nScore = 104000; % doug\r\nScore = 118000; % JamesE\r\nScore = 120000; % stealShareCatch\r\nScore = 122000; % philipp\r\nScore = 125000; % bert\r\nScore = 135000; % amro\r\n\r\n\r\n\r\nassert(yourScore \u003e Score(end), 'Score: %d', yourScore)","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":"2012-07-10T13:37:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-03T17:58:45.000Z","updated_at":"2013-04-17T13:38:44.000Z","published_at":"2012-05-03T18:29:26.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\u003eI am no longer supporting this problem. No changes will be made to put more entries in the test suite, but have fun playing anyways!\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/650-steal-share-or-catch\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eSteal, Share, or Catch\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is explained in the link.\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\u003eThis problem is the \\\"Tournament of Champions\\\". If you make a passing entry in the original, from time to time I will move entries over to this Cody problem. You will no longer be playing against only easy characters:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvil\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eChaos\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDoug\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\u003eYou will face\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eVincent\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSean\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eJames\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExploiter\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePhilipp\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBert\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAmro\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\u003eExploiter recognizes the strategies of many of the above characters, and plays well against them.\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\u003eIs this cheating? Maybe, but\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/Security_through_obscurity#Arguments_against\\\"\u003e\u003cw:r\u003e\u003cw:t\u003esecurity through obscurity\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is questionable! Take a look at Exploiter, it is the reference solution to this problem.\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\u003eI will update the test suite and cast of characters and winning score as we go. I will try to keep making the test suite tougher so that only one/two entries can pass it at any given time. It will be a matter of beating the test score more than getting lowest complexity!\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 you made something and want to see it here, just call my attention to it.\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\u003eWinner is determined by score, not by length. As of 6/28/2012 on my machine Amro is the current winner at 136K!\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:\"gametheory\"","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:\"gametheory\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"gametheory\"","","\"","gametheory","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaa980\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f64e7aaa8e0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f64e7aa84a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaac00\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f64e7aaab60\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f64e7aaaac0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f64e7aaaa20\u003e":"tag:\"gametheory\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaaa20\u003e":"tag:\"gametheory\""},"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:\"gametheory\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"gametheory\"","","\"","gametheory","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaa980\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f64e7aaa8e0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f64e7aa84a0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaac00\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f64e7aaab60\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f64e7aaaac0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f64e7aaaa20\u003e":"tag:\"gametheory\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f64e7aaaa20\u003e":"tag:\"gametheory\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":650,"difficulty_rating":"easy-medium"},{"id":653,"difficulty_rating":"hard"}]}}