1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
!function(t){var e={};function i(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},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 r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(r,s,function(e){return t[e]}.bind(null,s));return r},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=11)}([function(t,e){const i={empty:0,food:1,wall:2,mouth:3,producer:4,mover:5,killer:6,armor:7,colors:["#121D29","green","gray","orange","white","#3493eb","red","purple"],getRandomLivingType:function(){return Math.floor(5*Math.random())+3}};t.exports=i},function(t,e,i){const r=i(2),s=i(0);t.exports=class{constructor(t,e,i,o=s.empty){this.grid=[],this.cols=t,this.rows=e,this.cell_size=i;for(var l=0;l<t;l++){for(var n=[],h=0;h<e;h++){var a=new r(o,l,h,l*i,h*i);n.push(a)}this.grid.push(n)}}fillGrid(t){for(var e of this.grid)for(var i of e)i.setType(t),i.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].owner=i)}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),r=Math.floor(e/this.cell_size);return i>=this.cols?i=this.cols-1:i<0&&(i=0),r>=this.rows?r=this.rows-1:r<0&&(r=0),[i,r]}}},function(t,e,i){const r=i(0),s=i(3);function o(t,e,i){null!=e&&e.type==r.food&&(i.changeCell(e.col,e.row,r.empty,null),t.owner.food_collected++)}function l(t,e){if(null!=e&&null!=e.owner&&null!=t.owner&&e.owner!=t.owner&&e.owner.living&&e.type!=r.armor){var i=e.type==r.killer;e.owner.harm(),i&&t.owner.harm()}}t.exports=class{constructor(t,e,i,r,s){this.owner=null,this.setType(t),this.col=e,this.row=i,this.x=r,this.y=s}setType(t){this.type=t}performFunction(t){switch(this.type){case r.mouth:!function(t,e){for(var i of s.edibleNeighbors){var r=e.grid_map.cellAt(t.col+i[0],t.row+i[1]);o(t,r,e)}}(this,t);break;case r.producer:!function(t,e){if(t.owner.is_mover)return;var i=s.foodProdProb;if(100*Math.random()<=i){var o=s.growableNeighbors[Math.floor(Math.random()*s.growableNeighbors.length)],l=o[0],n=o[1],h=e.grid_map.cellAt(t.col+l,t.row+n);if(null!=h&&h.type==r.empty)e.changeCell(t.col+l,t.row+n,r.food,null)}}(this,t);break;case r.killer:!function(t,e){for(var i of s.killableNeighbors){var r=e.grid_map.cellAt(t.col+i[0],t.row+i[1]);l(t,r)}}(this,t)}}getColor(){return r.colors[this.type]}isLiving(){return this.type!=r.empty&&this.type!=r.food&&this.type!=r.wall}}},function(t,e,i){const r=i(6),s={lifespanMultiplier:100,foodProdProb:4,foodProdProbScalar:4,killableNeighbors:r.adjacent,edibleNeighbors:r.adjacent,growableNeighbors:r.adjacent,useGlobalMutability:!1,globalMutability:0,addProb:33,changeProb:33,removeProb:33,moversCanRotate:!0,offspringRotate:!0,instaKill:!1,calcProducerFoodRatio:function(t=!0){t?this.foodProdProb=100/this.lifespanMultiplier*this.foodProdProbScalar:this.lifespanMultiplier=Math.floor(100/(this.foodProdProb/this.foodProdProbScalar))},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}}};t.exports=s},function(t,e,i){const r=i(0),s=(i(2),i(1),i(13)),o=i(6),l=i(3),n=i(8);class h{constructor(t,e,i,r=null){this.c=t,this.r=e,this.env=i,this.lifetime=0,this.food_collected=0,this.living=!0,this.cells=[],this.is_producer=!1,this.is_mover=!1,this.direction=n.up,this.rotation=n.up,this.can_rotate=l.moversCanRotate,this.move_count=0,this.move_range=4,this.mutability=5,this.damage=0,null!=r&&this.inherit(r)}addCell(t,e,i){for(var r of this.cells)if(r.loc_col==e&&r.loc_row==i)return!1;return this.checkProducerMover(t),this.cells.push(new s(t,e,i)),!0}removeCell(t,e){if(0==t&&0==e)return!1;for(var i=!1,s=0;s<this.cells.length;s++){if((o=this.cells[s]).loc_col==t&&o.loc_row==e){o.type!=r.producer&&o.type!=r.mover||(i=!0),this.cells.splice(s,1);break}}if(i)for(var o of(this.is_producer=!1,this.is_producer=!1,this.cells))this.checkProducerMover(o.type);return!0}getLocalCell(t,e){for(var i of this.cells)if(i.loc_col==t&&i.loc_row==e)return i;return null}checkProducerMover(t){t==r.producer&&(this.is_producer=!0),t==r.mover&&(this.is_mover=!0)}inherit(t){for(var e of(this.move_range=t.move_range,this.mutability=t.mutability,t.cells))this.addCell(e.type,e.loc_col,e.loc_row)}foodNeeded(){return this.cells.length}lifespan(){return this.cells.length*l.lifespanMultiplier}maxHealth(){return this.cells.length}reproduce(){var t=new h(0,0,this.env,this);l.offspringRotate&&(t.rotation=n.getRandomDirection());var e=this.mutability;l.useGlobalMutability?e=l.globalMutability:Math.random()<=.5?t.mutability++:(t.mutability--,t.mutability<1&&(t.mutability=1)),100*Math.random()<=e&&t.mutate();var i=n.getRandomScalar(),r=i[0],s=i[1],o=2*Math.floor(2*Math.random()),a=this.c+r*Math.min(2*this.cells.length,15)+r*o,c=this.r+s*Math.min(2*this.cells.length,15)+s*o;t.isClear(a,c)&&t.isStraightPath(a,c,this.c,this.r,this)&&(t.c=a,t.r=c,this.env.addOrganism(t),t.updateGrid()),this.food_collected-=this.foodNeeded()}mutate(){var t=Math.floor(100*Math.random()),e=!1;if(t<=l.addProb){var i=r.getRandomLivingType(),s=(Math.floor(3*Math.random()),this.cells[Math.floor(Math.random()*this.cells.length)]),n=o.all[Math.floor(Math.random()*o.all.length)],h=s.loc_col+n[0],a=s.loc_row+n[1];e=this.addCell(i,h,a)}else if(t<=l.addProb+l.changeProb){var c=this.cells[Math.floor(Math.random()*this.cells.length)];c.type=r.getRandomLivingType(),this.checkProducerMover(c.type),e=!0}else t<=l.addProb+l.changeProb+l.removeProb&&this.cells.length>1&&(c=this.cells[Math.floor(Math.random()*this.cells.length)],e=this.removeCell(c.loc_col,c.loc_row));return this.is_mover&&(this.move_range+=Math.floor(4*Math.random())-2,this.move_range<=0&&(this.move_range=1)),e}attemptMove(){var t=n.scalars[this.direction],e=t[0],i=t[1],s=this.c+e,o=this.r+i;if(this.isClear(s,o)){for(var l of this.cells){var h=this.c+l.rotatedCol(this.rotation),a=this.r+l.rotatedRow(this.rotation);this.env.changeCell(h,a,r.empty,null)}return this.c=s,this.r=o,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.cells){var i=this.c+e.rotatedCol(this.rotation),s=this.r+e.rotatedRow(this.rotation);this.env.changeCell(i,s,r.empty,null)}return this.rotation=t,this.direction=n.getRandomDirection(),this.updateGrid(),this.move_count=0,!0}return!1}isStraightPath(t,e,i,r,s){if(t==i){if(e>r){var o=r;r=e,e=o}for(var l=e;l!=r;l++){var n=this.env.grid_map.cellAt(t,l);if(!this.isPassableCell(n,s))return!1}return!0}if(t>i){o=i;i=t,t=o}for(l=t;l!=i;l++){n=this.env.grid_map.cellAt(l,e);if(!this.isPassableCell(n,s))return!1}return!0}isPassableCell(t,e){return null!=t&&(t.type==r.empty||t.owner==this||t.owner==e||t.type==r.food)}isClear(t,e,i=this.rotation){for(var s of this.cells){var o=this.getRealCell(s,t,e,i);if(null==o||o.type!=r.empty&&o.owner!=this)return!1}return!0}harm(){this.damage++,(this.damage>=this.maxHealth()||l.instaKill)&&this.die()}die(){for(var t of this.cells){var e=this.c+t.rotatedCol(this.rotation),i=this.r+t.rotatedRow(this.rotation);this.env.changeCell(e,i,r.food,null)}this.living=!1}updateGrid(){for(var t of this.cells){var e=this.c+t.rotatedCol(this.rotation),i=this.r+t.rotatedRow(this.rotation);this.env.changeCell(e,i,t.type,this)}}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.cells))this.getRealCell(t).performFunction(this.env);if(!this.living)return this.living;if(this.is_mover){this.move_count++;this.attemptMove();this.move_count>this.move_range&&this.attemptRotate()}return this.living}getRealCell(t,e=this.c,i=this.r,r=this.rotation){var s=e+t.rotatedCol(r),o=i+t.rotatedRow(r);return this.env.grid_map.cellAt(s,o)}}t.exports=h},function(t,e){t.exports={None:0,FoodDrop:1,WallDrop:2,ClickKill:3,Select:4,Edit:5,Clone:6}},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]]}},function(t,e){t.exports=class{constructor(t,e,i){this.cell_size=i,this.canvas=document.getElementById(t),this.ctx=this.canvas.getContext("2d"),this.canvas.width=$("#"+e).width(),this.canvas.height=$("#"+e).height(),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}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.ctx.fillStyle=i.getColor(),this.ctx.fillRect(i.x,i.y,this.cell_size,this.cell_size)}renderCells(){for(var t of this.cells_to_render)this.renderCell(t);this.cells_to_render.clear()}renderCell(t){this.ctx.fillStyle=t.getColor(),this.ctx.fillRect(t.x,t.y,this.cell_size,this.cell_size)}renderOrganism(t){for(var e of t.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.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){const i={up:0,down:1,left:2,right:3,scalars:[[0,-1],[0,1],[-1,0],[1,0]],getRandomDirection:function(){return Math.floor(4*Math.random())},getRandomScalar:function(){return this.scalars[Math.floor(Math.random()*this.scalars.length)]}};t.exports=i},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=>{var e=this.cur_cell,i=this.cur_org;this.mouse_x=t.offsetX,this.mouse_y=t.offsetY;var r=this.env.grid_map.xyToColRow(this.mouse_x,this.mouse_y);this.mouse_c=r[0],this.mouse_r=r[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==i&&this.cur_cell==e||(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)),this.mouseMove()}),this.canvas.addEventListener("mouseup",function(t){t.preventDefault(),this.left_click=!1,this.right_click=!1}.bind(this)),this.canvas.addEventListener("mousedown",function(t){t.preventDefault(),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))}mouseMove(){alert("mouse move must be overriden")}mouseDown(){alert("mouse down must be overriden")}}},function(t,e,i){const r=i(12),s=i(15),o=i(16);t.exports=class{constructor(){this.fps=60,this.env=new r(5),this.organism_editor=new o,this.controlpanel=new s(this),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 r=i(10),s=i.n(r);$("document").ready((function(){(new s.a).start(60)}))},function(t,e,i){i(1);const r=i(7),s=i(1),o=i(4),l=i(0),n=(i(2),i(14));t.exports=class{constructor(t){this.renderer=new r("env-canvas","env",t),this.controller=new n(this,this.renderer.canvas),this.grid_rows=Math.floor(this.renderer.height/t),this.grid_cols=Math.floor(this.renderer.width/t),this.grid_map=new s(this.grid_cols,this.grid_rows,t),this.renderer.renderFullGrid(this.grid_map.grid),this.organisms=[],this.walls=[],this.total_mutability=0}update(t){var e=[];for(var i in this.organisms){var r=this.organisms[i];r.living&&r.update()||e.push(i)}this.removeOrganisms(e)}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)}OriginOfLife(){var t=this.grid_map.getCenter(),e=new o(t[0],t[1],this);e.addCell(l.mouth,0,0),e.addCell(l.producer,-1,-1),e.addCell(l.producer,1,1),this.addOrganism(e)}addOrganism(t){t.updateGrid(),this.total_mutability+=t.mutability,this.organisms.push(t)}averageMutability(){return this.organisms.length<1?0:this.total_mutability/this.organisms.length}changeCell(t,e,i,r){this.grid_map.setCellType(t,e,i),this.grid_map.setCellOwner(t,e,r),this.renderer.addToRender(this.grid_map.cellAt(t,e)),i==l.wall&&this.walls.push(this.grid_map.cellAt(t,e))}clearWalls(){for(var t of this.walls)this.changeCell(t.col,t.row,l.empty,null)}clearOrganisms(){for(var t of this.organisms)t.die();this.organisms=[]}reset(){this.organisms=[],this.grid_map.fillGrid(l.empty),this.renderer.renderFullGrid(this.grid_map.grid),this.total_mutability=0,this.OriginOfLife()}}},function(t,e,i){i(0);const r=i(8);i(3);t.exports=class{constructor(t,e,i){this.type=t,this.loc_col=e,this.loc_row=i}rotatedCol(t){switch(t){case r.up:return this.loc_col;case r.down:return-1*this.loc_col;case r.left:return this.loc_row;case r.right:return-1*this.loc_row}}rotatedRow(t){switch(t){case r.up:return this.loc_row;case r.down:return-1*this.loc_row;case r.left:return-1*this.loc_col;case r.right:return this.loc_col}}}},function(t,e,i){const r=i(9),s=i(4),o=i(5),l=i(0);t.exports=class extends r{constructor(t,e){super(t,e),this.mode=o.None,this.org_to_clone=null}mouseMove(){this.performModeAction()}mouseDown(){this.performModeAction()}performModeAction(){var t=this.mode,e=this.right_click,i=this.left_click;if(t!=o.None&&(e||i)){var r=this.cur_cell;if(null==r)return;switch(t){case o.FoodDrop:i&&r.type==l.empty?this.env.changeCell(r.col,r.row,l.food,null):e&&r.type==l.food&&this.env.changeCell(r.col,r.row,l.empty,null);break;case o.WallDrop:!i||r.type!=l.empty&&r.type!=l.food?e&&r.type==l.wall&&this.env.changeCell(r.col,r.row,l.empty,null):this.env.changeCell(r.col,r.row,l.wall,null);break;case o.ClickKill:null!=this.cur_org&&this.cur_org.die();break;case o.Select:null!=this.cur_org&&this.control_panel.setEditorOrganism(this.cur_org);break;case o.Clone:if(null!=this.org_to_clone){var n=new s(this.mouse_c,this.mouse_r,this.env,this.org_to_clone);n.isClear(this.mouse_c,this.mouse_r)&&this.env.addOrganism(n)}}}}}},function(t,e,i){const r=i(3),s=i(5);i(0);t.exports=class{constructor(t){this.engine=t,this.defineEngineSpeedControls(),this.defineTabNavigation(),this.defineHyperparameterControls(),this.defineModeControls(),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)}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"==$("#pause-button").text()&&this.engine.running?($("#pause-button").text("Play"),this.engine.stop()):this.engine.running||($("#pause-button").text("Pause"),this.engine.start(this.fps))}.bind(this))}defineTabNavigation(){var t=this;$(".tabnav-item").click((function(){$(".tab").css("display","none");var e="#"+this.id+".tab";t.engine.organism_editor.is_active="editor"==this.id,$(e).css("display","grid")}))}defineHyperparameterControls(){$("#food-prod-prob").change(function(){var t=$("#food-prod-prob").val();$("#fixed-ratio").is(":checked")?(r.foodProdProb=t,r.calcProducerFoodRatio(!1),$("#lifespan-multiplier").val(r.lifespanMultiplier)):r.foodProdProb=t}.bind(this)),$("#lifespan-multiplier").change(function(){var t=$("#lifespan-multiplier").val();$("#fixed-ratio").is(":checked")?(r.lifespanMultiplier=t,r.calcProducerFoodRatio(!0),$("#food-prod-prob").val(r.foodProdProb)):r.lifespanMultiplier=t}.bind(this)),$(".mut-prob").change((function(){switch(this.id){case"add-prob":r.addProb=this.value,r.balanceMutationProbs(1);break;case"change-prob":r.changeProb=this.value,r.balanceMutationProbs(2);break;case"remove-prob":r.removeProb=this.value,r.balanceMutationProbs(3)}$("#add-prob").val(Math.floor(r.addProb)),$("#change-prob").val(Math.floor(r.changeProb)),$("#remove-prob").val(Math.floor(r.removeProb))})),$("#mover-rot").change((function(){r.moversCanRotate=this.checked})),$("#offspring-rot").change((function(){r.offspringRotate=this.checked})),$("#insta-kill").change((function(){r.instaKill=this.checked}))}defineModeControls(){var t=this;$("#editor-mode").change((function(e){var i=$(this).children("option:selected").val(),r=t.env_controller.mode;switch($("#cell-selections").css("display","none"),i){case"none":t.setMode(s.None);break;case"food":t.setMode(s.FoodDrop);break;case"wall":t.setMode(s.WallDrop);break;case"kill":t.setMode(s.ClickKill);break;case"select":r==s.Edit||r==s.Clone&&t.engine.organism_editor.organism.cells.length>1?confirm("Selecting a new organism will clear the current organism. Are you sure you wish to switch?")?t.setMode(s.Select):$("#editor-mode").val("edit"):t.setMode(s.Select);break;case"edit":t.setMode(s.Edit),$("#cell-selections").css("display","grid");break;case"clone":t.setMode(s.Clone),t.env_controller.org_to_clone=t.engine.organism_editor.getCopyOfOrg()}})),$("#reset-env").click(function(){this.engine.env.reset()}.bind(this)),$("#kill-all").click(function(){this.engine.env.clearOrganisms()}.bind(this)),$("#clear-walls").click(function(){this.engine.env.clearWalls()}.bind(this)),$("#clear-editor").click(function(){this.engine.organism_editor.clear()}.bind(this))}setMode(t){this.env_controller.mode=t,this.editor_controller.mode=t}setEditorOrganism(t){this.engine.organism_editor.setOrganismToCopyOf(t)}changeEngineSpeed(t){this.engine.stop(),this.engine.start(t),this.fps=this.engine.fps}update(){$("#fps-actual").text("Actual FPS: "+Math.floor(this.engine.actual_fps));var t=this.engine.env.organisms.length;$("#org-count").text("Organism count: "+t),t>this.organism_record&&(this.organism_record=t),$("#org-record").text("Highest count: "+this.organism_record),$("#avg-mut").text("Average Mutation Rate: "+Math.round(100*this.engine.env.averageMutability())/100)}}},function(t,e,i){const r=i(4),s=i(1),o=i(7),l=i(0),n=i(17);i(2);t.exports=class{constructor(){this.is_active=!0;this.grid_map=new s(11,11,20),this.renderer=new o("editor-canvas","editor-env",20),this.controller=new n(this,this.renderer.canvas),this.clear(),this.renderer.renderFullGrid(this.grid_map.grid)}update(){this.is_active&&this.renderer.renderHighlights()}changeCell(t,e,i,r){this.grid_map.setCellType(t,e,i),this.grid_map.setCellOwner(t,e,r),this.renderer.renderFullGrid(this.grid_map.grid)}addCellToOrg(t,e,i){var r=this.grid_map.getCenter(),s=t-r[0],o=e-r[1],l=this.organism.getLocalCell(s,o);null!=l?(l.type=i,this.changeCell(t,e,i,this.organism)):this.organism.addCell(i,s,o)&&this.changeCell(t,e,i,this.organism)}removeCellFromOrg(t,e){var i=this.grid_map.getCenter(),r=t-i[0],s=e-i[1];0!=r||0!=s?null!=this.organism.getLocalCell(r,s)&&this.organism.removeCell(r,s)&&this.changeCell(t,e,l.empty,null):alert("Cannot remove center cell")}setOrganismToCopyOf(t){this.grid_map.fillGrid(l.empty);var e=this.grid_map.getCenter();this.organism=new r(e[0],e[1],this,t),this.organism.updateGrid()}getCopyOfOrg(){return new r(0,0,null,this.organism)}clear(){this.grid_map.fillGrid(l.empty);var t=this.grid_map.getCenter();this.organism=new r(t[0],t[1],this,null),this.organism.addCell(l.mouth,0,0),this.organism.updateGrid()}}},function(t,e,i){const r=i(9),s=i(5),o=i(0);t.exports=class extends r{constructor(t,e){super(t,e),this.mode=s.None,this.edit_cell_type=null,this.highlight_org=!1,this.defineCellTypeSelection()}mouseMove(){}mouseDown(){null!=this.edit_cell_type&&this.mode==s.Edit&&(this.left_click&&this.env.addCellToOrg(this.mouse_c,this.mouse_r,this.edit_cell_type),this.right_click&&this.env.removeCellFromOrg(this.mouse_c,this.mouse_r))}defineCellTypeSelection(){var t=this;$(".cell-type").click((function(){switch(this.id){case"mouth":t.edit_cell_type=o.mouth;break;case"producer":t.edit_cell_type=o.producer;break;case"mover":t.edit_cell_type=o.mover;break;case"killer":t.edit_cell_type=o.killer;break;case"armor":t.edit_cell_type=o.armor}$(".cell-type").css("border-color","black"),$("#"+this.id).css("border-color","yellow")}))}}}]); |