82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// The Nanobrain namespace
|
|
/// </summary>
|
|
namespace NanoBrain {
|
|
|
|
/// <summary>
|
|
/// A Nucleus is a basic element in a brain cluster
|
|
/// </summary>
|
|
[Serializable]
|
|
public abstract class Nucleus {
|
|
/// <summary>
|
|
/// The name of the Nucleus
|
|
/// </summary>
|
|
[HideInInspector]
|
|
public string name;
|
|
|
|
/// <summary>
|
|
/// The cluster instance in which the nucleus is located
|
|
/// </summary>
|
|
[SerializeReference]
|
|
//[HideInInspector]
|
|
public Cluster parent;
|
|
|
|
/// <summary>
|
|
/// Function to make a partial clone of this nucleus
|
|
/// </summary>
|
|
/// <param name="parent">The cluster in which the cloned nucleus should be placed</param>
|
|
/// <returns></returns>
|
|
public abstract Nucleus ShallowCloneTo(Cluster parent);
|
|
|
|
/// <summary>
|
|
/// The types of Nucleus
|
|
/// </summary>
|
|
public enum Type {
|
|
None,
|
|
Neuron,
|
|
MemoryCell,
|
|
Cluster,
|
|
}
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Update the state without updating other Nuclei
|
|
/// </summary>
|
|
public abstract void UpdateStateIsolated();
|
|
|
|
#endregion Update
|
|
|
|
public static bool EqualStructure(Nucleus nucleus1, Nucleus nucleus2) {
|
|
if (nucleus1.parent != null && nucleus2.parent != null) {
|
|
if (nucleus1.parent.baseName != nucleus2.parent.baseName)
|
|
return false;
|
|
} else {
|
|
// mainly to check one is null, other is not.
|
|
if (nucleus1.parent != nucleus2.parent)
|
|
return false;
|
|
}
|
|
|
|
if (nucleus1 is Neuron neuron1) {
|
|
if (nucleus2 is not Neuron neuron2)
|
|
return false;
|
|
if (neuron1.name != neuron2.name)
|
|
return false;
|
|
return Neuron.EqualStructure(neuron1, neuron2);
|
|
}
|
|
else if (nucleus1 is Cluster cluster1) {
|
|
if (nucleus2 is not Cluster cluster2)
|
|
return false;
|
|
if (cluster1.baseName != cluster2.baseName)
|
|
return false;
|
|
return Cluster.EqualStructure(cluster1, cluster2);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} |