function TournamentSim(config){ var self = this; self.id = config.id; // APP var app = new PIXI.Application(500, 500, {transparent:true, resolution:2}); self.dom = app.view; // DOM self.dom.className = "object"; self.dom.style.width = 500; self.dom.style.height = 500; //self.dom.classList.add("fader"); self.dom.style.left = config.x+"px"; self.dom.style.top = config.y+"px"; self.dom.style.border = "1px solid rgba(0,0,0,0.2)"; // CREATE A RING OF AGENTS var AGENTS = [ {strategy:"all_c", count:20}, {strategy:"all_d", count:5}, {strategy:"grim", count:2}, {strategy:"tft", count:2}, ]; var _convertCountToArray = function(countList){ var array = []; for(var i=0; i250) body.scale.x*=-1; body.anchor.set(0.5); g.addChild(body); // Score! var textStyle = new PIXI.TextStyle({ fontFamily: 'Arial', fontSize: 16, }); var scoreText = new PIXI.Text("", textStyle); scoreText.anchor.x = 0.5; scoreText.x = 0; scoreText.y = -40; g.addChild(scoreText); self.updateScore = function(){ scoreText.text = self.coins; }; self.updateScore(); // What's the play logic? var LogicClass = window["Logic_"+self.strategyName]; self.logic = new LogicClass(); self.play = function(){ return self.logic.play(); }; self.remember = function(other){ self.logic.remember(other); }; // Reset! self.resetCoins = function(){ self.coins = 0; // reset coins; self.updateScore(); } self.resetLogic = function(){ self.logic = new LogicClass(); // reset logic }; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// var PD = {}; PD.COOPERATE = "COOPERATE"; PD.CHEAT = "CHEAT"; PD.P = 0; // punishment: neither of you get anything PD.S = -1; // sucker: you put in coin, other didn't. PD.R = 2; // reward: you both put 1 coin in, both got 3 back PD.T = 3; // temptation: you put no coin, got 3 coins anyway PD.getPayoffs = function(move1, move2){ if(move1==PD.CHEAT && move2==PD.CHEAT) return [PD.P, PD.P]; // both punished if(move1==PD.COOPERATE && move2==PD.CHEAT) return [PD.S, PD.T]; // sucker - temptation if(move1==PD.CHEAT && move2==PD.COOPERATE) return [PD.T, PD.S]; // temptation - sucker if(move1==PD.COOPERATE && move2==PD.COOPERATE) return [PD.R, PD.R]; // both rewarded }; PD.playOneGame = function(playerA, playerB){ var A = playerA.play(); var B = playerB.play(); var payoffs = PD.getPayoffs(A,B); playerA.remember(B); playerB.remember(A); playerA.addPayoff(payoffs[0]); playerB.addPayoff(payoffs[1]); }; PD.playRepeatedGame = function(playerA, playerB, turns){ // I've never met you before, let's pretend playerA.resetLogic(); playerB.resetLogic(); // Play N turns for(var i=0; i