1 line
48 KiB
JavaScript
1 line
48 KiB
JavaScript
!function(t){var e={};function i(s){if(e[s])return e[s].exports;var o=e[s]={i:s,l:!1,exports:{}};return t[s].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(s,o,function(e){return t[e]}.bind(null,o));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=15)}([function(t,e){class i{constructor(t){this.name=t,this.color="black"}render(t,e,i){t.fillStyle=this.color,t.fillRect(e.x,e.y,i,i)}}const s={empty:new class extends i{constructor(){super("empty")}},food:new class extends i{constructor(){super("food")}},wall:new class extends i{constructor(){super("wall")}},mouth:new class extends i{constructor(){super("mouth")}},producer:new class extends i{constructor(){super("producer")}},mover:new class extends i{constructor(){super("mover")}},killer:new class extends i{constructor(){super("killer")}},armor:new class extends i{constructor(){super("armor")}},eye:new class extends i{constructor(){super("eye"),this.slit_color="black"}render(t,e,i){if(t.fillStyle=this.color,t.fillRect(e.x,e.y,i,i),1!=i){var s=i/2,o=-i/8,r=-s,a=i/2+i/4,n=i/4;t.translate(e.x+s,e.y+s),t.rotate(90*e.cell_owner.getAbsoluteDirection()*Math.PI/180),t.fillStyle=this.slit_color,t.fillRect(o,r,n,a),t.setTransform(1,0,0,1,0,0)}}},defineLists(){this.all=[this.empty,this.food,this.wall,this.mouth,this.producer,this.mover,this.killer,this.armor,this.eye],this.living=[this.mouth,this.producer,this.mover,this.killer,this.armor,this.eye]},getRandomName:function(){return this.all[Math.floor(Math.random()*this.all.length)].name},getRandomLivingType:function(){return this.living[Math.floor(Math.random()*this.living.length)]}};s.defineLists(),t.exports=s},function(t,e,i){const s=i(6),o={setDefaults:function(){this.headless=!1,this.lifespanMultiplier=100,this.foodProdProb=4,this.foodProdProbScalar=4,this.killableNeighbors=s.adjacent,this.edibleNeighbors=s.adjacent,this.growableNeighbors=s.adjacent,this.useGlobalMutability=!1,this.globalMutability=5,this.addProb=33,this.changeProb=33,this.removeProb=33,this.moversCanRotate=!0,this.offspringRotate=!0,this.foodBlocksReproduction=!0,this.moversCanProduce=!1,this.instaKill=!1,this.lookRange=20,this.foodDropProb=0},balanceMutationProbs:function(t){if(1==t){var e=100-this.addProb;this.changeProb=e/2,this.removeProb=e/2}else if(2==t){e=100-this.changeProb;this.addProb=e/2,this.removeProb=e/2}else{e=100-this.removeProb;this.changeProb=e/2,this.addProb=e/2}}};o.setDefaults(),t.exports=o},function(t,e,s){const o=s(0),r=s(12),a={init:function(){this.extant_species=[],this.extinct_species=[],this.min_discard=10,this.record_size_limit=500},setEnv:function(t){this.env=t,this.setData()},addSpecies:function(t,e){var i=new r(t.anatomy,e,this.env.total_ticks);return this.extant_species.push(i),t.species=i,i},addSpeciesObj:function(t){return this.extant_species.push(t),t},fossilize:function(t){for(i in t.end_tick=this.env.total_ticks,this.extant_species){var e=this.extant_species[i];if(e==t)return this.extant_species.splice(i,1),!(t.cumulative_pop<this.min_pop)&&(this.extinct_species.push(e),!0)}},resurrect:function(t){if(t.extinct)for(i in this.extinct_species){this.extinct_species[i]==t&&(this.extinct_species.splice(i,1),this.extant_species.push(t),t.extinct=!1)}},setData(){this.tick_record=[0],this.pop_counts=[0],this.species_counts=[0],this.av_mut_rates=[0],this.av_cells=[0],this.av_cell_counts=[this.calcCellCountAverages()]},updateData(){var t=this.env.total_ticks;this.tick_record.push(t),this.pop_counts.push(this.env.organisms.length),this.species_counts.push(this.extant_species.length),this.av_mut_rates.push(this.env.averageMutability()),this.calcCellCountAverages(),this.tick_record.length>this.record_size_limit&&(this.tick_record.shift(),this.pop_counts.shift(),this.species_counts.shift(),this.av_mut_rates.shift(),this.av_cells.shift(),this.av_cell_counts.shift())},calcCellCountAverages(){var t=0,e={};for(let t of o.living)e[t.name]=0;var i=!0;for(let s of this.extant_species)if(!(s.cumulative_pop<this.min_discard)||i){for(let t in s.cell_counts)e[t]+=s.cell_counts[t]*s.population;t+=s.population,i=!1}if(0==t)return e;var s=0;for(let i in e)s+=e[i],e[i]/=t;this.av_cells.push(s/t),this.av_cell_counts.push(e)},clear_record:function(){this.extant_species=[],this.extinct_species=[],this.setData()}};a.init(),t.exports=a},function(t,e){const i={up:0,right:1,down:2,left:3,scalars:[[0,-1],[1,0],[0,1],[-1,0]],getRandomDirection:function(){return Math.floor(4*Math.random())},getRandomScalar:function(){return this.scalars[Math.floor(Math.random()*this.scalars.length)]},getOppositeDirection:function(t){switch(t){case this.up:return this.down;case this.down:return this.up;case this.left:return this.right;case this.right:return this.left}},rotateRight:function(t){return++t>3&&(t=0),t}};t.exports=i},function(t,e,i){i(0);const s=i(3);t.exports=class{constructor(t,e,i,s){this.state=t,this.org=e,this.loc_col=i,this.loc_row=s;var o=Math.max(2*Math.abs(s)+2,2*Math.abs(i)+2);this.org.anatomy.birth_distance<o&&(this.org.anatomy.birth_distance=o)}initInherit(t){this.loc_col=t.loc_col,this.loc_row=t.loc_row}initRandom(){}initDefault(){}performFunction(t){}getRealCol(){return this.org.c+this.rotatedCol(this.org.rotation)}getRealRow(){return this.org.r+this.rotatedRow(this.org.rotation)}getRealCell(){var t=this.getRealCol(),e=this.getRealRow();return this.org.env.grid_map.cellAt(t,e)}rotatedCol(t){switch(t){case s.up:return this.loc_col;case s.down:return-1*this.loc_col;case s.left:return this.loc_row;case s.right:return-1*this.loc_row}}rotatedRow(t){switch(t){case s.up:return this.loc_row;case s.down:return-1*this.loc_row;case s.left:return-1*this.loc_col;case s.right:return this.loc_col}}}},function(t,e,i){const s=i(2);t.exports=class{constructor(t,e=""){this.data=[],this.chart=new CanvasJS.Chart("chartContainer",{zoomEnabled:!0,title:{text:t},axisX:{minimum:0},axisY:{minimum:0},data:this.data}),this.chart.render(),$("#chart-note").text(e)}setData(){alert("Must override updateData!")}setMinimum(){var t=0;this.data[0].dataPoints!=[]&&(t=this.data[0].dataPoints[0].x),this.chart.options.axisX.minimum=t}addAllDataPoints(){for(var t in s.tick_record)this.addDataPoint(t)}render(){this.setMinimum(),this.chart.render()}updateData(){var t=s.tick_record.length,e=-1;this.data[0].dataPoints.length>0&&(e=this.data[0].dataPoints[this.data[0].dataPoints.length-1].x,e=this.data[0].dataPoints[0].x),e<s.tick_record[t-1]&&this.addNewest(),0<s.tick_record[0]&&this.removeOldest()}addNewest(){var t=s.tick_record.length-1;this.addDataPoint(t)}addDataPoint(t){alert("Must override addDataPoint")}removeOldest(){for(var t of this.data)t.dataPoints.shift()}clear(){this.data.length=0,this.chart.render()}}},function(t,e){t.exports={all:[[0,1],[0,-1],[1,0],[-1,0],[-1,-1],[1,1],[-1,1],[1,-1]],adjacent:[[0,1],[0,-1],[1,0],[-1,0]],corners:[[-1,-1],[1,1],[-1,1],[1,-1]],allSelf:[[0,0],[0,1],[0,-1],[1,0],[-1,0],[-1,-1],[1,1],[-1,1],[1,-1]]}},function(t,e,i){const s=i(0),o=i(6),r=i(1),a=i(3),n=i(18),l=i(27),h=i(2);class c{constructor(t,e,i,s=null){this.c=t,this.r=e,this.env=i,this.lifetime=0,this.food_collected=0,this.living=!0,this.anatomy=new n(this),this.direction=a.down,this.rotation=a.up,this.can_rotate=r.moversCanRotate,this.move_count=0,this.move_range=4,this.ignore_brain_for=0,this.mutability=5,this.damage=0,this.brain=new l(this),null!=s&&this.inherit(s)}inherit(t){for(var e of(this.move_range=t.move_range,this.mutability=t.mutability,this.species=t.species,t.anatomy.cells))this.anatomy.addInheritCell(e);if(t.anatomy.is_mover)for(var i in t.brain.decisions)this.brain.decisions[i]=t.brain.decisions[i]}foodNeeded(){return this.anatomy.cells.length}lifespan(){return this.anatomy.cells.length*r.lifespanMultiplier}maxHealth(){return this.anatomy.cells.length}reproduce(){var t=new c(0,0,this.env,this);r.offspringRotate&&(t.rotation=a.getRandomDirection());var e=this.mutability;r.useGlobalMutability?e=r.globalMutability:Math.random()<=.5?t.mutability++:(t.mutability--,t.mutability<1&&(t.mutability=1));var i=!1;100*Math.random()<=e&&(t.anatomy.is_mover&&100*Math.random()<=10?(t.anatomy.has_eyes&&t.brain.mutate(),t.move_range+=Math.floor(4*Math.random())-2,t.move_range<=0&&(t.move_range=1)):i=t.mutate());var s=a.getRandomScalar(),o=s[0],n=s[1],l=Math.floor(3*Math.random()),d=this.anatomy.birth_distance,u=this.c+o*d+o*l,p=this.r+n*d+n*l;t.isClear(u,p,t.rotation,!0)&&t.isStraightPath(u,p,this.c,this.r,this)&&(t.c=u,t.r=p,this.env.addOrganism(t),t.updateGrid(),i?h.addSpecies(t,this.species):t.species.addPop()),this.food_collected-=this.foodNeeded()}mutate(){var t=Math.floor(100*Math.random()),e=!1;if(t<=r.addProb){var i=this.anatomy.getRandomCell(),a=s.getRandomLivingType(),n=o.all[Math.floor(Math.random()*o.all.length)],l=i.loc_col+n[0],h=i.loc_row+n[1];this.anatomy.canAddCellAt(l,h)&&(e=!0,this.anatomy.addRandomizedCell(a,l,h))}else if(t<=r.addProb+r.changeProb){var c=this.anatomy.getRandomCell();a=s.getRandomLivingType();this.anatomy.replaceCell(a,c.loc_col,c.loc_row),e=!0}else if(t<=r.addProb+r.changeProb+r.removeProb&&this.anatomy.cells.length>1){c=this.anatomy.getRandomCell();e=this.anatomy.removeCell(c.loc_col,c.loc_row)}return e}attemptMove(){var t=a.scalars[this.direction],e=t[0],i=t[1],o=this.c+e,r=this.r+i;if(this.isClear(o,r)){for(var n of this.anatomy.cells){var l=this.c+n.rotatedCol(this.rotation),h=this.r+n.rotatedRow(this.rotation);this.env.changeCell(l,h,s.empty,null)}return this.c=o,this.r=r,this.updateGrid(),!0}return!1}attemptRotate(){if(!this.can_rotate)return this.direction=a.getRandomDirection(),this.move_count=0,!0;var t=a.getRandomDirection();if(this.isClear(this.c,this.r,t)){for(var e of this.anatomy.cells){var i=this.c+e.rotatedCol(this.rotation),o=this.r+e.rotatedRow(this.rotation);this.env.changeCell(i,o,s.empty,null)}return this.rotation=t,this.direction=a.getRandomDirection(),this.updateGrid(),this.move_count=0,!0}return!1}changeDirection(t){this.direction=t,this.move_count=0}isStraightPath(t,e,i,s,o){if(t==i){if(e>s){var r=s;s=e,e=r}for(var a=e;a!=s;a++){var n=this.env.grid_map.cellAt(t,a);if(!this.isPassableCell(n,o))return!1}return!0}if(t>i){r=i;i=t,t=r}for(a=t;a!=i;a++){n=this.env.grid_map.cellAt(a,e);if(!this.isPassableCell(n,o))return!1}return!0}isPassableCell(t,e){return null!=t&&(t.state==s.empty||t.owner==this||t.owner==e||t.state==s.food)}isClear(t,e,i=this.rotation,o=!1){for(var a of this.anatomy.cells){var n=this.getRealCell(a,t,e,i);if(null==n)return!1;if(!(n.owner==this||n.state==s.empty||!r.foodBlocksReproduction&&n.state==s.food||o&&a.state==s.armor&&n.state==s.food))return!1}return!0}harm(){this.damage++,(this.damage>=this.maxHealth()||r.instaKill)&&this.die()}die(){for(var t of this.anatomy.cells){var e=this.c+t.rotatedCol(this.rotation),i=this.r+t.rotatedRow(this.rotation);this.env.changeCell(e,i,s.food,null)}this.species.decreasePop(),this.living=!1}updateGrid(){for(var t of this.anatomy.cells){var e=this.c+t.rotatedCol(this.rotation),i=this.r+t.rotatedRow(this.rotation);this.env.changeCell(e,i,t.state,t)}}update(){if(this.lifetime++,this.lifetime>this.lifespan())return this.die(),this.living;for(var t of(this.food_collected>=this.foodNeeded()&&this.reproduce(),this.anatomy.cells))if(t.performFunction(),!this.living)return this.living;if(this.anatomy.is_mover){this.move_count++;var e=!1;0==this.ignore_brain_for?e=this.brain.decide():this.ignore_brain_for--;var i=this.attemptMove();if(this.move_count>this.move_range&&!e||!i)this.attemptRotate()||(this.changeDirection(a.getRandomDirection()),e&&(this.ignore_brain_for=this.move_range+1))}return this.living}getRealCell(t,e=this.c,i=this.r,s=this.rotation){var o=e+t.rotatedCol(s),r=i+t.rotatedRow(s);return this.env.grid_map.cellAt(o,r)}}t.exports=c},function(t,e){t.exports={None:0,FoodDrop:1,WallDrop:2,ClickKill:3,Select:4,Edit:5,Clone:6,Drag:7}},function(t,e){t.exports=class{constructor(){}update(){alert("Environment.update() must be overriden")}changeCell(t,e,i,s){this.grid_map.setCellType(t,e,i),this.grid_map.setCellOwner(t,e,s)}}},function(t,e,i){i(0),i(3);t.exports=class{constructor(t,e,i){this.cell_size=i,this.canvas=document.getElementById(t),this.ctx=this.canvas.getContext("2d"),this.fillWindow(e),this.height=this.canvas.height,this.width=this.canvas.width,this.cells_to_render=new Set,this.cells_to_highlight=new Set,this.highlighted_cells=new Set}fillWindow(t){this.fillShape($("#"+t).height(),$("#"+t).width())}fillShape(t,e){this.canvas.width=e,this.canvas.height=t,this.height=this.canvas.height,this.width=this.canvas.width}clear(){this.ctx.fillStyle="white",this.ctx.fillRect(0,0,this.height,this.width)}renderFullGrid(t){for(var e of t)for(var i of e)this.renderCell(i)}renderCells(){for(var t of this.cells_to_render)this.renderCell(t);this.cells_to_render.clear()}renderCell(t){t.state.render(this.ctx,t,this.cell_size)}renderOrganism(t){for(var e of t.anatomy.cells){var i=t.getRealCell(e);this.renderCell(i)}}addToRender(t){this.highlighted_cells.has(t)&&this.cells_to_highlight.add(t),this.cells_to_render.add(t)}renderHighlights(){for(var t of this.cells_to_highlight)this.renderCellHighlight(t),this.highlighted_cells.add(t);this.cells_to_highlight.clear()}highlightOrganism(t){for(var e of t.anatomy.cells){var i=t.getRealCell(e);this.cells_to_highlight.add(i)}}highlightCell(t){this.cells_to_highlight.add(t)}renderCellHighlight(t,e="yellow"){this.renderCell(t),this.ctx.fillStyle=e,this.ctx.globalAlpha=.5,this.ctx.fillRect(t.x,t.y,this.cell_size,this.cell_size),this.ctx.globalAlpha=1,this.highlighted_cells.add(t)}clearAllHighlights(t=!1){for(var e of this.highlighted_cells)this.renderCell(e);this.highlighted_cells.clear(),t&&this.cells_to_highlight.clear()}}},function(t,e,i){const s=i(17),o=i(0);t.exports=class{constructor(t,e,i){this.resize(t,e,i)}resize(t,e,i){this.grid=[],this.cols=t,this.rows=e,this.cell_size=i;for(var r=0;r<t;r++){for(var a=[],n=0;n<e;n++){var l=new s(o.empty,r,n,r*i,n*i);a.push(l)}this.grid.push(a)}}fillGrid(t){for(var e of this.grid)for(var i of e)i.setType(t),i.owner=null,i.cell_owner=null}cellAt(t,e){return this.isValidLoc(t,e)?this.grid[t][e]:null}setCellType(t,e,i){this.isValidLoc(t,e)&&this.grid[t][e].setType(i)}setCellOwner(t,e,i){this.isValidLoc(t,e)&&(this.grid[t][e].cell_owner=i,this.grid[t][e].owner=null!=i?i.org:null)}isValidLoc(t,e){return t<this.cols&&e<this.rows&&t>=0&&e>=0}getCenter(){return[Math.floor(this.cols/2),Math.floor(this.rows/2)]}xyToColRow(t,e){var i=Math.floor(t/this.cell_size),s=Math.floor(e/this.cell_size);return i>=this.cols?i=this.cols-1:i<0&&(i=0),s>=this.rows?s=this.rows-1:s<0&&(s=0),[i,s]}}},function(t,e,i){const s=i(0);t.exports=class{constructor(t,e,i){if(this.anatomy=t,this.ancestor=e,this.population=1,this.cumulative_pop=1,this.start_tick=i,this.end_tick=-1,this.color=Math.floor(16777215*Math.random()).toString(16),null!=e){var s=Math.floor(16777215*Math.random())-8e6;this.color=(s+parseInt(e.color,16)).toString(16)}this.name="_"+Math.random().toString(36).substr(2,9),this.extinct=!1,this.calcAnatomyDetails()}calcAnatomyDetails(){var t={};for(let e of s.living)t[e.name]=0;for(let e of this.anatomy.cells)t[e.state.name]+=1;this.cell_counts=t}addPop(){this.population++,this.cumulative_pop++}decreasePop(){if(this.population--,this.population<=0){this.extinct=!0;i(2).fossilize(this)}}lifespan(){return this.end_tick-this.start_tick}}},function(t,e){t.exports=class{constructor(t,e){this.env=t,this.canvas=e,this.mouse_x,this.mouse_y,this.mouse_c,this.mouse_r,this.left_click=!1,this.right_click=!1,this.cur_cell=null,this.cur_org=null,this.highlight_org=!0,this.defineEvents()}setControlPanel(t){this.control_panel=t}defineEvents(){this.canvas.addEventListener("mousemove",t=>{this.updateMouseLocation(t.offsetX,t.offsetY),this.mouseMove()}),this.canvas.addEventListener("mouseup",function(t){t.preventDefault(),this.updateMouseLocation(t.offsetX,t.offsetY),this.mouseUp(),this.left_click=!1,this.right_click=!1}.bind(this)),this.canvas.addEventListener("mousedown",function(t){t.preventDefault(),this.updateMouseLocation(t.offsetX,t.offsetY),0==t.button&&(this.left_click=!0),2==t.button&&(this.right_click=!0),this.mouseDown()}.bind(this)),this.canvas.addEventListener("contextmenu",(function(t){t.preventDefault()})),this.canvas.addEventListener("mouseleave",function(){this.right_click=!1,this.left_click=!1,this.env.renderer.clearAllHighlights(!0)}.bind(this))}updateMouseLocation(t,e){var i=this.cur_cell,s=this.cur_org;this.mouse_x=t,this.mouse_y=e;var o=this.env.grid_map.xyToColRow(this.mouse_x,this.mouse_y);this.mouse_c=o[0],this.mouse_r=o[1],this.cur_cell=this.env.grid_map.cellAt(this.mouse_c,this.mouse_r),this.cur_org=this.cur_cell.owner,this.cur_org==s&&this.cur_cell==i||(this.env.renderer.clearAllHighlights(!0),null!=this.cur_org&&this.highlight_org?this.env.renderer.highlightOrganism(this.cur_org):null!=this.cur_cell&&this.env.renderer.highlightCell(this.cur_cell,!0))}mouseMove(){alert("mouse move must be overridden")}mouseDown(){alert("mouse down must be overridden")}mouseUp(){alert("mouse up must be overridden")}}},function(t,e,i){const s=i(16),o=i(29),r=i(35),a=i(37);t.exports=class{constructor(){this.fps=60,this.env=new s(5),this.organism_editor=new r,this.controlpanel=new o(this),this.colorscheme=new a(this.env,this.organism_editor),this.colorscheme.loadColorScheme(),this.env.OriginOfLife(),this.last_update=Date.now(),this.delta_time=0,this.actual_fps=0,this.running=!1}start(t=60){t<=0&&(t=1),this.fps=t,this.game_loop=setInterval(function(){this.updateDeltaTime(),this.environmentUpdate()}.bind(this),1e3/t),this.running=!0,this.fps>=60?null!=this.render_loop&&(clearInterval(this.render_loop),this.render_loop=null):this.setRenderLoop()}stop(){clearInterval(this.game_loop),this.running=!1,this.setRenderLoop()}setRenderLoop(){null==this.render_loop&&(this.render_loop=setInterval(function(){this.updateDeltaTime(),this.necessaryUpdate()}.bind(this),1e3/60))}updateDeltaTime(){this.delta_time=Date.now()-this.last_update,this.last_update=Date.now()}environmentUpdate(){this.env.update(this.delta_time),this.actual_fps=1/this.delta_time*1e3,null==this.render_loop&&this.necessaryUpdate()}necessaryUpdate(){this.env.render(),this.controlpanel.update(this.delta_time),this.organism_editor.update()}}},function(t,e,i){"use strict";i.r(e);var s=i(14),o=i.n(s);$("document").ready((function(){(function(){let t=!1;return function(e){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4)))&&(t=!0)}(navigator.userAgent||navigator.vendor||window.opera),t})()&&(alert("Though the simulation still works on mobile, most features are disabled. Try it on desktop for the full experience!"),$(".control-panel").css("display","none")),(new o.a).start(60)}))},function(t,e,i){const s=i(9),o=i(10),r=i(11),a=i(7),n=i(0),l=i(28),h=i(1),c=i(2);t.exports=class extends s{constructor(t){super(),this.renderer=new o("env-canvas","env",t),this.controller=new l(this,this.renderer.canvas);var e=Math.floor(this.renderer.height/t),i=Math.floor(this.renderer.width/t);this.grid_map=new r(i,e,t),this.organisms=[],this.walls=[],this.total_mutability=0,this.auto_reset=!0,this.largest_cell_count=0,this.reset_count=0,this.total_ticks=0,this.data_update_rate=100,c.setEnv(this)}update(t){var e=[];for(var i in this.organisms){var s=this.organisms[i];s.living&&s.update()||e.push(i)}h.foodDropProb>0&&this.generateFood(),this.removeOrganisms(e),this.total_ticks++,this.total_ticks%this.data_update_rate==0&&c.updateData()}render(){h.headless?this.renderer.cells_to_render.clear():(this.renderer.renderCells(),this.renderer.renderHighlights())}renderFull(){this.renderer.renderFullGrid(this.grid_map.grid)}removeOrganisms(t){for(var e of t.reverse())this.total_mutability-=this.organisms[e].mutability,this.organisms.splice(e,1);0==this.organisms.length&&this.auto_reset&&(this.reset_count++,this.reset())}OriginOfLife(){var t=this.grid_map.getCenter(),e=new a(t[0],t[1],this);e.anatomy.addDefaultCell(n.mouth,0,0),e.anatomy.addDefaultCell(n.producer,1,1),e.anatomy.addDefaultCell(n.producer,-1,-1),this.addOrganism(e),c.addSpecies(e,null)}addOrganism(t){t.updateGrid(),this.total_mutability+=t.mutability,this.organisms.push(t),t.anatomy.cells.length>this.largest_cell_count&&(this.largest_cell_count=t.anatomy.cells.length)}averageMutability(){return this.organisms.length<1?0:h.useGlobalMutability?h.globalMutability:this.total_mutability/this.organisms.length}changeCell(t,e,i,s){super.changeCell(t,e,i,s),this.renderer.addToRender(this.grid_map.cellAt(t,e)),i==n.wall&&this.walls.push(this.grid_map.cellAt(t,e))}clearWalls(){for(var t of this.walls)this.grid_map.cellAt(t.col,t.row).state==n.wall&&this.changeCell(t.col,t.row,n.empty,null)}clearOrganisms(){for(var t of this.organisms)t.die();this.organisms=[]}generateFood(){for(var t=Math.max(Math.floor(this.grid_map.cols*this.grid_map.rows*h.foodDropProb/5e4),1),e=h.foodDropProb,i=0;i<t;i++)if(Math.random()<=e){var s=Math.floor(Math.random()*this.grid_map.cols),o=Math.floor(Math.random()*this.grid_map.rows);this.grid_map.cellAt(s,o).state==n.empty&&this.changeCell(s,o,n.food,null)}}reset(){this.organisms=[],this.grid_map.fillGrid(n.empty),this.renderer.renderFullGrid(this.grid_map.grid),this.total_mutability=0,this.total_ticks=0,c.clear_record(),this.OriginOfLife()}resizeGridColRow(t,e,i){this.renderer.cell_size=t,this.renderer.fillShape(i*t,e*t),this.grid_map.resize(e,i,t)}resizeFillWindow(t){this.renderer.cell_size=t,this.renderer.fillWindow("env");var e=Math.floor(this.renderer.width/t),i=Math.floor(this.renderer.height/t);this.grid_map.resize(e,i,t)}}},function(t,e,i){i(0),i(1);t.exports=class{constructor(t,e,i,s,o){this.owner=null,this.cell_owner=null,this.setType(t),this.col=e,this.row=i,this.x=s,this.y=o}setType(t){this.state=t}}},function(t,e,i){const s=i(0),o=i(19);t.exports=class{constructor(t){this.owner=t,this.cells=[],this.is_producer=!1,this.is_mover=!1,this.has_eyes=!1,this.birth_distance=4}canAddCellAt(t,e){for(var i of this.cells)if(i.loc_col==t&&i.loc_row==e)return!1;return!0}addDefaultCell(t,e,i){var s=o.createDefault(this.owner,t,e,i);return this.cells.push(s),s}addRandomizedCell(t,e,i){t!=s.eye||this.has_eyes||this.owner.brain.randomizeDecisions();var r=o.createRandom(this.owner,t,e,i);return this.cells.push(r),r}addInheritCell(t){var e=o.createInherited(this.owner,t);return this.cells.push(e),e}replaceCell(t,e,i,s=!0){return this.removeCell(e,i,!0),s?this.addRandomizedCell(t,e,i):this.addDefaultCell(t,e,i)}removeCell(t,e,i=!1){if(0==t&&0==e&&!i)return!1;for(var s=0;s<this.cells.length;s++){var o=this.cells[s];if(o.loc_col==t&&o.loc_row==e){this.cells.splice(s,1);break}}return this.checkTypeChange(o.state),!0}getLocalCell(t,e){for(var i of this.cells)if(i.loc_col==t&&i.loc_row==e)return i;return null}checkTypeChange(){for(var t of(this.is_producer=!1,this.is_mover=!1,this.has_eyes=!1,this.cells))t.state==s.producer&&(this.is_producer=!0),t.state==s.mover&&(this.is_mover=!0),t.state==s.eye&&(this.has_eyes=!0)}getRandomCell(){return this.cells[Math.floor(Math.random()*this.cells.length)]}}},function(t,e,i){const s=i(20),o=i(21),r=i(22),a=i(23),n=i(24),l=i(25),h=i(0),c={init:function(){var t={};t[h.mouth.name]=s,t[h.producer.name]=o,t[h.mover.name]=r,t[h.killer.name]=a,t[h.armor.name]=n,t[h.eye.name]=l,this.type_map=t},createInherited:function(t,e){var i=new this.type_map[e.state.name](t,e.loc_col,e.loc_row);return i.initInherit(e),i},createRandom:function(t,e,i,s){var o=new this.type_map[e.name](t,i,s);return o.initRandom(),o},createDefault:function(t,e,i,s){var o=new this.type_map[e.name](t,i,s);return o.initDefault(),o}};c.init(),t.exports=c},function(t,e,i){const s=i(0),o=i(4),r=i(1);t.exports=class extends o{constructor(t,e,i){super(s.mouth,t,e,i)}performFunction(){var t=this.org.env,e=this.getRealCol(),i=this.getRealRow();for(var s of r.edibleNeighbors){var o=t.grid_map.cellAt(e+s[0],i+s[1]);this.eatNeighbor(o,t)}}eatNeighbor(t,e){null!=t&&t.state==s.food&&(e.changeCell(t.col,t.row,s.empty,null),this.org.food_collected++)}}},function(t,e,i){const s=i(0),o=i(4),r=i(1);t.exports=class extends o{constructor(t,e,i){super(s.producer,t,e,i),this.org.anatomy.is_producer=!0}performFunction(){if(!this.org.anatomy.is_mover||r.moversCanProduce){var t=this.org.env,e=r.foodProdProb,i=this.getRealCol(),o=this.getRealRow();if(100*Math.random()<=e){var a=r.growableNeighbors[Math.floor(Math.random()*r.growableNeighbors.length)],n=a[0],l=a[1],h=t.grid_map.cellAt(i+n,o+l);if(null!=h&&h.state==s.empty)return void t.changeCell(i+n,o+l,s.food,null)}}}}},function(t,e,i){const s=i(0),o=i(4);t.exports=class extends o{constructor(t,e,i){super(s.mover,t,e,i),this.org.anatomy.is_mover=!0}}},function(t,e,i){const s=i(0),o=i(4),r=i(1);t.exports=class extends o{constructor(t,e,i){super(s.killer,t,e,i)}performFunction(){var t=this.org.env,e=this.getRealCol(),i=this.getRealRow();for(var s of r.killableNeighbors){var o=t.grid_map.cellAt(e+s[0],i+s[1]);this.killNeighbor(o)}}killNeighbor(t){if(null!=t&&null!=t.owner&&t.owner!=this.org&&t.owner.living&&t.state!=s.armor){var e=t.state==s.killer;t.owner.harm(),r.instaKill&&e&&this.org.harm()}}}},function(t,e,i){const s=i(0),o=i(4);t.exports=class extends o{constructor(t,e,i){super(s.armor,t,e,i)}}},function(t,e,i){const s=i(0),o=i(4),r=i(1),a=i(3),n=i(26);t.exports=class extends o{constructor(t,e,i){super(s.eye,t,e,i),this.org.anatomy.has_eyes=!0}initInherit(t){super.initInherit(t),this.direction=t.direction}initRandom(){this.direction=a.getRandomDirection()}initDefault(){this.direction=a.up}getAbsoluteDirection(){var t=this.org.rotation+this.direction;return t>3&&(t-=4),t}performFunction(){var t=this.look();this.org.brain.observe(t)}look(){var t=this.org.env,e=this.getAbsoluteDirection(),i=0,o=0;switch(e){case a.up:o=-1;break;case a.down:o=1;break;case a.right:i=1;break;case a.left:i=-1}for(var l=this.getRealCol(),h=this.getRealRow(),c=l,d=h,u=null,p=0;p<r.lookRange&&(c+=i,d+=o,null!=(u=t.grid_map.cellAt(c,d)));p++)if(u.state!=s.empty){var m=Math.abs(l-c)+Math.abs(h-d);return new n(u,m,e)}return new n(u,r.lookRange,e)}}},function(t,e){t.exports=class{constructor(t,e,i){this.cell=t,this.distance=e,this.direction=i}}},function(t,e,i){const s=i(1),o=i(3),r=i(0),a=0,n=1,l=2,h=function(){return Math.floor(3*Math.random())};t.exports=class{constructor(t){this.owner=t,this.observations=[],this.decisions=[],this.decisions[r.empty.name]=a,this.decisions[r.food.name]=l,this.decisions[r.wall.name]=a,this.decisions[r.mouth.name]=a,this.decisions[r.producer.name]=a,this.decisions[r.mover.name]=a,this.decisions[r.killer.name]=n,this.decisions[r.armor.name]=a,this.decisions[r.eye.name]=a}randomizeDecisions(){this.decisions[r.mouth.name]=h(),this.decisions[r.producer.name]=h(),this.decisions[r.mover.name]=h(),this.decisions[r.armor.name]=h(),this.decisions[r.eye.name]=h()}observe(t){this.observations.push(t)}decide(){var t=a,e=s.lookRange+1,i=0;for(var r of this.observations)null!=r.cell&&r.cell.owner!=this.owner&&r.distance<e&&(t=this.decisions[r.cell.state.name],i=r.direction,e=r.distance);return this.observations=[],t==l?(this.owner.changeDirection(i),!0):t==n&&(this.owner.changeDirection(o.getOppositeDirection(i)),!0)}mutate(){this.decisions[r.getRandomName()]=h(),this.decisions[r.empty.name]=a}}},function(t,e,i){const s=i(13),o=i(7),r=i(8),a=i(0),n=i(6),l=i(2),h=i(1);t.exports=class extends s{constructor(t,e){super(t,e),this.mode=r.Drag,this.org_to_clone=null,this.add_new_species=!1,this.defineZoomControls(),this.scale=1}defineZoomControls(){var t=1;const e=document.querySelector("#env-canvas");e.onwheel=function(i){i.preventDefault();var s=-Math.sign(i.deltaY);if(.5!=(t=Math.max(.5,this.scale+.5*s))){var o=parseInt($("#env-canvas").css("top")),r=parseInt($("#env-canvas").css("left"));if(1==s)var a=(this.canvas.width/2-r/this.scale-this.mouse_x)*this.scale/1.5,n=(this.canvas.height/2-o/this.scale-this.mouse_y)*this.scale/1.5;else a=-r/t,n=-o/t;$("#env-canvas").css("top",o+n+"px"),$("#env-canvas").css("left",r+a+"px")}e.style.transform=`scale(${t})`,this.scale=t}.bind(this)}resetView(){$("#env-canvas").css("transform","scale(1)"),$("#env-canvas").css("top","0px"),$("#env-canvas").css("left","0px"),this.scale=1}updateMouseLocation(t,e){super.updateMouseLocation(t,e)}mouseMove(){this.performModeAction()}mouseDown(){this.start_x=this.mouse_x,this.start_y=this.mouse_y,this.performModeAction()}mouseUp(){}performModeAction(){if(!h.headless){var t=this.mode,e=this.right_click,i=this.left_click;if(t!=r.None&&(e||i)){var s=this.cur_cell;if(null==s)return;switch(t){case r.FoodDrop:i?this.dropCellType(s.col,s.row,a.food,!1):e&&this.dropCellType(s.col,s.row,a.empty,!1);break;case r.WallDrop:i?this.dropCellType(s.col,s.row,a.wall,!0):e&&this.dropCellType(s.col,s.row,a.empty,!1);break;case r.ClickKill:this.killNearOrganisms();break;case r.Select:null==this.cur_org&&(this.cur_org=this.findNearOrganism()),null!=this.cur_org&&this.control_panel.setEditorOrganism(this.cur_org);break;case r.Clone:if(null!=this.org_to_clone){var n=new o(this.mouse_c,this.mouse_r,this.env,this.org_to_clone);this.add_new_species?(l.addSpeciesObj(n.species),n.species.start_tick=this.env.total_ticks,this.add_new_species=!1,n.species.population=0):this.org_to_clone.species.extinct&&l.resurrect(this.org_to_clone.species),n.isClear(this.mouse_c,this.mouse_r)&&(this.env.addOrganism(n),n.species.addPop())}break;case r.Drag:var c=parseInt($("#env-canvas").css("top"),10),d=parseInt($("#env-canvas").css("left"),10),u=c+(this.mouse_y-this.start_y)*this.scale,p=d+(this.mouse_x-this.start_x)*this.scale;$("#env-canvas").css("top",u+"px"),$("#env-canvas").css("left",p+"px")}}}}dropCellType(t,e,i,s=!1){for(var o of n.allSelf){var r=t+o[0],a=e+o[1],l=this.env.grid_map.cellAt(r,a);if(null!=l){if(s&&null!=l.owner)l.owner.die();else if(null!=l.owner)continue;this.env.changeCell(r,a,i,null)}}}findNearOrganism(){for(var t of n.all){var e=this.cur_cell.col+t[0],i=this.cur_cell.row+t[1],s=this.env.grid_map.cellAt(e,i);if(null!=s&&null!=s.owner)return s.owner}return null}killNearOrganisms(){for(var t of n.allSelf){var e=this.cur_cell.col+t[0],i=this.cur_cell.row+t[1],s=this.env.grid_map.cellAt(e,i);null!=s&&null!=s.owner&&s.owner.die()}}}},function(t,e,i){const s=i(1),o=i(8),r=i(30);t.exports=class{constructor(t){this.engine=t,this.defineMinMaxControls(),this.defineEngineSpeedControls(),this.defineGridSizeControls(),this.defineTabNavigation(),this.defineHyperparameterControls(),this.defineModeControls(),this.defineChallenges(),this.fps=t.fps,this.organism_record=0,this.env_controller=this.engine.env.controller,this.editor_controller=this.engine.organism_editor.controller,this.env_controller.setControlPanel(this),this.editor_controller.setControlPanel(this),this.stats_panel=new r(this.engine.env),this.headless_opacity=1,this.opacity_change_rate=-.8,this.paused=!1}defineMinMaxControls(){var t=this;$("#minimize").click(function(){$(".control-panel").css("display","none"),$(".hot-controls").css("display","block"),this.stats_panel.stopAutoRender()}.bind(this)),$("#maximize").click((function(){$(".control-panel").css("display","grid"),$(".hot-controls").css("display","none"),"stats"==t.tab_id&&t.stats_panel.startAutoRender()}))}defineEngineSpeedControls(){this.slider=document.getElementById("slider"),this.slider.oninput=function(){this.fps=this.slider.value,this.engine.running&&this.changeEngineSpeed(this.fps),$("#fps").text("Target FPS: "+this.fps)}.bind(this),$(".pause-button").click(function(){$(".pause-button").find("i").toggleClass("fa fa-pause"),$(".pause-button").find("i").toggleClass("fa fa-play"),this.paused=!this.paused,this.engine.running?this.engine.stop():this.engine.running||this.engine.start(this.fps)}.bind(this)),$(".headless").click(function(){$(".headless").find("i").toggleClass("fa fa-eye"),$(".headless").find("i").toggleClass("fa fa-eye-slash"),s.headless?($("#headless-notification").css("display","none"),this.engine.env.renderFull()):$("#headless-notification").css("display","block"),s.headless=!s.headless}.bind(this))}defineGridSizeControls(){$("#fill-window").change((function(){this.checked?$(".col-row-input").css("display","none"):$(".col-row-input").css("display","block")})),$("#resize").click(function(){var t=$("#cell-size").val();if($("#fill-window").is(":checked"))this.engine.env.resizeFillWindow(t);else{var e=$("#col-input").val(),i=$("#row-input").val();this.engine.env.resizeGridColRow(t,e,i)}this.engine.env.reset(),this.stats_panel.reset()}.bind(this))}defineTabNavigation(){this.tab_id="about";var t=this;$(".tabnav-item").click((function(){$(".tab").css("display","none");var e="#"+this.id+".tab";$(e).css("display","grid"),t.engine.organism_editor.is_active="editor"==this.id,t.stats_panel.stopAutoRender(),"stats"==this.id&&t.stats_panel.startAutoRender(),t.tab_id=this.id}))}defineHyperparameterControls(){$("#food-prod-prob").change(function(){s.foodProdProb=$("#food-prod-prob").val()}.bind(this)),$("#lifespan-multiplier").change(function(){s.lifespanMultiplier=$("#lifespan-multiplier").val()}.bind(this)),$("#mover-rot").change((function(){s.moversCanRotate=this.checked})),$("#offspring-rot").change((function(){s.offspringRotate=this.checked})),$("#insta-kill").change((function(){s.instaKill=this.checked})),$("#look-range").change((function(){s.lookRange=$("#look-range").val()})),$("#food-drop-rate").change((function(){s.foodDropProb=$("#food-drop-rate").val()})),$("#evolved-mutation").change((function(){this.checked?($(".global-mutation-in").css("display","none"),$("#avg-mut").css("display","block")):($(".global-mutation-in").css("display","block"),$("#avg-mut").css("display","none")),s.useGlobalMutability=!this.checked})),$("#global-mutation").change((function(){s.globalMutability=parseInt($("#global-mutation").val())})),$(".mut-prob").change((function(){switch(this.id){case"add-prob":s.addProb=this.value,s.balanceMutationProbs(1);break;case"change-prob":s.changeProb=this.value,s.balanceMutationProbs(2);break;case"remove-prob":s.removeProb=this.value,s.balanceMutationProbs(3)}$("#add-prob").val(Math.floor(s.addProb)),$("#change-prob").val(Math.floor(s.changeProb)),$("#remove-prob").val(Math.floor(s.removeProb))})),$("#movers-produce").change((function(){s.moversCanProduce=this.checked})),$("#food-blocks").change((function(){s.foodBlocksReproduction=this.checked})),$("#reset-rules").click((function(){s.setDefaults(),$("#food-prod-prob").val(s.foodProdProb),$("#lifespan-multiplier").val(s.lifespanMultiplier),$("#mover-rot").prop("checked",s.moversCanRotate),$("#offspring-rot").prop("checked",s.offspringRotate),$("#insta-kill").prop("checked",s.instaKill),$("#evolved-mutation").prop("checked",!s.useGlobalMutability),$("#add-prob").val(s.addProb),$("#change-prob").val(s.changeProb),$("#remove-prob").val(s.removeProb),$("#movers-produce").prop("checked",s.moversCanProduce),$("#food-blocks").prop("checked",s.foodBlocksReproduction),$("#food-drop-rate").val(s.foodDropProb),$("#look-range").val(s.lookRange),s.useGlobalMutability?($(".global-mutation-in").css("display","block"),$("#avg-mut").css("display","none")):($(".global-mutation-in").css("display","none"),$("#avg-mut").css("display","block"))}))}defineModeControls(){var t=this;$(".edit-mode-btn").click((function(){switch($("#cell-selections").css("display","none"),$("#organism-options").css("display","none"),t.editor_controller.setDetailsPanel(),this.id){case"food-drop":t.setMode(o.FoodDrop);break;case"wall-drop":t.setMode(o.WallDrop);break;case"click-kill":t.setMode(o.ClickKill);break;case"select":t.setMode(o.Select);break;case"edit":t.setMode(o.Edit),t.editor_controller.setEditorPanel();break;case"drop-org":t.setMode(o.Clone),t.env_controller.org_to_clone=t.engine.organism_editor.getCopyOfOrg(),t.env_controller.add_new_species=t.editor_controller.new_species,t.editor_controller.new_species=!1;break;case"drag-view":t.setMode(o.Drag)}$(".edit-mode-btn").css("background-color","#9099c2"),$("#"+this.id).css("background-color","#81d2c7")})),$(".reset-view").click(function(){this.env_controller.resetView()}.bind(this));var e=this.engine.env;$("#reset-env").click(function(){this.engine.env.reset(),this.stats_panel.reset()}.bind(this)),$("#auto-reset").change((function(){e.auto_reset=this.checked})),$("#clear-walls").click(function(){confirm("Are you sure you want to clear all the walls?")&&this.engine.env.clearWalls()}.bind(this)),$("#clear-editor").click(function(){this.engine.organism_editor.clear(),this.editor_controller.setEditorPanel()}.bind(this))}defineChallenges(){$(".challenge-btn").click((function(){$("#challenge-title").text($(this).text()),$("#challenge-description").text($(this).val())}))}setMode(t){this.env_controller.mode=t,this.editor_controller.mode=t}setEditorOrganism(t){this.engine.organism_editor.setOrganismToCopyOf(t),this.editor_controller.clearDetailsPanel(),this.editor_controller.setDetailsPanel()}changeEngineSpeed(t){this.engine.stop(),this.engine.start(t),this.fps=this.engine.fps}updateHeadlessIcon(t){if(!this.paused){var e=this.headless_opacity+this.opacity_change_rate*t/1e3;e<=.4?(e=.4,this.opacity_change_rate=-this.opacity_change_rate):e>=1&&(e=1,this.opacity_change_rate=-this.opacity_change_rate),this.headless_opacity=e,$("#headless-notification").css("opacity",100*e+"%")}}update(t){$("#fps-actual").text("Actual FPS: "+Math.floor(this.engine.actual_fps)),$("#reset-count").text("Auto reset count: "+this.engine.env.reset_count),this.stats_panel.updateDetails(),s.headless&&this.updateHeadlessIcon(t)}}},function(t,e,i){const s=i(31),o=i(32),r=i(33),a=i(34),n=i(2),l=[s,o,a,r];t.exports=class{constructor(t){this.defineControls(),this.chart_selection=0,this.setChart(),this.env=t,this.last_reset_count=t.reset_count}setChart(t=this.chart_selection){this.chart_controller=new l[t],this.chart_controller.setData(),this.chart_controller.render()}startAutoRender(){this.setChart(),this.render_loop=setInterval(function(){this.updateChart()}.bind(this),1e3)}stopAutoRender(){clearInterval(this.render_loop)}defineControls(){$("#chart-option").change(function(){this.chart_selection=$("#chart-option")[0].selectedIndex,this.setChart()}.bind(this))}updateChart(){this.last_reset_count<this.env.reset_count&&this.reset(),this.last_reset_count=this.env.reset_count,this.chart_controller.updateData(),this.chart_controller.render()}updateDetails(){var t=this.env.organisms.length;$("#org-count").text("Total Population: "+t),$("#species-count").text("Number of Species: "+n.extant_species.length),$("#largest-org").text("Largest Organism Ever: "+this.env.largest_cell_count+" cells"),$("#avg-mut").text("Average Mutation Rate: "+Math.round(100*this.env.averageMutability())/100)}reset(){this.setChart()}}},function(t,e,i){const s=i(2),o=i(5);t.exports=class extends o{constructor(){super("Population")}setData(){this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"pop1",legendText:"Total Population",dataPoints:[]}),this.addAllDataPoints()}addDataPoint(t){var e=s.tick_record[t],i=s.pop_counts[t];this.data[0].dataPoints.push({x:e,y:i})}}},function(t,e,i){const s=i(2),o=i(5);t.exports=class extends o{constructor(){super("Species")}setData(){this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"spec",legendText:"Number of Species",dataPoints:[]}),this.addAllDataPoints()}addDataPoint(t){var e=s.tick_record[t],i=s.species_counts[t];this.data[0].dataPoints.push({x:e,y:i})}}},function(t,e,i){const s=i(2),o=i(5);t.exports=class extends o{constructor(){super("Mutation Rate")}setData(){this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"pop1",legendText:"Average Mutation Rate",dataPoints:[]}),this.addAllDataPoints()}addDataPoint(t){var e=s.tick_record[t],i=s.av_mut_rates[t];this.data[0].dataPoints.push({x:e,y:i})}}},function(t,e,i){const s=i(0),o=i(2),r=i(5);t.exports=class extends r{constructor(){super("Organism Size / Composition","Note: to maintain efficiency, species with very small populations are discarded when collecting cell statistics.")}setData(){for(var t of(this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"pop1",legendText:"Avg. organism size",dataPoints:[]}),s.living))this.data.push({type:"line",markerType:"none",color:t.color,showInLegend:!0,name:t.name,legendText:"Avg. "+t.name+" cells",dataPoints:[]});this.addAllDataPoints()}addDataPoint(t){var e=o.tick_record[t],i=o.av_cells[t];this.data[0].dataPoints.push({x:e,y:i});var s=1;for(var r in o.av_cell_counts[t]){var a=o.av_cell_counts[t][r];this.data[s].dataPoints.push({x:e,y:a}),s++}}}},function(t,e,i){const s=i(9),o=i(7),r=i(11),a=i(10),n=i(0),l=i(36),h=i(12);t.exports=class extends s{constructor(){super(),this.is_active=!0;this.renderer=new a("editor-canvas","editor-env",13),this.controller=new l(this,this.renderer.canvas),this.grid_map=new r(15,15,13),this.clear()}update(){this.is_active&&this.renderer.renderHighlights()}changeCell(t,e,i,s){super.changeCell(t,e,i,s),this.renderFull()}renderFull(){this.renderer.renderFullGrid(this.grid_map.grid)}addCellToOrg(t,e,i){var s=this.grid_map.getCenter(),o=t-s[0],r=e-s[1],a=this.organism.anatomy.getLocalCell(o,r);if(null!=a){var n=this.organism.anatomy.replaceCell(i,a.loc_col,a.loc_row,!1);this.changeCell(t,e,i,n)}else this.organism.anatomy.canAddCellAt(o,r)&&this.changeCell(t,e,i,this.organism.anatomy.addDefaultCell(i,o,r));this.organism.species=new h(this.organism.anatomy,null,0)}removeCellFromOrg(t,e){var i=this.grid_map.getCenter(),s=t-i[0],o=e-i[1];0!=s||0!=o?null!=this.organism.anatomy.getLocalCell(s,o)&&this.organism.anatomy.removeCell(s,o)&&(this.changeCell(t,e,n.empty,null),this.organism.species=new h(this.organism.anatomy,null,0)):alert("Cannot remove center cell")}setOrganismToCopyOf(t){this.grid_map.fillGrid(n.empty);var e=this.grid_map.getCenter();this.organism=new o(e[0],e[1],this,t),this.organism.updateGrid(),this.controller.updateDetails(),this.controller.new_species=!1}getCopyOfOrg(){return new o(0,0,null,this.organism)}clear(){this.grid_map.fillGrid(n.empty);var t=this.grid_map.getCenter();this.organism=new o(t[0],t[1],this,null),this.organism.anatomy.addDefaultCell(n.mouth,0,0),this.organism.updateGrid(),this.organism.species=new h(this.organism.anatomy,null,0)}}},function(t,e,i){const s=i(13),o=i(8),r=i(0),a=i(3),n=i(1);t.exports=class extends s{constructor(t,e){super(t,e),this.mode=o.None,this.edit_cell_type=null,this.highlight_org=!1,this.new_species=!1,this.defineCellTypeSelection(),this.defineEditorDetails()}mouseMove(){(this.right_click||this.left_click)&&this.editOrganism()}mouseDown(){this.editOrganism()}mouseUp(){}getCurLocalCell(){return this.env.organism.anatomy.getLocalCell(this.mouse_c-this.env.organism.c,this.mouse_r-this.env.organism.r)}editOrganism(){if(null!=this.edit_cell_type&&this.mode==o.Edit){if(this.left_click)if(this.edit_cell_type==r.eye&&this.cur_cell.state==r.eye){var t=this.getCurLocalCell();t.direction=a.rotateRight(t.direction),this.env.renderFull()}else this.env.addCellToOrg(this.mouse_c,this.mouse_r,this.edit_cell_type);else this.right_click&&this.env.removeCellFromOrg(this.mouse_c,this.mouse_r);this.new_species=!0,this.setBrainPanelVisibility(),this.setMoveRangeVisibility(),this.updateDetails()}}updateDetails(){$(".cell-count").text("Cell count: "+this.env.organism.anatomy.cells.length)}defineCellTypeSelection(){var t=this;$(".cell-type").click((function(){switch(this.id){case"mouth":t.edit_cell_type=r.mouth;break;case"producer":t.edit_cell_type=r.producer;break;case"mover":t.edit_cell_type=r.mover;break;case"killer":t.edit_cell_type=r.killer;break;case"armor":t.edit_cell_type=r.armor;break;case"eye":t.edit_cell_type=r.eye}$(".cell-type").css("border-color","black");var e="#"+this.id+".cell-type";$(e).css("border-color","yellow")}))}defineEditorDetails(){this.details_html=$("#organism-details"),this.edit_details_html=$("#edit-organism-details"),this.decision_names=["ignore","move away","move towards"],$("#move-range-edit").change(function(){this.env.organism.move_range=parseInt($("#move-range-edit").val())}.bind(this)),$("#observation-type-edit").change(function(){this.setBrainEditorValues($("#observation-type-edit").val()),this.setBrainDetails()}.bind(this)),$("#reaction-edit").change(function(){var t=$("#observation-type-edit").val(),e=parseInt($("#reaction-edit").val());this.env.organism.brain.decisions[t]=e,this.setBrainDetails()}.bind(this))}clearDetailsPanel(){$("#organism-details").css("display","none"),$("#edit-organism-details").css("display","none")}setDetailsPanel(){this.clearDetailsPanel();var t=this.env.organism;$(".cell-count").text("Cell count: "+t.anatomy.cells.length),$("#move-range").text("Move Range: "+t.move_range),$("#mutation-rate").text("Mutation Rate: "+t.mutability),n.useGlobalMutability?$("#mutation-rate").css("display","none"):$("#mutation-rate").css("display","block"),this.setMoveRangeVisibility(),this.setBrainPanelVisibility()&&this.setBrainDetails(),$("#organism-details").css("display","block")}setEditorPanel(){this.clearDetailsPanel();var t=this.env.organism;$(".cell-count").text("Cell count: "+t.anatomy.cells.length),this.setMoveRangeVisibility()&&$("#move-range-edit").val(t.move_range),this.setBrainPanelVisibility()&&this.setBrainEditorValues($("#observation-type-edit").val()),$("#cell-selections").css("display","grid"),$("#edit-organism-details").css("display","block")}setBrainPanelVisibility(){var t=this.env.organism;return t.anatomy.has_eyes&&t.anatomy.is_mover?($(".brain-details").css("display","block"),!0):($(".brain-details").css("display","none"),!1)}setBrainDetails(){var t=[],e=[];for(var i in this.env.organism.brain.decisions){var s=this.env.organism.brain.decisions[i];1==s?e.push(i):2==s&&t.push(i)}$(".chase-types").text("Move Towards: "+t),$(".retreat-types").text("Move Away From: "+e)}setMoveRangeVisibility(){return this.env.organism.anatomy.is_mover?($("#move-range-cont").css("display","block"),$("#move-range").css("display","block"),!0):($("#move-range-cont").css("display","none"),$("#move-range").css("display","none"),!1)}setBrainEditorValues(t){$("#observation-type-edit").val(t);var e=this.env.organism.brain.decisions[t];$("#reaction-edit").val(e)}}},function(t,e,i){const s=i(0);var o={empty:"#0E1318",food:"#2F7AB7",wall:"gray",mouth:"#DEB14D",producer:"#15DE59",mover:"#60D4FF",killer:"#F82380",armor:"#7230DB",eye:"#B6C1EA","eye-slit":"#0E1318"};t.exports=class{constructor(t,e){this.world_env=t,this.editor_env=e}loadColorScheme(){for(var t of s.all)t.color=o[t.name];for(var e in s.eye.slit_color=o["eye-slit"],o)$("#"+e+".cell-type ").css("background-color",o[e]),$("#"+e+".cell-legend-type").css("background-color",o[e]);this.world_env.renderer.renderFullGrid(this.world_env.grid_map.grid),this.editor_env.renderer.renderFullGrid(this.editor_env.grid_map.grid)}}}]); |