diff --git a/Assets/NanoBrain/Cluster.cs b/Assets/NanoBrain/Cluster.cs index a148a00..54b9c92 100644 --- a/Assets/NanoBrain/Cluster.cs +++ b/Assets/NanoBrain/Cluster.cs @@ -104,15 +104,9 @@ public class Cluster : ScriptableObject, INucleus { public void UpdateNuclei() { foreach (INucleus nucleus in nuclei) - nucleus.IncreaseAge(); + nucleus.UpdateNuclei(); } - public void IncreaseAge() { - foreach (INucleus nucleus in nuclei) - nucleus.IncreaseAge(); - } - // ha ha ha - #endregion Dynamics } \ No newline at end of file diff --git a/Assets/NanoBrain/INucleus.cs b/Assets/NanoBrain/INucleus.cs index 535caca..dedd500 100644 --- a/Assets/NanoBrain/INucleus.cs +++ b/Assets/NanoBrain/INucleus.cs @@ -20,7 +20,7 @@ public interface INucleus : IReceptor { public void UpdateState(); - public void IncreaseAge(); + public void UpdateNuclei(); #endregion dynamic state diff --git a/Assets/NanoBrain/Neuroid.cs b/Assets/NanoBrain/Neuroid.cs index f14a788..b8e14d3 100644 --- a/Assets/NanoBrain/Neuroid.cs +++ b/Assets/NanoBrain/Neuroid.cs @@ -38,21 +38,6 @@ public class Neuroid : Nucleus { return clone; } - public void SetWeight(Neuroid input, float weight) { - this.SetWeight((Nucleus)input, weight); - } - - public void SetInput(Neuroid input) { - if (this.SynapseExists(input) == false) - this.SetWeight(input, 1.0f); - UpdateState(); - } - - public void SetInput(Neuroid input, float weight) { - this.SetWeight(input, weight); - UpdateState(); - } - public override void UpdateState() { Vector3 sum = Vector3.zero; int n = 0; diff --git a/Assets/NanoBrain/Nucleus.cs b/Assets/NanoBrain/Nucleus.cs index 01f0693..ffe7125 100644 --- a/Assets/NanoBrain/Nucleus.cs +++ b/Assets/NanoBrain/Nucleus.cs @@ -5,8 +5,6 @@ using UnityEngine; [Serializable] public class Nucleus : INucleus { - public int id; // hash code - [SerializeField] protected string _name; public virtual string name { @@ -23,10 +21,8 @@ public class Nucleus : INucleus { public List receivers => _receivers; public NucleusArray array { get; set; } - #region Serialization - [SerializeField] - protected string nucleusType; + #region Serialization public enum CurvePresets { Linear, @@ -67,32 +63,6 @@ public class Nucleus : INucleus { } } - // public virtual void Rebuild(NanoBrain brain) { - // if (this.synapses != null) { - // foreach (Synapse synapse in synapses) - // synapse.Rebuild(brain); - // } - // // foreach (INucleus receiver in receivers.ToArray()) { - // // if (receiver.Rebuild(brain) == false) { - // // Debug.Log("Rebuilding failed, removing receiver."); - // // receivers.Remove(receiver); - // // } - // // } - // } - - // public static Nucleus RebuildType(NanoBrain brain, Nucleus nucleus) { - // if (string.IsNullOrEmpty(nucleus.nucleusType) == false) { - // Type nucleusType = Type.GetType(nucleus.nucleusType); - // if (nucleusType != null) { - // object[] args = new object[] { brain, nucleus.name }; - // Nucleus rebuiltNucleus = (Nucleus)Activator.CreateInstance(nucleusType, args); - // rebuiltNucleus.Deserialize(nucleus); - // return rebuiltNucleus; - // } - // } - // return nucleus; - // } - public virtual void Deserialize(Nucleus nucleus) { } #endregion Serialization @@ -111,26 +81,23 @@ public class Nucleus : INucleus { } } - [System.NonSerialized] + [NonSerialized] private int stale = 1000; private bool _isSleeping = false; public bool isSleeping => _isSleeping; - public void IncreaseAge() { + public void UpdateNuclei() { this.stale++; this._isSleeping = this.stale > 2; if (isSleeping) _outputValue = Vector3.zero; } - [System.NonSerialized] - public int layerIx; #endregion Runtime state public Nucleus(string name) { this._name = name; - this.id = this.GetHashCode(); } public virtual INucleus Clone() { @@ -188,34 +155,11 @@ public class Nucleus : INucleus { } } - public void GetInputFrom(Nucleus input, float weight = 1.0f) { - input.AddReceiver(this); - this.SetWeight(input, weight); - } - - public bool SynapseExists(Nucleus nucleus) { - foreach (Synapse synapse in synapses) { - if (synapse.nucleus == nucleus) - return true; - } - return false; - } - public Synapse AddSynapse(IReceptor sendingNucleus) { Synapse synapse = new(sendingNucleus, 1.0f); this.synapses.Add(synapse); return synapse; } - public void SetWeight(Nucleus nucleus, float weight) { - foreach (Synapse synapse in synapses) { - if (synapse.nucleus == nucleus) { - synapse.weight = weight; - return; - } - } - Synapse newSynapse = new(nucleus, weight); - synapses.Add(newSynapse); - } public virtual void UpdateState() { } diff --git a/Assets/NanoBrain/Receptor.cs b/Assets/NanoBrain/Receptor.cs index 39f1699..403367d 100644 --- a/Assets/NanoBrain/Receptor.cs +++ b/Assets/NanoBrain/Receptor.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using UnityEngine; -using LinearAlgebra; public class Receptor : IReceptor { [SerializeField] @@ -26,52 +25,16 @@ public class Receptor : IReceptor { public bool isSleeping => false; - /// - /// The list of perceptoid which can process stimuli from this receptor - /// - //public List perceptei = new(); - - // private int _thingType = 0; - // public int thingType { - // get { return _thingType; } - // set { - // _thingType = value; - // foreach (Perceptoid perceptoid in perceptei) { - // perceptoid.thingType = _thingType; - // } - // } - // } public Vector3 localPosition; public float distanceResolution = 0.1f; public float directionResolution = 5; - public Vector3 outputValue { - get { return localPosition; } - set { - localPosition = value; - } - } - - - // public Receptor(NanoBrain brain, int thingType) { - // this.thingType = thingType; - // brain.receptors.Add(this); - // } + public Vector3 outputValue => this.localPosition; public Receptor(Cluster cluster, INucleus nucleus) { - //this.cluster = cluster; this.AddReceiver(nucleus); } - // public static Receptor GetReceptor(NanoBrain brain, int thingType) { - // foreach (Receptor receptor in brain.receptors) { - // if (thingType == 0 || receptor.thingType == thingType) - // return receptor; - // } - // Receptor newReceptor = new(brain, thingType); - // return newReceptor; - // } - public static Receptor CreateReceptor(Cluster cluster, string nucleusName) { if (cluster == null) return null;