added more movement range

This commit is contained in:
MaxRobinsonTheGreat
2020-07-04 14:51:40 -06:00
parent 9b24e4cc1c
commit 2ba56abb1d
4 changed files with 37 additions and 17 deletions

View File

@@ -1,2 +1,10 @@
# EvolutionSimulatorV2 # EvolutionSimulatorV2
Version 2 of the evolution simulator Version 2 of the evolution simulator
Requirements:
- npm
- webpack
To build minified: `npm run build`
To build in dev mode: `npm run build-dev`
To build in dev/watch mode: `npm run build-watch`

4
dist/bundle.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -17,13 +17,6 @@ class Environment{
this.organisms = []; this.organisms = [];
} }
// {
// running: 0,
// paused: 1,
// headless: 2
// };
update(delta_time) { update(delta_time) {
var to_remove = []; var to_remove = [];
for (var i in this.organisms) { for (var i in this.organisms) {

View File

@@ -15,6 +15,10 @@ class Organism {
this.cells = []; this.cells = [];
this.is_producer = false; this.is_producer = false;
this.is_mover = false; this.is_mover = false;
this.direction = this.getRandomDirection();
this.move_count = 0;
this.move_range = 1;
this.mutability = 5;
if (parent != null) { if (parent != null) {
this.inherit(parent); this.inherit(parent);
} }
@@ -59,6 +63,8 @@ class Organism {
} }
inherit(parent) { inherit(parent) {
this.move_range = parent.move_range;
this.mutability = parent.mutability;
for (var c of parent.cells){ for (var c of parent.cells){
//deep copy parent cells //deep copy parent cells
this.addCell(c.type, c.loc_col, c.loc_row); this.addCell(c.type, c.loc_col, c.loc_row);
@@ -78,18 +84,22 @@ class Organism {
//produce mutated child //produce mutated child
//check nearby locations (is there room and a direct path) //check nearby locations (is there room and a direct path)
var org = new Organism(0, 0, this.env, this); var org = new Organism(0, 0, this.env, this);
if (Math.random() * 100 <= 5) { if (Math.random() * 100 <= this.mutability) {
org.mutate(); org.mutate();
} }
else if (Math.random() * 100 <= 2) {
org.mutability--;
if (org.mutability < 1)
org.mutability = 1;
}
var direction = this.getRandomDirection(); var direction = this.getRandomDirection();
var direction_c = direction[0]; var direction_c = direction[0];
var direction_r = direction[1]; var direction_r = direction[1];
var boost = Math.floor(Math.random() * 2) + 1; var offset = (Math.floor(Math.random() * 2));
boost = 1;
var new_c = this.c + (direction_c*this.cells.length*2) + (direction_c*boost); var new_c = this.c + (direction_c*this.cells.length*2) + (direction_c*offset);
var new_r = this.r + (direction_r*this.cells.length*2) + (direction_r*boost); var new_r = this.r + (direction_r*this.cells.length*2) + (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.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;
@@ -103,6 +113,7 @@ class Organism {
} }
mutate() { mutate() {
this.mutability += 2;
var choice = Math.floor(Math.random() * 3); var choice = Math.floor(Math.random() * 3);
if (choice == 0) { if (choice == 0) {
var type = CellTypes.getRandomLivingType(); var type = CellTypes.getRandomLivingType();
@@ -125,11 +136,14 @@ class Organism {
return true; return true;
} }
} }
if (this.is_mover) {
this.move_range += Math.floor(Math.random() * 4) - 2;
}
return false; return false;
} }
attemptMove(col, row) { attemptMove(direction) {
var direction = this.getRandomDirection();
var direction_c = direction[0]; var direction_c = direction[0];
var direction_r = direction[1]; var direction_r = direction[1];
var new_c = this.c + direction_c; var new_c = this.c + direction_c;
@@ -229,7 +243,12 @@ class Organism {
return this.living return this.living
} }
if (this.is_mover) { if (this.is_mover) {
this.attemptMove(); this.move_count++;
if (this.move_count > this.move_range){
this.move_count = 0;
this.direction = this.getRandomDirection()
}
this.attemptMove(this.direction);
} }
if (this.food_collected >= this.foodNeeded()) { if (this.food_collected >= this.foodNeeded()) {
this.reproduce(); this.reproduce();