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:15}, {strategy:"all_d", count:5}, {strategy:"grim", count:0}, {strategy:"tft", count:5}, ]; var _convertCountToArray = function(countList){ var array = []; 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... self.remove = function(INSTANT){ return _remove(self); }; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// function TournamentConnection(config){ var self = this; // 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/connection.png"); var gold = PIXI.Sprite.fromImage("assets/connection_gold.png"); 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 }; }; /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// 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