Tournament.SELECTION = 5; subscribe("rules/evolution",function(value){ Tournament.SELECTION = value; }); Tournament.NUM_TURNS = 10; subscribe("rules/turns",function(value){ Tournament.NUM_TURNS = value; }); // CREATE A RING OF AGENTS /*Tournament.INITIAL_AGENTS = [ {strategy:"tft", count:5}, {strategy:"all_d", count:5}, {strategy:"all_c", count:15}, {strategy:"grudge", count:0}, {strategy:"prober", count:0}, {strategy:"tf2t", count:0}, {strategy:"pavlov", count:0}, {strategy:"random", count:0} ];*/ Tournament.INITIAL_AGENTS = [ {strategy:"tft", count:5}, {strategy:"all_d", count:5}, {strategy:"all_c", count:0}, {strategy:"grudge", count:0}, {strategy:"prober", count:0}, {strategy:"tf2t", count:5}, {strategy:"pavlov", count:5}, {strategy:"random", count:5} ]; // OH THAT'S SO COOL. Mostly C: Pavlov wins, Mostly D: tit for two tats wins (with 5% mistake!) // ALSO, NOISE: tft vs all_d. no random: tft wins. low random: tf2t wins. high random: all_d wins. totally random: nobody wins ////////////////////////////////////////////// ////////////////////////////////////////////// // REGULAR LOAD Loader.addToManifest(Loader.manifest,{ tournament_peep: "assets/tournament/tournament_peep.json" }); function Tournament(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)"; var _convertCountToArray = function(countList){ var array = []; for(var i=0; i0) self.agents[0].kill(); // Convert to an array self.agents = _convertCountToArray(AGENTS); // Put 'em in a ring var count = 0; for(var i=0; i0) self.connections[0].kill(); // Connect all of 'em for(var i=0; i0) self.agents[_playIndex-1].dehighlightConnections(); if(_playIndex=1){ _tweenTimer = 0; self.STAGE = STAGE_REST; // slideshow.objects._b1.activate(); // activate NEXT button! } } }); // PLAY A TOURNAMENT self.deactivateAllButtons = function(){ // slideshow.objects._b1.deactivate(); // slideshow.objects._b2.deactivate(); // slideshow.objects._b3.deactivate(); }; self._startPlay = function(){ self.STAGE=STAGE_PLAY; // self.deactivateAllButtons(); }; subscribe("tournament/play", self._startPlay); self._startEliminate = function(){ self.STAGE=STAGE_ELIMINATE; // self.deactivateAllButtons(); }; subscribe("tournament/eliminate", self._startEliminate); self._startReproduce = function(){ self.STAGE=STAGE_REPRODUCE; // self.deactivateAllButtons(); }; subscribe("tournament/reproduce", self._startReproduce); // Add... self.add = function(INSTANT){ return _add(self); }; // Remove... // TODO: KILL ALL LISTENERS, TOO. // TODO: Don't screw up when paused or looking at new tab self.remove = function(INSTANT){ app.destroy(); return _remove(self); }; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// function TournamentConnection(config){ var self = this; self.config = config; self.tournament = config.tournament; // Connect from & to self.from = config.from; self.to = config.to; self.from.connections.push(self); self.to.connections.push(self); // Graphics! var g = new PIXI.Container(); var gray = PIXI.Sprite.fromImage("assets/tournament/connection.png"); // TODO: PRELOAD var gold = PIXI.Sprite.fromImage("assets/tournament/connection_gold.png"); // TODO: PRELOAD gray.height = 1; gold.height = 2; gray.anchor.y = gold.anchor.y = 0.5; g.addChild(gray); g.addChild(gold); self.graphics = g; // Highlight or no? self.highlight = function(){ gray.visible = false; gold.visible = true; }; self.dehighlight = function(){ gray.visible = true; gold.visible = false; }; self.dehighlight(); // Stretch dat bad boy self.updateGraphics = function(){ var f = self.from.graphics; var t = self.to.graphics; var dx = t.x-f.x; var dy = t.y-f.y; var a = Math.atan2(dy,dx); var dist = Math.sqrt(dx*dx+dy*dy); g.x = f.x; g.y = f.y; g.rotation = a; gray.width = gold.width = dist; }; self.updateGraphics(); // KILL self.IS_DEAD = false; self.kill = function(){ if(self.IS_DEAD) return; self.IS_DEAD = true; self.graphics.parent.removeChild(self.graphics); // remove self's graphics self.tournament.actuallyRemoveConnection(self); }; }; /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// function TournamentAgent(config){ var self = this; self.strategyName = config.strategy; self.tournament = config.tournament; self.angle = config.angle; self.gotoAngle = self.angle; // Connections self.connections = []; self.highlightConnections = function(){ for(var i=0;i