merged species tracking

This commit is contained in:
Max Robinson
2021-08-30 19:01:50 -05:00
25 changed files with 838 additions and 190 deletions

View File

@@ -1,5 +1,6 @@
const Hyperparams = require("../Hyperparameters");
const Modes = require("./ControlModes");
const StatsPanel = require("../Stats/StatsPanel");
class ControlPanel {
constructor(engine) {
@@ -17,6 +18,10 @@ class ControlPanel {
this.editor_controller = this.engine.organism_editor.controller;
this.env_controller.setControlPanel(this);
this.editor_controller.setControlPanel(this);
this.stats_panel = new StatsPanel(this.engine.env);
this.headless_opacity = 1;
this.opacity_change_rate = -0.8;
this.paused=false;
}
defineMinMaxControls(){
@@ -26,11 +31,15 @@ class ControlPanel {
$('.control-panel').css('display', 'none');
$('.hot-controls').css('display', 'block');
this.control_panel_active = false;
this.stats_panel.stopAutoRender();
});
$('#maximize').click ( () => {
$('.control-panel').css('display', 'grid');
$('.hot-controls').css('display', 'none');
this.control_panel_active = true;
if (this.tab_id == 'stats') {
this.stats_panel.startAutoRender();
}
});
const V_KEY = 118;
$('body').keypress( (e) => {
@@ -38,6 +47,9 @@ class ControlPanel {
if (this.no_hud) {
let control_panel_display = this.control_panel_active ? 'grid' : 'none';
let hot_control_display = !this.control_panel_active ? 'block' : 'none';
if (this.control_panel_active && this.tab_id == 'stats') {
this.stats_panel.startAutoRender();
};
$('.control-panel').css('display', control_panel_display);
$('.hot-controls').css('display', hot_control_display);
}
@@ -48,6 +60,19 @@ class ControlPanel {
this.no_hud = !this.no_hud;
}
});
// var self = this;
// $('#minimize').click ( function() {
// $('.control-panel').css('display', 'none');
// $('.hot-controls').css('display', 'block');
// }.bind(this));
// $('#maximize').click ( function() {
// $('.control-panel').css('display', 'grid');
// $('.hot-controls').css('display', 'none');
// if (self.tab_id == 'stats') {
// self.stats_panel.startAutoRender();
// }
// });
}
defineEngineSpeedControls(){
@@ -56,13 +81,13 @@ class ControlPanel {
this.fps = this.slider.value
if (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;
if (this.engine.running) {
this.engine.stop();
}
@@ -70,6 +95,18 @@ class ControlPanel {
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");
if (Hyperparams.headless){
$('#headless-notification').css('display', 'none');
this.engine.env.renderFull();
}
else {
$('#headless-notification').css('display', 'block');
}
Hyperparams.headless = !Hyperparams.headless;
}.bind(this));
}
defineGridSizeControls() {
@@ -91,24 +128,31 @@ class ControlPanel {
var rows = $('#row-input').val();
this.engine.env.resizeGridColRow(cell_size, cols, rows);
}
this.engine.env.reset();
this.stats_panel.reset();
}.bind(this));
}
defineTabNavigation() {
this.tab_id = 'about';
var self = this;
$('.tabnav-item').click(function() {
$('.tab').css('display', 'none');
var tab = '#'+this.id+'.tab';
self.engine.organism_editor.is_active = (this.id == 'editor');
$(tab).css('display', 'grid');
self.engine.organism_editor.is_active = (this.id == 'editor');
self.stats_panel.stopAutoRender();
if (this.id == 'stats') {
self.stats_panel.startAutoRender();
}
self.tab_id = this.id;
});
}
defineHyperparameterControls() {
$('#food-prod-prob').change(function() {
var food_prob =
Hyperparams.foodProdProb = $('#food-prod-prob').val();;
Hyperparams.foodProdProb = $('#food-prod-prob').val();
}.bind(this));
$('#lifespan-multiplier').change(function() {
Hyperparams.lifespanMultiplier = $('#lifespan-multiplier').val();
@@ -142,7 +186,7 @@ class ControlPanel {
Hyperparams.useGlobalMutability = !this.checked;
});
$('#global-mutation').change( function() {
Hyperparams.globalMutability = $('#global-mutation').val();
Hyperparams.globalMutability = parseInt($('#global-mutation').val());
});
$('.mut-prob').change( function() {
switch(this.id){
@@ -182,6 +226,9 @@ class ControlPanel {
$('#remove-prob').val(Hyperparams.removeProb);
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
$('#food-drop-rate').val(Hyperparams.foodDropProb);
$('#look-range').val(Hyperparams.lookRange);
if (!Hyperparams.useGlobalMutability) {
$('.global-mutation-in').css('display', 'none');
$('#avg-mut').css('display', 'block');
@@ -199,7 +246,7 @@ class ControlPanel {
$('#cell-selections').css('display', 'none');
$('#organism-options').css('display', 'none');
self.editor_controller.setDetailsPanel();
switch(this.id){
switch(this.id) {
case "food-drop":
self.setMode(Modes.FoodDrop);
break;
@@ -219,6 +266,9 @@ class ControlPanel {
case "drop-org":
self.setMode(Modes.Clone);
self.env_controller.org_to_clone = self.engine.organism_editor.getCopyOfOrg();
self.env_controller.add_new_species = self.editor_controller.new_species;
self.editor_controller.new_species = false;
// console.log(self.env_controller.add_new_species)
break;
case "drag-view":
self.setMode(Modes.Drag);
@@ -234,6 +284,7 @@ class ControlPanel {
var env = this.engine.env;
$('#reset-env').click( function() {
this.engine.env.reset();
this.stats_panel.reset();
}.bind(this));
$('#auto-reset').change(function() {
env.auto_reset = this.checked;
@@ -273,16 +324,29 @@ class ControlPanel {
this.fps = this.engine.fps;
}
update() {
updateHeadlessIcon(delta_time) {
if (this.paused)
return;
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
if (op <= 0.4){
op=0.4;
this.opacity_change_rate = -this.opacity_change_rate;
}
else if (op >= 1){
op=1;
this.opacity_change_rate = -this.opacity_change_rate;
}
this.headless_opacity = op;
$('#headless-notification').css('opacity',(op*100)+'%');
}
update(delta_time) {
$('#fps-actual').text("Actual FPS: " + Math.floor(this.engine.actual_fps));
var org_count = this.engine.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.organism_record);
$('#avg-mut').text("Average Mutation Rate: " + Math.round(this.engine.env.averageMutability() * 100) / 100);
$('#largest-org').text("Largest Organism: " + this.engine.env.largest_cell_count + " cells");
$('#reset-count').text("Auto reset count: " + this.engine.env.reset_count);
this.stats_panel.updateDetails();
if (Hyperparams.headless)
this.updateHeadlessIcon(delta_time);
}
}

View File

@@ -10,6 +10,7 @@ class EditorController extends CanvasController{
this.mode = Modes.None;
this.edit_cell_type = null;
this.highlight_org = false;
this.new_species = false;
this.defineCellTypeSelection();
this.defineEditorDetails();
}
@@ -26,7 +27,7 @@ class EditorController extends CanvasController{
mouseUp(){}
getCurLocalCell(){
return this.env.organism.getLocalCell(this.mouse_c-this.env.organism.c, this.mouse_r-this.env.organism.r);
return this.env.organism.anatomy.getLocalCell(this.mouse_c-this.env.organism.c, this.mouse_r-this.env.organism.r);
}
editOrganism() {
@@ -41,15 +42,17 @@ class EditorController extends CanvasController{
else
this.env.addCellToOrg(this.mouse_c, this.mouse_r, this.edit_cell_type);
}
if (this.right_click)
else if (this.right_click)
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);
this.new_species = true;
this.setBrainPanelVisibility();
this.setMoveRangeVisibility();
this.updateDetails();
}
updateDetails() {
$('.cell-count').text("Cell count: "+this.env.organism.cells.length);
$('.cell-count').text("Cell count: "+this.env.organism.anatomy.cells.length);
}
defineCellTypeSelection() {
@@ -111,7 +114,7 @@ class EditorController extends CanvasController{
this.clearDetailsPanel();
var org = this.env.organism;
$('.cell-count').text("Cell count: "+org.cells.length);
$('.cell-count').text("Cell count: "+org.anatomy.cells.length);
$('#move-range').text("Move Range: "+org.move_range);
$('#mutation-rate').text("Mutation Rate: "+org.mutability);
if (Hyperparams.useGlobalMutability) {
@@ -134,7 +137,7 @@ class EditorController extends CanvasController{
this.clearDetailsPanel();
var org = this.env.organism;
$('.cell-count').text("Cell count: "+org.cells.length);
$('.cell-count').text("Cell count: "+org.anatomy.cells.length);
if (this.setMoveRangeVisibility()){
$('#move-range-edit').val(org.move_range);
}
@@ -149,7 +152,7 @@ class EditorController extends CanvasController{
setBrainPanelVisibility() {
var org = this.env.organism;
if (org.has_eyes && org.is_mover) {
if (org.anatomy.has_eyes && org.anatomy.is_mover) {
$('.brain-details').css('display', 'block');
return true;
}
@@ -175,7 +178,7 @@ class EditorController extends CanvasController{
setMoveRangeVisibility() {
var org = this.env.organism;
if (org.is_mover) {
if (org.anatomy.is_mover) {
$('#move-range-cont').css('display', 'block');
$('#move-range').css('display', 'block');
return true;

View File

@@ -3,12 +3,15 @@ const Organism = require('../Organism/Organism');
const Modes = require("./ControlModes");
const CellStates = require("../Organism/Cell/CellStates");
const Neighbors = require("../Grid/Neighbors");
const FossilRecord = require("../Stats/FossilRecord");
const Hyperparams = require("../Hyperparameters");
class EnvironmentController extends CanvasController{
constructor(env, canvas) {
super(env, canvas);
this.mode = Modes.Drag;
this.org_to_clone = null;
this.add_new_species = false;
this.defineZoomControls();
this.scale = 1;
}
@@ -76,6 +79,8 @@ class EnvironmentController extends CanvasController{
}
performModeAction() {
if (Hyperparams.headless)
return;
var mode = this.mode;
var right_click = this.right_click;
var left_click = this.left_click;
@@ -118,8 +123,19 @@ class EnvironmentController extends CanvasController{
case Modes.Clone:
if (this.org_to_clone != null){
var new_org = new Organism(this.mouse_c, this.mouse_r, this.env, this.org_to_clone);
if (this.add_new_species){
FossilRecord.addSpeciesObj(new_org.species);
new_org.species.start_tick = this.env.total_ticks;
this.add_new_species = false;
new_org.species.population = 0;
}
else if (this.org_to_clone.species.extinct){
FossilRecord.resurrect(this.org_to_clone.species);
}
if (new_org.isClear(this.mouse_c, this.mouse_r)){
this.env.addOrganism(new_org)
this.env.addOrganism(new_org);
new_org.species.addPop();
}
}
break;