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;">
|
<div id='organism-details' style="display:none;">
|
||||||
<h3>Organism Details</h3>
|
<h3>Organism Details</h3>
|
||||||
<p class='cell-count'>Cell count: </p>
|
<p class='cell-count'>Cell count: </p>
|
||||||
<p id='birth-distance'>Reproduction Distance: </p>
|
|
||||||
<p id='move-range'>Move Range: </p>
|
<p id='move-range'>Move Range: </p>
|
||||||
<p id='mutation-rate'>Mutation Rate: </p>
|
<p id='mutation-rate'>Mutation Rate: </p>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<div class='brain-details'>
|
<div class='brain-details'>
|
||||||
<h4>Brain</h4>
|
<h4>Brain</h4>
|
||||||
<p id='chase-types'>Move Towards: food</p>
|
<p class='chase-types'>Move Towards: food</p>
|
||||||
<p id='retreat-types'>Move Away From: killer</p>
|
<p class='retreat-types'>Move Away From: killer</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id='edit-organism-details' style="display:none;">
|
<div id='edit-organism-details' style="display:none;">
|
||||||
<h3>Edit Organism</h3>
|
<h3>Edit Organism</h3>
|
||||||
<p class='cell-count'>Cell count: </p>
|
<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'>
|
<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>
|
<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">
|
<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="1">move away</option>
|
||||||
<option value="2">move towards</option>
|
<option value="2">move towards</option>
|
||||||
</select>
|
</select>
|
||||||
|
<br>
|
||||||
|
<p class='chase-types'>Move Towards: food</p>
|
||||||
|
<p class='retreat-types'>Move Away From: killer</p>
|
||||||
</div>
|
</div>
|
||||||
</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() {
|
$('.edit-mode-btn').click( function() {
|
||||||
$('#cell-selections').css('display', 'none');
|
$('#cell-selections').css('display', 'none');
|
||||||
$('#organism-options').css('display', 'none');
|
$('#organism-options').css('display', 'none');
|
||||||
self.editor_controller.clearDetailsPanel();
|
self.editor_controller.setDetailsPanel();
|
||||||
switch(this.id){
|
switch(this.id){
|
||||||
case "food-drop":
|
case "food-drop":
|
||||||
self.setMode(Modes.FoodDrop);
|
self.setMode(Modes.FoodDrop);
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ class EditorController extends CanvasController{
|
|||||||
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);
|
this.env.removeCellFromOrg(this.mouse_c, this.mouse_r);
|
||||||
this.setBrainPanelVisibility();
|
this.setBrainPanelVisibility();
|
||||||
this.setMoveRangeVisibility();
|
this.setMoveRangeVisibility();
|
||||||
|
this.updateDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDetails() {
|
updateDetails() {
|
||||||
$('#birth-distance').val(this.env.organism.birth_distance);
|
|
||||||
$('.cell-count').text("Cell count: "+this.env.organism.cells.length);
|
$('.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"];
|
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() {
|
$('#move-range-edit').change ( function() {
|
||||||
this.env.organism.move_range = parseInt($('#move-range-edit').val());
|
this.env.organism.move_range = parseInt($('#move-range-edit').val());
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
$('#observation-type-edit').change ( function() {
|
$('#observation-type-edit').change ( function() {
|
||||||
this.setBrainEditorValues($('#observation-type-edit').val());
|
this.setBrainEditorValues($('#observation-type-edit').val());
|
||||||
|
this.setBrainDetails();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
$('#reaction-edit').change ( function() {
|
$('#reaction-edit').change ( function() {
|
||||||
var obs = $('#observation-type-edit').val();
|
var obs = $('#observation-type-edit').val();
|
||||||
var decision = parseInt($('#reaction-edit').val());
|
var decision = parseInt($('#reaction-edit').val());
|
||||||
this.env.organism.brain.decisions[obs] = decision;
|
this.env.organism.brain.decisions[obs] = decision;
|
||||||
|
this.setBrainDetails();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +108,10 @@ class EditorController extends CanvasController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDetailsPanel() {
|
setDetailsPanel() {
|
||||||
|
this.clearDetailsPanel();
|
||||||
var org = this.env.organism;
|
var org = this.env.organism;
|
||||||
|
|
||||||
$('.cell-count').text("Cell count: "+org.cells.length);
|
$('.cell-count').text("Cell count: "+org.cells.length);
|
||||||
$('#birth-distance').text("Reproduction Distance: "+org.birth_distance);
|
|
||||||
$('#move-range').text("Move Range: "+org.move_range);
|
$('#move-range').text("Move Range: "+org.move_range);
|
||||||
$('#mutation-rate').text("Mutation Rate: "+org.mutability);
|
$('#mutation-rate').text("Mutation Rate: "+org.mutability);
|
||||||
if (Hyperparams.useGlobalMutability) {
|
if (Hyperparams.useGlobalMutability) {
|
||||||
@@ -125,19 +124,7 @@ class EditorController extends CanvasController{
|
|||||||
this.setMoveRangeVisibility();
|
this.setMoveRangeVisibility();
|
||||||
|
|
||||||
if (this.setBrainPanelVisibility()) {
|
if (this.setBrainPanelVisibility()) {
|
||||||
var chase_types = [];
|
this.setBrainDetails();
|
||||||
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');
|
$('#organism-details').css('display', 'block');
|
||||||
@@ -148,7 +135,6 @@ class EditorController extends CanvasController{
|
|||||||
var org = this.env.organism;
|
var org = this.env.organism;
|
||||||
|
|
||||||
$('.cell-count').text("Cell count: "+org.cells.length);
|
$('.cell-count').text("Cell count: "+org.cells.length);
|
||||||
$('#birth-distance-edit').val(org.birth_distance);
|
|
||||||
if (this.setMoveRangeVisibility()){
|
if (this.setMoveRangeVisibility()){
|
||||||
$('#move-range-edit').val(org.move_range);
|
$('#move-range-edit').val(org.move_range);
|
||||||
}
|
}
|
||||||
@@ -171,6 +157,22 @@ class EditorController extends CanvasController{
|
|||||||
return false;
|
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() {
|
setMoveRangeVisibility() {
|
||||||
var org = this.env.organism;
|
var org = this.env.organism;
|
||||||
if (org.is_mover) {
|
if (org.is_mover) {
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ class BodyCell{
|
|||||||
this.org = org;
|
this.org = org;
|
||||||
this.loc_col = loc_col;
|
this.loc_col = loc_col;
|
||||||
this.loc_row = loc_row;
|
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) {
|
initInherit(parent) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class KillerCell extends BodyCell{
|
|||||||
return;
|
return;
|
||||||
var is_hit = n_cell.state == CellStates.killer; // has to be calculated before death
|
var is_hit = n_cell.state == CellStates.killer; // has to be calculated before death
|
||||||
n_cell.owner.harm();
|
n_cell.owner.harm();
|
||||||
if (is_hit) {
|
if (Hyperparams.instaKill && is_hit) {
|
||||||
this.org.harm();
|
this.org.harm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class Organism {
|
|||||||
inherit(parent) {
|
inherit(parent) {
|
||||||
this.move_range = parent.move_range;
|
this.move_range = parent.move_range;
|
||||||
this.mutability = parent.mutability;
|
this.mutability = parent.mutability;
|
||||||
this.birth_distance = parent.birth_distance;
|
// this.birth_distance = parent.birth_distance;
|
||||||
for (var c of parent.cells){
|
for (var c of parent.cells){
|
||||||
//deep copy parent cells
|
//deep copy parent cells
|
||||||
this.addInheritCell(c);
|
this.addInheritCell(c);
|
||||||
@@ -172,7 +172,7 @@ class Organism {
|
|||||||
var new_c = this.c + (direction_c*basemovement) + (direction_c*offset);
|
var new_c = this.c + (direction_c*basemovement) + (direction_c*offset);
|
||||||
var new_r = this.r + (direction_r*basemovement) + (direction_r*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.c = new_c;
|
||||||
org.r = new_r;
|
org.r = new_r;
|
||||||
this.env.addOrganism(org);
|
this.env.addOrganism(org);
|
||||||
@@ -194,12 +194,10 @@ class Organism {
|
|||||||
var growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
|
var growth_direction = Neighbors.all[Math.floor(Math.random() * Neighbors.all.length)]
|
||||||
var c = branch.loc_col+growth_direction[0];
|
var c = branch.loc_col+growth_direction[0];
|
||||||
var r = branch.loc_row+growth_direction[1];
|
var r = branch.loc_row+growth_direction[1];
|
||||||
// mutated = this.addCell(state, c, r);
|
|
||||||
if (this.canAddCellAt(c, r)){
|
if (this.canAddCellAt(c, r)){
|
||||||
mutated = true;
|
mutated = true;
|
||||||
this.addRandomizedCell(state, c, r);
|
this.addRandomizedCell(state, c, r);
|
||||||
}
|
}
|
||||||
this.birth_distance++;
|
|
||||||
}
|
}
|
||||||
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){
|
else if (choice <= Hyperparams.addProb + Hyperparams.changeProb){
|
||||||
// change cell
|
// change cell
|
||||||
@@ -225,11 +223,6 @@ class Organism {
|
|||||||
this.move_range = 1;
|
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) {
|
if (this.is_mover && this.has_eyes && Math.random() * 100 <= 10) {
|
||||||
this.brain.mutate();
|
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);
|
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) {
|
for(var loccell of this.cells) {
|
||||||
var cell = this.getRealCell(loccell, col, row, rotation);
|
var cell = this.getRealCell(loccell, col, row, rotation);
|
||||||
if(cell==null) {
|
if(cell==null) {
|
||||||
return false;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user