Cleanup
This commit is contained in:
parent
e477ce4814
commit
b3823ac2e6
@ -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
|
||||
}
|
||||
@ -20,7 +20,7 @@ public interface INucleus : IReceptor {
|
||||
|
||||
public void UpdateState();
|
||||
|
||||
public void IncreaseAge();
|
||||
public void UpdateNuclei();
|
||||
|
||||
#endregion dynamic state
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<INucleus> 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() { }
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// The list of perceptoid which can process stimuli from this receptor
|
||||
/// </summary>
|
||||
//public List<Perceptoid> 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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user