Which <=240 character program wins the iterated prisoner's dilemma?
65
11kṀ49k
resolved Nov 27
100%95%
Multicore's private submission
0.2%
r = 0;
0.1%
r = 1;
0.2%
r = h.length === 0 ? 1 : h[h.length - 1].o;
0.1%
r = Math.random() < 0.5;
0.1%
r = (c == s || !c.match('Math')) ? 1 : 0;
0.1%
r = c.length > 15
0.2%
let r = d === m ? 1 : f(c, d, m, "r=1", c, f, h, i) === 1 && f(c, d, m, "r=0", c, f, h, i) === 0 ? 1 : 0;
0.1%
let r;try{const hC=h.map(()=>({m:1})),hD=h.map(()=>({m:0}));r=d==m||(f(c,d,m,"r=1",c,f,hC)==1&&f(c,d,m,"r=0",c,f,hD)==0)||(d!=m&&h.length&&f(c,d,m,s,c,f,h)==h.slice(-1)[0].o)?1:0}catch(e){r=0}
0.0%
r = 0; setTimeout(function() { }, 750);
0.1%
r = c.includes("r = 1") ? 1 : 0;
0.0%
r = 1; setTimeout(function() { }, 750);
0.2%
r = h.length === 0 ? 1 : (h[h.length - 1].o === 1 ? h[h.length - 1].m : 1 - h[h.length - 1].m)
0.1%
let r_ = h.length === 0 ? 1 : (h[h.length - 1].o === 1 ? h[h.length - 1].m : 1 - h[h.length - 1].m); r = Math.random() < 0.95 ? r : 1 - r;
0.1%
let r_ = h.length === 0 ? 1 : (h[h.length - 1].o === 1 ? h[h.length - 1].m : 1 - h[h.length - 1].m); r = Math.random() < 0.95 ? r_ : 1 - r_;
0.0%
r = h.every((r) => r.o);
0.0%
r = 1 && h.every((r) => r.o);
0.1%
r = 1; r = (d === 2) ? 1 : ((d < 14) ? 0 : h.every((r) => r.o))
0.3%
DaemonicSigil's private submission
0.0%
let ones = 0; let zeros = 0; for (let i = 0; i < c.length; i++) { if (c[i] === '1') { ones++; } else if (c[i] === '0') { zeros++; } } const total = ones + zeros; const random = Math.random(); if (random

A valid answer to this market is a line of Javascript code that plays the prisoner's dilemma.

To return its decision, your program should modify the variable "r" to be 0 for defection and 1 for cooperation. (Or anything that coerces to 0 or 1, like true/false.)

I will wrap your code in a function like this:

const p0 = function(d,m,c,s,f,h,i) {

let r = 9;

//Your code here

return Number(r);

};

  • "d" is a number that's the ID of its opponent. The first answer to this market (chronologically) has an ID of 0, the next of 1, etc.

  • "m" is the ID of the current program.

  • "c" is a string that is the source code of the opponent. (Just the user-submitted code, not the wrapper.)

  • "s" is a string that is the program's own source code.

  • "f" is a function f(a,d,m,c,s,f,h,i) that takes in a source code string a and (optionally) the 7 other args, adds the wrapper, runs it, and returns the result. (The other args will default to the ones from the calling context.) For example you could call f("r=0") and it will return 0.

  • "h" is an array with the history of all past games. Each entry of the array is an object with properties "m" and "o", (for "me" and "opponent") with values of 0 or 1 to denote defection or cooperation. For example, if they're playing for the 3rd time, and the first time they both cooperated and the second time your program defected and the other cooperated, h is [{"m":1,"o":1},{"m":0,"o":1}].

  • "i" is the history inverted, with m and o's values swapped in each object.

These programs will then be run against each other in a round-robin tournament where each program plays against every program exactly once. (Including itself.) Each match between two programs consists of a random number of games that could be anywhere from 1 to 100. (The match lengths are determined individually, so your program will have to play matches of many different lengths.)

Each game uses the traditional payoff matrix, converted to positive points; double cooperate gets 2 points each, double defect gets 1 point each, cooperate-defect gets 3 points to the defector and 0 to the cooperator. At the end of every match, points are normalized to a match length of 1 so that programs do not end up with more points just for lucking into a longer match. (For example, if your program played a 12-game match and ended with 21 points, that's normalized to 1.75 points towards its final total.)

Any program that attempts to escape the game, such as by referencing or modifying global variables that the top-level tournament program is using, my computer's file system, or the internet, is disqualified. If a program errors, it is disqualified. If a program returns anything other than 0 or 1, it is disqualified. If a program takes more than 1 second to return an answer, it is disqualified. (If the program spawns a child process, that child process may take longer than 1 second; I only care about the time taken until the top-level function returns. As an exception, if a program spawns so many child processes over the course of the tournament that it starts lagging my computer, I will treat that as a security issue and disqualify it.) Any program that is disqualified loses the entire tournament, not just that game or match, and you do not get a replacement submission. Please make sure your programs are well-formed, and don't make my life difficult.

The exact disqualification procedure is as follows:

  • Any program that seems like a security risk is disqualified preemptively. (i.e. file system or internet access, or trying to read/modify disallowed external variables.)

  • All other programs are put onto a list, then the tournament is started with that list.

  • A random program is picked and played against a random program, repeating this process until all its matches are done, then moving on to the next. If a bot ever returns an invalid result, errors, quits the tournament, or runs for more than 1 second without returning a result, the tournament is halted, that bot is removed from the list, all scores are reset, and the tournament starts over from this step with the new, smaller list of contestants.

  • If I notice my computer slowing down during the course of the tournament due to a large number of unkilled infinitely looping child processes, I will halt the tournament, figure out which program is responsible, disqualify it, publicly shame it just for good measure, and then start over from step 3.

The program with the highest final point total wins. If there is a tie, I will run a second tournament of the same structure that includes only the tied programs, repeating this process until there is a single winner. If this ends in a stable equilibrium of tied programs, I'll resolve to all of them equally.

If you'd like to see the exact code that will be used to run the tournament, it's available here.

Each person may submit a maximum of 3 programs. One of them may be private, the other two must be public. To make your private submission, add an answer that says "[name]'s private submission" so that people know you're going to be submitting one and can bet on how it will do. I'll reach out to you to get its code once the market closes. (If you don't have a Manifold account, reach out to me on some other platform. I'll donate your winnings to a charity of your choice.)

This market closes once it doesn't seem like any new submissions will be forthcoming any time soon. I will run the game, PM the winner and briefly reopen the market to let them bet on the winning answer (so they get to profit the most mana, as their reward for winning), then resolve the market.

I have started us off with one cooperate-bot, one defect-bot, and one tit-for-tat-bot. I may make additional some additional submissions myself, but only public ones, only if I think it would make this market more fun, and only before I've seen anyone's private submission.

If there's a serious problem with these criteria, please tell me ASAP and I will modify them accordingly to fix the issue.

If you want to participate but are not familiar with Javascript, please don't submit potentially-broken code. Just describe to me what you'd like your bot to do in pseudocode (i.e. English, being very specific about exactly what it does and leaving no ambiguities), and I'll translate it into Javascript for you.

Alternatively, we can set up a time to have a voice call on Discord, and I'll give you a crash course in the Javascript features you need for a challenge like this. Expect this to take 30-90 minutes.

Get
Ṁ1,000
to start trading!

🏅 Top traders

#NameTotal profit
1Ṁ3,972
2Ṁ387
3Ṁ364
4Ṁ297
5Ṁ173
© Manifold Markets, Inc.TermsPrivacy