Added color scheme/better brain

This commit is contained in:
MaxRobinsonTheGreat
2020-08-21 16:07:04 -06:00
parent 0d2220827d
commit eaffd06133
15 changed files with 276 additions and 80 deletions

View File

@@ -2,6 +2,7 @@ const CanvasController = require("./CanvasController");
const Modes = require("./ControlModes");
const CellStates = require("../Organism/Cell/CellStates");
const Directions = require("../Organism/Directions");
const Hyperparams = require("../Hyperparameters");
class EditorController extends CanvasController{
constructor(env, canvas) {
@@ -10,7 +11,7 @@ class EditorController extends CanvasController{
this.edit_cell_type = null;
this.highlight_org = false;
this.defineCellTypeSelection();
this.defineEditorOptions();
this.defineEditorDetails();
}
mouseMove() {
@@ -42,10 +43,13 @@ class EditorController extends CanvasController{
}
if (this.right_click)
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);
this.setBrainPanelVisibility();
this.setMoveRangeVisibility();
}
updateDetails() {
$('#birth-distance').val(this.env.organism.birth_distance);
$('.cell-count').text("Cell count: "+this.env.organism.cells.length);
}
defineCellTypeSelection() {
@@ -77,11 +81,112 @@ class EditorController extends CanvasController{
});
}
defineEditorOptions() {
$('#birth-distance').change ( function() {
this.env.organism.birth_distance = parseInt($('#birth-distance').val());
defineEditorDetails() {
this.details_html = $('#organism-details');
this.edit_details_html = $('#edit-organism-details');
this.decision_names = ["ignore", "move away", "move towards"];
$('#birth-distance-edit').change ( function() {
this.env.organism.birth_distance = parseInt($('#birth-distance-edit').val());
}.bind(this));
$('#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());
}.bind(this));
$('#reaction-edit').change ( function() {
var obs = $('#observation-type-edit').val();
var decision = parseInt($('#reaction-edit').val());
this.env.organism.brain.decisions[obs] = decision;
}.bind(this));
}
clearDetailsPanel() {
$('#organism-details').css('display', 'none');
$('#edit-organism-details').css('display', 'none');
}
setDetailsPanel() {
var org = this.env.organism;
$('.cell-count').text("Cell count: "+org.cells.length);
$('#birth-distance').text("Reproduction Distance: "+org.birth_distance);
$('#move-range').text("Move Range: "+org.move_range);
$('#mutation-rate').text("Mutation Rate: "+org.mutability);
if (Hyperparams.useGlobalMutability) {
$('#mutation-rate').css('display', 'none');
}
else {
$('#mutation-rate').css('display', 'block');
}
this.setMoveRangeVisibility();
if (this.setBrainPanelVisibility()) {
var chase_types = [];
var retreat_types = [];
for(var cell_name in org.brain.decisions) {
var decision = org.brain.decisions[cell_name];
if (decision == 1) {
retreat_types.push(cell_name)
}
else if (decision == 2) {
chase_types.push(cell_name);
}
}
$('#chase-types').text("Move Towards: " + chase_types);
$('#retreat-types').text("Move Away From: " + retreat_types);
}
$('#organism-details').css('display', 'block');
}
setEditorPanel() {
this.clearDetailsPanel();
var org = this.env.organism;
$('.cell-count').text("Cell count: "+org.cells.length);
$('#birth-distance-edit').val(org.birth_distance);
if (this.setMoveRangeVisibility()){
$('#move-range-edit').val(org.move_range);
}
if (this.setBrainPanelVisibility()){
this.setBrainEditorValues($('#observation-type-edit').val());
}
$('#cell-selections').css('display', 'grid');
$('#edit-organism-details').css('display', 'block');
}
setBrainPanelVisibility() {
var org = this.env.organism;
if (org.has_eyes && org.is_mover) {
$('.brain-details').css('display', 'block');
return true;
}
$('.brain-details').css('display', 'none');
return false;
}
setMoveRangeVisibility() {
var org = this.env.organism;
if (org.is_mover) {
$('#move-range-cont').css('display', 'block');
$('#move-range').css('display', 'block');
return true;
}
$('#move-range-cont').css('display', 'none');
$('#move-range').css('display', 'none');
return false;
}
setBrainEditorValues(name) {
$('#observation-type-edit').val(name);
var reaction = this.env.organism.brain.decisions[name];
$('#reaction-edit').val(reaction);
}
}