From ed7037f35762404dd81004ecf03335f581d00632 Mon Sep 17 00:00:00 2001 From: Tim Falken Date: Fri, 14 Jul 2017 16:40:24 +0200 Subject: [PATCH] Add extra neuron for heartbeat, add heartbeat Note: This also causes an extra unneccesary neuron to be created in the output layer, but this should be harmless. --- Brain.pde | 13 +++++++++++-- Creature.pde | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Brain.pde b/Brain.pde index 0598d20..351bf15 100644 --- a/Brain.pde +++ b/Brain.pde @@ -1,4 +1,7 @@ class Brain { + float heartbeatStrength = 10; + float heartbeatInterval = 0.1; + float timesUsed = 0; float[][] neurons; Axon[][][] axons; int BRAIN_WIDTH = 0; @@ -86,10 +89,16 @@ class Brain { public void useBrain(Creature owner){ ArrayList n = owner.n; ArrayList m = owner.m; - for(int i = 0; i < n.size(); i++){ - Node ni = n.get(i); + + for(int i = 1; i < n.size(); i++){ + Node ni = n.get(i - 1); neurons[0][i] = dist(ni.x, ni.y, ni.z, foodX, foodY, foodZ); } + + neurons[0][0] = ((sin(timesUsed) / 2) + 0.5) * heartbeatStrength; + + timesUsed += heartbeatInterval; + for(int i = 0; i < m.size(); i++){ Muscle am = m.get(i); Node ni1 = n.get(am.c1); diff --git a/Creature.pde b/Creature.pde index 8857a87..f573a7e 100644 --- a/Creature.pde +++ b/Creature.pde @@ -44,7 +44,7 @@ class Creature { } } int getBrainHeight(){ - return n.size()+m.size()+1; + return n.size()+m.size()+2; } void changeBrainStructure(int rowInsertionIndex, int rowRemovalIndex){ brain.changeBrainStructure(BRAIN_WIDTH, getBrainHeight(), rowInsertionIndex,rowRemovalIndex);