diff --git a/dist/index.html b/dist/index.html index 02f41dc..df1b268 100644 --- a/dist/index.html +++ b/dist/index.html @@ -222,14 +222,15 @@

Stats

-

Organism count:

-

Highest count:

+

Total Population:

+

Number of Species:

+

Largest Organism Ever:

Average Mutation Rate:

-

Largest Organism:

diff --git a/dist/js/bundle.js b/dist/js/bundle.js index 4b18cc8..8fdf209 100644 --- a/dist/js/bundle.js +++ b/dist/js/bundle.js @@ -1 +1 @@ -!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,n=i/2+i/4,a=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,a,n),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(5),o={setDefaults:function(){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(12),r={init:function(){this.extant_species=[],this.extinct_species=[],this.min_discard=10,this.record_size_limit=500,this.setData()},setEnv:function(t){this.env=t},addSpecies:function(t,e){var i=new o(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_popthis.record_size_limit&&(this.tick_record.shift(),this.pop_counts.shift(),this.av_pop_counts.shift(),this.species_counts.shift(),this.av_mut_rates.shift())},clear_record:function(){this.extant_species=[],this.extinct_species=[],this.setData()}};r.init(),t.exports=r},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_distance1){c=this.anatomy.getRandomCell();e=this.anatomy.removeCell(c.loc_col,c.loc_row)}return e}attemptMove(){var t=n.scalars[this.direction],e=t[0],i=t[1],o=this.c+e,r=this.r+i;if(this.isClear(o,r)){for(var a of this.anatomy.cells){var l=this.c+a.rotatedCol(this.rotation),h=this.r+a.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=n.getRandomDirection(),this.move_count=0,!0;var t=n.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=n.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 n=e;n!=s;n++){var a=this.env.grid_map.cellAt(t,n);if(!this.isPassableCell(a,o))return!1}return!0}if(t>i){r=i;i=t,t=r}for(n=t;n!=i;n++){a=this.env.grid_map.cellAt(n,e);if(!this.isPassableCell(a,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 n of this.anatomy.cells){var a=this.getRealCell(n,t,e,i);if(null==a)return!1;if(!(a.owner==this||a.state==s.empty||!r.foodBlocksReproduction&&a.state==s.food||o&&n.state==s.armor&&a.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(n.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,i){const s=i(2);t.exports=class{constructor(t){this.data=[],this.chart=new CanvasJS.Chart("chartContainer",{zoomEnabled:!0,title:{text:t},data:this.data}),this.chart.render(),this.data}setData(){alert("Must override updateData!")}render(){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=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){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}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(34),n=i(36);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 n(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),t>300&&(t=300),this.fps=t,this.game_loop=setInterval(function(){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.necessaryUpdate()}.bind(this),1e3/60))}environmentUpdate(){this.delta_time=Date.now()-this.last_update,this.last_update=Date.now(),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.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),n=i(6),a=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(){this.renderer.renderCells(),this.renderer.renderHighlights()}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 n(t[0],t[1],this);e.anatomy.addDefaultCell(a.mouth,0,0),e.anatomy.addDefaultCell(a.producer,1,1),e.anatomy.addDefaultCell(a.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==a.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==a.wall&&this.changeCell(t.col,t.row,a.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;i3&&(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 n.up:o=-1;break;case n.down:o=1;break;case n.right:i=1;break;case n.left:i=-1}for(var l=this.getRealCol(),h=this.getRealRow(),c=l,d=h,u=null,p=0;pthis.organism_record&&(this.organism_record=t),$("#org-record").text("Highest count: "+this.env.organism_record),$("#avg-mut").text("Average Mutation Rate: "+Math.round(100*this.env.averageMutability())/100),$("#largest-org").text("Largest Organism: "+this.env.largest_cell_count+" cells")}reset(){this.setChart()}}},function(t,e,i){const s=i(2),o=i(8);t.exports=class extends o{constructor(){super("Population")}setData(){for(var t in this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"pop1",legendText:"Total Population",dataPoints:[]}),s.tick_record){var e=s.tick_record[t],i=s.pop_counts[t];this.data[0].dataPoints.push({x:e,y:i})}}addNewest(){var t=s.tick_record.length-1,e=s.tick_record[t],i=s.pop_counts[t];this.data[0].dataPoints.push({x:e,y:i})}removeOldest(){this.data[0].dataPoints.shift()}}},function(t,e,i){const s=i(2),o=i(8);t.exports=class extends o{constructor(){super("Species")}setData(){for(var t in this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"spec",legendText:"Number of Species",dataPoints:[]}),s.tick_record){var e=s.tick_record[t],i=s.species_counts[t];this.data[0].dataPoints.push({x:e,y:i})}}addNewest(){var t=s.tick_record.length-1,e=s.tick_record[t],i=s.species_counts[t];this.data[0].dataPoints.push({x:e,y:i})}removeOldest(){this.data[0].dataPoints.shift()}}},function(t,e,i){const s=i(2),o=i(8);t.exports=class extends o{constructor(){super("Mutation Rate")}setData(){for(var t in this.clear(),this.data.push({type:"line",markerType:"none",color:"black",showInLegend:!0,name:"pop1",legendText:"Average Mutation Rate",dataPoints:[]}),s.tick_record){var e=s.tick_record[t],i=s.av_mut_rates[t];this.data[0].dataPoints.push({x:e,y:i})}}addNewest(){var t=s.tick_record.length-1,e=s.tick_record[t],i=s.av_mut_rates[t];this.data[0].dataPoints.push({x:e,y:i})}removeOldest(){this.data[0].dataPoints.shift()}}},function(t,e,i){const s=i(9),o=i(6),r=i(11),n=i(10),a=i(0),l=i(35),h=i(12);t.exports=class extends s{constructor(){super(),this.is_active=!0;this.renderer=new n("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],n=this.organism.anatomy.getLocalCell(o,r);if(null!=n){var a=this.organism.anatomy.replaceCell(i,n.loc_col,n.loc_row,!1);this.changeCell(t,e,i,a)}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,a.empty,null),this.organism.species=new h(this.organism.anatomy,null,0)):alert("Cannot remove center cell")}setOrganismToCopyOf(t){this.grid_map.fillGrid(a.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(a.empty);var t=this.grid_map.getCenter();this.organism=new o(t[0],t[1],this,null),this.organism.anatomy.addDefaultCell(a.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(7),r=i(0),n=i(3),a=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=n.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),a.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)}}}]); \ No newline at end of file +!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,n=i/2+i/4,a=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,a,n),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.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),n={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_pop0&&(e=this.env.total_cells/this.env.organisms.length),this.av_cells.push(e),this.av_cell_counts.push(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())},calcCellCountAverages(){var t=this.env.organisms.length,e={};for(let t of o.living)e[t.name]=0;for(let t of this.extant_species)for(let i in t.cell_counts)e[i]+=t.cell_counts[i]*t.population;if(0==t)return e;for(let i in e)e[i]/=t;return e},clear_record:function(){this.extant_species=[],this.extinct_species=[],this.setData()}};n.init(),t.exports=n},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_distance0&&(e=this.data[0].dataPoints[this.data[0].dataPoints.length-1].x,e=this.data[0].dataPoints[0].x),e1){c=this.anatomy.getRandomCell();e=this.anatomy.removeCell(c.loc_col,c.loc_row)}return e}attemptMove(){var t=n.scalars[this.direction],e=t[0],i=t[1],o=this.c+e,r=this.r+i;if(this.isClear(o,r)){for(var a of this.anatomy.cells){var l=this.c+a.rotatedCol(this.rotation),h=this.r+a.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=n.getRandomDirection(),this.move_count=0,!0;var t=n.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=n.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 n=e;n!=s;n++){var a=this.env.grid_map.cellAt(t,n);if(!this.isPassableCell(a,o))return!1}return!0}if(t>i){r=i;i=t,t=r}for(n=t;n!=i;n++){a=this.env.grid_map.cellAt(n,e);if(!this.isPassableCell(a,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 n of this.anatomy.cells){var a=this.getRealCell(n,t,e,i);if(null==a)return!1;if(!(a.owner==this||a.state==s.empty||!r.foodBlocksReproduction&&a.state==s.food||o&&n.state==s.armor&&a.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(n.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=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),n=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 n(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),t>300&&(t=300),this.fps=t,this.game_loop=setInterval(function(){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.necessaryUpdate()}.bind(this),1e3/60))}environmentUpdate(){this.delta_time=Date.now()-this.last_update,this.last_update=Date.now(),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.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),n=i(7),a=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.total_cells=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(){this.renderer.renderCells(),this.renderer.renderHighlights()}removeOrganisms(t){for(var e of t.reverse())this.total_mutability-=this.organisms[e].mutability,this.total_cells-=this.organisms[e].anatomy.cells.length,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 n(t[0],t[1],this);e.anatomy.addDefaultCell(a.mouth,0,0),e.anatomy.addDefaultCell(a.producer,1,1),e.anatomy.addDefaultCell(a.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),this.total_cells+=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==a.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==a.wall&&this.changeCell(t.col,t.row,a.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;i3&&(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 n.up:o=-1;break;case n.down:o=1;break;case n.right:i=1;break;case n.left:i=-1}for(var l=this.getRealCol(),h=this.getRealRow(),c=l,d=h,u=null,p=0;p this.largest_cell_count) this.largest_cell_count = organism.anatomy.cells.length; + this.total_cells += organism.anatomy.cells.length; } averageMutability() { @@ -122,12 +125,13 @@ class WorldEnvironment extends Environment{ } } - reset(clear_walls=true) { + reset() { this.organisms = []; this.grid_map.fillGrid(CellStates.empty); this.renderer.renderFullGrid(this.grid_map.grid); this.total_mutability = 0; this.total_ticks = 0; + this.total_cells = 0; FossilRecord.clear_record(); this.OriginOfLife(); } diff --git a/src/Stats/Charts/CellsChart.js b/src/Stats/Charts/CellsChart.js new file mode 100644 index 0000000..5110941 --- /dev/null +++ b/src/Stats/Charts/CellsChart.js @@ -0,0 +1,51 @@ +const CellStates = require("../../Organism/Cell/CellStates"); +const FossilRecord = require("../FossilRecord"); +const ChartController = require("./ChartController"); + +class CellsChart extends ChartController { + constructor() { + super("Organism Size / Composition"); + } + + setData() { + this.clear(); + //this.mouth, this.producer, this.mover, this.killer, this.armor, this.eye + this.data.push({ + type: "line", + markerType: "none", + color: 'black', + showInLegend: true, + name: "pop1", + legendText: "Avg. organism size", + dataPoints: [] + } + ); + for (var c of CellStates.living) { + this.data.push({ + type: "line", + markerType: "none", + color: c.color, + showInLegend: true, + name: c.name, + legendText: "Avg. " + c.name + " cells", + dataPoints: [] + } + ); + } + this.addAllDataPoints(); + } + + addDataPoint(i) { + var t = FossilRecord.tick_record[i]; + var p = FossilRecord.av_cells[i]; + this.data[0].dataPoints.push({x:t, y:p}); + var j=1; + for (var name in FossilRecord.av_cell_counts[i]) { + var count = FossilRecord.av_cell_counts[i][name]; + this.data[j].dataPoints.push({x:t,y:count}) + j++; + } + } +} + +module.exports = CellsChart; \ No newline at end of file diff --git a/src/Stats/Charts/ChartController.js b/src/Stats/Charts/ChartController.js index a8825f5..52f5757 100644 --- a/src/Stats/Charts/ChartController.js +++ b/src/Stats/Charts/ChartController.js @@ -18,6 +18,12 @@ class ChartController { alert("Must override updateData!"); } + addAllDataPoints(){ + for (var i in FossilRecord.tick_record) { + this.addDataPoint(i) + } + } + render() { this.chart.render(); } @@ -39,11 +45,18 @@ class ChartController { } addNewest() { - alert("Must override addNewest!"); + var i = FossilRecord.tick_record.length-1; + this.addDataPoint(i); + } + + addDataPoint(i) { + alert("Must override addDataPoint") } removeOldest() { - alert("Must override addNewest!"); + for (var dps of this.data) { + dps.dataPoints.shift(); + } } clear() { diff --git a/src/Stats/Charts/MutationChart.js b/src/Stats/Charts/MutationChart.js index 9cc4562..f211bdb 100644 --- a/src/Stats/Charts/MutationChart.js +++ b/src/Stats/Charts/MutationChart.js @@ -18,24 +18,14 @@ class MutationChart extends ChartController { dataPoints: [] } ); - for (var i in FossilRecord.tick_record) { - var t = FossilRecord.tick_record[i]; - var p = FossilRecord.av_mut_rates[i]; - this.data[0].dataPoints.push({x:t, y:p}); - } - // console.log(this.data) + this.addAllDataPoints(); } - addNewest() { - var i = FossilRecord.tick_record.length-1; + addDataPoint(i) { var t = FossilRecord.tick_record[i]; var p = FossilRecord.av_mut_rates[i]; this.data[0].dataPoints.push({x:t, y:p}); } - - removeOldest() { - this.data[0].dataPoints.shift(); - } } module.exports = MutationChart; \ No newline at end of file diff --git a/src/Stats/Charts/PopulationChart.js b/src/Stats/Charts/PopulationChart.js index bb3eba4..99a02af 100644 --- a/src/Stats/Charts/PopulationChart.js +++ b/src/Stats/Charts/PopulationChart.js @@ -18,24 +18,14 @@ class PopulationChart extends ChartController { dataPoints: [] } ); - for (var i in FossilRecord.tick_record) { - var t = FossilRecord.tick_record[i]; - var p = FossilRecord.pop_counts[i]; - this.data[0].dataPoints.push({x:t, y:p}); - } - // console.log(this.data) + this.addAllDataPoints(); } - addNewest() { - var i = FossilRecord.tick_record.length-1; + addDataPoint(i) { var t = FossilRecord.tick_record[i]; var p = FossilRecord.pop_counts[i]; this.data[0].dataPoints.push({x:t, y:p}); } - - removeOldest() { - this.data[0].dataPoints.shift(); - } } module.exports = PopulationChart; \ No newline at end of file diff --git a/src/Stats/Charts/SpeciesChart.js b/src/Stats/Charts/SpeciesChart.js index b330a04..50c6b84 100644 --- a/src/Stats/Charts/SpeciesChart.js +++ b/src/Stats/Charts/SpeciesChart.js @@ -18,23 +18,14 @@ class SpeciesChart extends ChartController { dataPoints: [] } ); - for (var i in FossilRecord.tick_record) { - var t = FossilRecord.tick_record[i]; - var p = FossilRecord.species_counts[i]; - this.data[0].dataPoints.push({x:t, y:p}); - } + this.addAllDataPoints(); } - addNewest() { - var i = FossilRecord.tick_record.length-1; + addDataPoint(i) { var t = FossilRecord.tick_record[i]; var p = FossilRecord.species_counts[i]; this.data[0].dataPoints.push({x:t, y:p}); } - - removeOldest() { - this.data[0].dataPoints.shift(); - } } module.exports = SpeciesChart; \ No newline at end of file diff --git a/src/Stats/FossilRecord.js b/src/Stats/FossilRecord.js index 8da97ad..8a53c48 100644 --- a/src/Stats/FossilRecord.js +++ b/src/Stats/FossilRecord.js @@ -1,3 +1,4 @@ +const CellStates = require("../Organism/Cell/CellStates"); const Species = require("./Species"); const FossilRecord = { @@ -9,11 +10,11 @@ const FossilRecord = { this.min_discard = 10; this.record_size_limit = 500; // store this many data points - this.setData(); }, setEnv: function(env) { this.env = env; + this.setData(); }, addSpecies: function(org, ancestor) { @@ -66,9 +67,10 @@ const FossilRecord = { // all parallel arrays this.tick_record = [0]; this.pop_counts = [1]; - this.av_pop_counts = [1] this.species_counts = [1]; this.av_mut_rates = [5]; + this.av_cells = [3]; + this.av_cell_counts = [this.calcCellCountAverages()]; }, updateData() { @@ -77,15 +79,41 @@ const FossilRecord = { this.pop_counts.push(this.env.organisms.length); this.species_counts.push(this.extant_species.length); this.av_mut_rates.push(this.env.averageMutability()); + let av_cell = 0; + if (this.env.organisms.length > 0) { + av_cell = this.env.total_cells / this.env.organisms.length; + } + this.av_cells.push(av_cell); + this.av_cell_counts.push(this.calcCellCountAverages()) + if (this.tick_record.length > this.record_size_limit) { this.tick_record.shift(); this.pop_counts.shift(); - this.av_pop_counts.shift(); this.species_counts.shift(); this.av_mut_rates.shift(); + this.av_cells.shift(); } }, + calcCellCountAverages() { + var total_org = this.env.organisms.length; + var cell_counts = {}; + for (let c of CellStates.living) { + cell_counts[c.name] = 0; + } + for (let s of this.extant_species) { + for (let name in s.cell_counts) { + cell_counts[name] += s.cell_counts[name] * s.population; + } + } + if (total_org == 0) + return cell_counts; + for (let c in cell_counts) { + cell_counts[c] /= total_org; + } + return cell_counts; + }, + clear_record: function() { this.extant_species = []; this.extinct_species = []; diff --git a/src/Stats/Species.js b/src/Stats/Species.js index 299faee..37daadd 100644 --- a/src/Stats/Species.js +++ b/src/Stats/Species.js @@ -1,3 +1,5 @@ +const CellStates = require("../Organism/Cell/CellStates"); + class Species { constructor(anatomy, ancestor, start_tick) { this.anatomy = anatomy; @@ -14,6 +16,18 @@ class Species { } this.name = '_' + Math.random().toString(36).substr(2, 9); this.extinct = false; + this.calcAnatomyDetails(); + } + + calcAnatomyDetails() { + var cell_counts = {}; + for (let c of CellStates.living) { + cell_counts[c.name] = 0; + } + for (let cell of this.anatomy.cells) { + cell_counts[cell.state.name]+=1; + } + this.cell_counts=cell_counts; } addPop() { diff --git a/src/Stats/StatsPanel.js b/src/Stats/StatsPanel.js index cfc3dbe..4487861 100644 --- a/src/Stats/StatsPanel.js +++ b/src/Stats/StatsPanel.js @@ -1,9 +1,11 @@ const PopulationChart = require("./Charts/PopulationChart"); const SpeciesChart = require("./Charts/SpeciesChart"); const MutationChart = require("./Charts/MutationChart"); +const CellsChart = require("./Charts/CellsChart"); +const FossilRecord = require("./FossilRecord"); -const ChartSelections = [PopulationChart, SpeciesChart, MutationChart]; +const ChartSelections = [PopulationChart, SpeciesChart, CellsChart, MutationChart]; class StatsPanel { constructor(env) { @@ -47,12 +49,11 @@ class StatsPanel { updateDetails() { var org_count = this.env.organisms.length; - $('#org-count').text("Organism count: " + org_count); - if (org_count > this.organism_record) - this.organism_record = org_count; - $('#org-record').text("Highest count: " + this.env.organism_record); + $('#org-count').text("Total Population: " + org_count); + $('#species-count').text("Number of Species: " + FossilRecord.extant_species.length); + $('#largest-org').text("Largest Organism Ever: " + this.env.largest_cell_count + " cells"); $('#avg-mut').text("Average Mutation Rate: " + Math.round(this.env.averageMutability() * 100) / 100); - $('#largest-org').text("Largest Organism: " + this.env.largest_cell_count + " cells"); + }