Added final touches
This commit is contained in:
11
dist/index.html
vendored
11
dist/index.html
vendored
@@ -123,24 +123,20 @@
|
||||
<div id='organism-details' style="display:none;">
|
||||
<h3>Organism Details</h3>
|
||||
<p class='cell-count'>Cell count: </p>
|
||||
<p id='birth-distance'>Reproduction Distance: </p>
|
||||
<p id='move-range'>Move Range: </p>
|
||||
<p id='mutation-rate'>Mutation Rate: </p>
|
||||
<br>
|
||||
|
||||
<div class='brain-details'>
|
||||
<h4>Brain</h4>
|
||||
<p id='chase-types'>Move Towards: food</p>
|
||||
<p id='retreat-types'>Move Away From: killer</p>
|
||||
<p class='chase-types'>Move Towards: food</p>
|
||||
<p class='retreat-types'>Move Away From: killer</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id='edit-organism-details' style="display:none;">
|
||||
<h3>Edit Organism</h3>
|
||||
<p class='cell-count'>Cell count: </p>
|
||||
<label for="birth-distance-edit" title='The number of cells away offspring will spawn.'>Reproduction Distance:</label>
|
||||
<input type="number" id="birth-distance-edit" min="1" max="100" value=3 step="1">
|
||||
<br>
|
||||
<div id='move-range-cont'>
|
||||
<label for="move-range-edit" title='The number of cells to move before randomly changing direction. Overriden by brain decisions.'>Move Range:</label>
|
||||
<input type="number" id="move-range-edit" min="1" max="100" value=3 step="1">
|
||||
@@ -165,6 +161,9 @@
|
||||
<option value="1">move away</option>
|
||||
<option value="2">move towards</option>
|
||||
</select>
|
||||
<br>
|
||||
<p class='chase-types'>Move Towards: food</p>
|
||||
<p class='retreat-types'>Move Away From: killer</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
2
dist/js/bundle.js
vendored
2
dist/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -175,7 +175,7 @@ class ControlPanel {
|
||||
$('.edit-mode-btn').click( function() {
|
||||
$('#cell-selections').css('display', 'none');
|
||||
$('#organism-options').css('display', 'none');
|
||||
self.editor_controller.clearDetailsPanel();
|
||||
self.editor_controller.setDetailsPanel();
|
||||
switch(this.id){
|
||||
case "food-drop":
|
||||
self.setMode(Modes.FoodDrop);
|
||||
|
||||
@@ -45,10 +45,10 @@ class EditorController extends CanvasController{
|
||||
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);
|
||||
this.setBrainPanelVisibility();
|
||||
this.setMoveRangeVisibility();
|
||||
this.updateDetails();
|
||||
}
|
||||
|
||||
updateDetails() {
|
||||
$('#birth-distance').val(this.env.organism.birth_distance);
|
||||
$('.cell-count').text("Cell count: "+this.env.organism.cells.length);
|
||||
}
|
||||
|
||||
@@ -87,19 +87,18 @@ class EditorController extends CanvasController{
|
||||
|
||||
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());
|
||||
this.setBrainDetails();
|
||||
}.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;
|
||||
this.setBrainDetails();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
@@ -109,10 +108,10 @@ class EditorController extends CanvasController{
|
||||
}
|
||||
|
||||
setDetailsPanel() {
|
||||
this.clearDetailsPanel();
|
||||
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) {
|
||||
@@ -125,19 +124,7 @@ class EditorController extends CanvasController{
|
||||
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);
|
||||
this.setBrainDetails();
|
||||
|
||||
}
|
||||
$('#organism-details').css('display', 'block');
|
||||
@@ -148,7 +135,6 @@ class EditorController extends CanvasController{
|
||||
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);
|
||||
}
|
||||
@@ -171,6 +157,22 @@ class EditorController extends CanvasController{
|
||||
return false;
|
||||
}
|
||||
|
||||
setBrainDetails() {
|
||||
var chase_types = [];
|
||||
var retreat_types = [];
|
||||
for(var cell_name in this.env.organism.brain.decisions) {
|
||||
var decision = this.env.organism.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);
|
||||
}
|
||||
|
||||
setMoveRangeVisibility() {
|
||||
var org = this.env.organism;
|
||||
if (org.is_mover) {
|
||||
|
||||
@@ -8,6 +8,11 @@ class BodyCell{
|
||||
this.org = org;
|
||||
this.loc_col = loc_col;
|
||||
this.loc_row = loc_row;
|
||||
|
||||
var distance = Math.max(Math.abs(loc_row)*2 + 2, Math.abs(loc_col)*2 + 2);
|
||||
if (this.org.birth_distance < distance) {
|
||||
this.org.birth_distance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
initInherit(parent) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class KillerCell extends BodyCell{
|
||||
return;
|
||||
var is_hit = n_cell.state == CellStates.killer; // has to be calculated before death
|
||||
n_cell.owner.harm();
|
||||
if (is_hit) {
|
||||
if (Hyperparams.instaKill && is_hit) {
|
||||
this.org.harm();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class Organism {
|
||||
inherit(parent) {
|
||||
this.move_range = parent.move_range;
|
||||
this.mutability = parent.mutability;
|
||||
this.birth_distance = parent.birth_distance;
|
||||
// this.birth_distance = parent.birth_distance;
|
||||
for (var c of parent.cells){
|
||||
//deep copy parent cells
|
||||
this.addInheritCell(c);
|
||||
@@ -172,7 +172,7 @@ class Organism {
|
||||
var new_c = this.c + (direction_c*basemovement) + (direction_c*offset);
|
||||
var new_r = this.r + (direction_r*basemovement) + (direction_r*offset);
|
||||
|
||||
if (org.isClear(new_c, new_r) && org.isStraightPath(new_c, new_r, this.c, this.r, this)){
|
||||
if (org.isClear(new_c, new_r, org.rotation, true) && org.isStraightPath(new_c, new_r, this.c, this.r, this)){
|
||||
org.c = new_c;
|
||||
org.r = new_r;
|
||||
this.env.addOrganism(org);
|
||||
@@ -194,12 +194,10 @@ class Organism {
|
||||
var growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
|
||||
var c = branch.loc_col+growth_direction[0];
|
||||
var r = branch.loc_row+growth_direction[1];
|
||||
// mutated = this.addCell(state, c, r);
|
||||
if (this.canAddCellAt(c, r)){
|
||||
mutated = true;
|
||||
this.addRandomizedCell(state, c, r);
|
||||
}
|
||||
this.birth_distance++;
|
||||
}
|
||||
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){
|
||||
// change cell
|
||||
@@ -225,11 +223,6 @@ class Organism {
|
||||
this.move_range = 1;
|
||||
};
|
||||
}
|
||||
if (Math.random() * 100 <= 10) {
|
||||
this.birth_distance += Math.floor(Math.random() * 5) - 2;
|
||||
if (this.birth_distance < 1)
|
||||
this.birth_distance = 1;
|
||||
}
|
||||
if (this.is_mover && this.has_eyes && Math.random() * 100 <= 10) {
|
||||
this.brain.mutate();
|
||||
}
|
||||
@@ -319,13 +312,13 @@ class Organism {
|
||||
return cell != null && (cell.state == CellStates.empty || cell.owner == this || cell.owner == parent || cell.state == CellStates.food);
|
||||
}
|
||||
|
||||
isClear(col, row, rotation=this.rotation) {
|
||||
isClear(col, row, rotation=this.rotation, ignore_armor=false) {
|
||||
for(var loccell of this.cells) {
|
||||
var cell = this.getRealCell(loccell, col, row, rotation);
|
||||
if(cell==null) {
|
||||
return false;
|
||||
}
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food)){
|
||||
if (cell.owner==this || cell.state==CellStates.empty || (!Hyperparams.foodBlocksReproduction && cell.state==CellStates.food) || (ignore_armor && loccell.state==CellStates.armor && cell.state==CellStates.food)){
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user