Beispiel #1
0
    public override object Read(ES2Reader reader)
    {
        CritterNode data = new CritterNode();

        Read(reader, data);
        return(data);
    }
 public CritterNode CloneThisCritterNode() {
     CritterNode clonedCritterNode = new CritterNode(this.ID, this.innov);
     clonedCritterNode.dimensions = this.dimensions;
     clonedCritterNode.jointLink.CopySettingsFromJointLink(this.jointLink);
     for(int i = 0; i < this.attachedChildNodesIdList.Count; i++) {
         // populate clonedNode's attachedChild list based on this Node
         clonedCritterNode.attachedChildNodesIdList.Add(this.attachedChildNodesIdList[i]);
     }
     return clonedCritterNode;
 }
 public void CopySettingsFromNode(CritterNode sourceNode) {
     this.iD = sourceNode.ID;
     this.innov = sourceNode.innov;
     this.dimensions = sourceNode.dimensions;
     this.jointLink.CopySettingsFromJointLink(sourceNode.jointLink);
     for (int i = 0; i < sourceNode.attachedChildNodesIdList.Count; i++) {
         // populate clonedNode's attachedChild list based on this Node
         this.attachedChildNodesIdList.Add(sourceNode.attachedChildNodesIdList[i]);
     }
 }
 public void CopySettingsFromNode(CritterNode sourceNode)
 {
     this.iD         = sourceNode.ID;
     this.innov      = sourceNode.innov;
     this.dimensions = sourceNode.dimensions;
     this.jointLink.CopySettingsFromJointLink(sourceNode.jointLink);
     for (int i = 0; i < sourceNode.attachedChildNodesIdList.Count; i++)
     {
         // populate clonedNode's attachedChild list based on this Node
         this.attachedChildNodesIdList.Add(sourceNode.attachedChildNodesIdList[i]);
     }
 }
    public CritterNode CloneThisCritterNode()
    {
        CritterNode clonedCritterNode = new CritterNode(this.ID, this.innov);

        clonedCritterNode.dimensions = this.dimensions;
        clonedCritterNode.jointLink.CopySettingsFromJointLink(this.jointLink);
        for (int i = 0; i < this.attachedChildNodesIdList.Count; i++)
        {
            // populate clonedNode's attachedChild list based on this Node
            clonedCritterNode.attachedChildNodesIdList.Add(this.attachedChildNodesIdList[i]);
        }
        return(clonedCritterNode);
    }
Beispiel #6
0
    public override void Write(object obj, ES2Writer writer)
    {
        CritterNode data = (CritterNode)obj;

        // Add your writer.Write calls here.
        writer.Write(0); // Version 0 is current version number
        // Make sure to edit Read() function to properly handle version control!
        // VERSION 0:
        //writer.Write(data.attachedJointLinkList);
        //writer.Write(data.jointLink);
        writer.Write(data.attachedChildNodesIdList);
        writer.Write(data.jointLink);
        writer.Write(data.dimensions);
        writer.Write(data.ID);
        writer.Write(data.innov);
    }
Beispiel #7
0
    public override void Read(ES2Reader reader, object c)
    {
        CritterNode data = (CritterNode)c;
        // Add your reader.Read calls here to read the data into the object.
        // Read the version number.
        int fileVersion = reader.Read <int>();

        // VERSION 0:
        if (fileVersion >= 0)
        {
            //data.attachedJointLinkList = reader.ReadList<CritterJointLink>();
            //if (data.jointLink != null)
            data.attachedChildNodesIdList = reader.ReadList <System.Int32>();
            data.jointLink  = reader.Read <CritterJointLink>();
            data.dimensions = reader.Read <Vector3>();
            data.ID         = reader.Read <System.Int32>();
            data.innov      = reader.Read <System.Int32>();
        }
    }
 public void UpdateNodeAddonsPanel(bool segmentOn, GameObject selectedSegment, bool active)
 {
     if (active)
     {
         panelNodeAddons.panelOverlay.SetActive(false);
     }
     else
     {
         panelNodeAddons.panelOverlay.SetActive(true);
     }
     if (selectedSegment != null)
     {
         CritterNode sourceNode = selectedSegment.GetComponent <CritterSegment>().sourceNode;
         panelNodeAddons.textNodeID.text = "Selected Node ID: " + sourceNode.ID.ToString() + " [" + sourceNode.innov.ToString() + "]";
     }
     else
     {
         panelNodeAddons.textNodeID.text = "Selected Node ID: none";
     }
 }
    public CritterGenome() {
        //Debug.Log("CritterGenome Constructor()!");

        CritterNodeList = new List<CritterNode>();
        CritterNode critterRootNode = new CritterNode(0, 0); // create root node  // Does Root node ALWAYS have innov=0?
        CritterNodeList.Add(critterRootNode); // set it to first member of the list.

        addonPhysicalAttributesList = new List<AddonPhysicalAttributes>();
        
        addonJointAngleSensorList = new List<AddonJointAngleSensor>();
        addonContactSensorList = new List<AddonContactSensor>();
        addonRaycastSensorList = new List<AddonRaycastSensor>();
        addonCompassSensor1DList = new List<AddonCompassSensor1D>();
        addonCompassSensor3DList = new List<AddonCompassSensor3D>();
        addonPositionSensor1DList = new List<AddonPositionSensor1D>();
        addonPositionSensor3DList = new List<AddonPositionSensor3D>();
        addonRotationSensor1DList = new List<AddonRotationSensor1D>();
        addonRotationSensor3DList = new List<AddonRotationSensor3D>();
        addonVelocitySensor1DList = new List<AddonVelocitySensor1D>();
        addonVelocitySensor3DList = new List<AddonVelocitySensor3D>();
        addonAltimeterList = new List<AddonAltimeter>();
        addonEarBasicList = new List<AddonEarBasic>();
        addonGravitySensorList = new List<AddonGravitySensor>();

        addonOscillatorInputList = new List<AddonOscillatorInput>();
        addonValueInputList = new List<AddonValueInput>();
        addonTimerInputList = new List<AddonTimerInput>();

        addonJointMotorList = new List<AddonJointMotor>();
        addonThrusterEffector1DList = new List<AddonThrusterEffector1D>();
        addonThrusterEffector3DList = new List<AddonThrusterEffector3D>();
        addonTorqueEffector1DList = new List<AddonTorqueEffector1D>();
        addonTorqueEffector3DList = new List<AddonTorqueEffector3D>();
        addonMouthBasicList = new List<AddonMouthBasic>();
        addonNoiseMakerBasicList = new List<AddonNoiseMakerBasic>();
        addonStickyList = new List<AddonSticky>();
        addonWeaponBasicList = new List<AddonWeaponBasic>();        
    }
	public override object Read(ES2Reader reader)
	{
		CritterNode data = new CritterNode();
		Read(reader, data);
		return data;
	}
 public void ResetToBlankGenome() {
     if(CritterNodeList == null) {
         CritterNodeList = new List<CritterNode>();
     }
     else {
         ClearAllAddons();
         CritterNodeList.Clear();
     }
     CritterNode critterRootNode = new CritterNode(0, 0); // create root node
     //critterRootNode.jointLink.parentNode = critterRootNode;
     CritterNodeList.Add(critterRootNode); // set it to first member of the list.
 }
    public void DeleteBranch(CritterNode node) {  // Removes the specified nodes as well as all of its children / mirrors

    }
 /*public void AddNewNode(CritterNode parentNode, Vector3 attachDir, int id) {        
     CritterNode newCritterNode = new CritterNode(id);
     newCritterNode.jointLink.parentNodeID = parentNode.ID;
     newCritterNode.jointLink.thisNodeID = newCritterNode.ID;
     newCritterNode.jointLink.numberOfRecursions = 0;
     Vector3 newSegmentDimensions = parentNode.dimensions;
     newCritterNode.dimensions = newSegmentDimensions;
     parentNode.attachedChildNodesIdList.Add(newCritterNode.ID);  // check this
     newCritterNode.jointLink.attachDir = attachDir.normalized;        
     CritterNodeList.Add(newCritterNode);
     //Debug.Log("AddNewNode(CritterNode parentNode = " + parentNode.ID.ToString() + ", Vector3 attachDir = " + newCritterNode.jointLink.attachDir.ToString() + ")");
 }*/
 public void AddNewNode(CritterNode parentNode, Vector3 attachDir, Vector3 restAngleDir, int id, int inno) {
     CritterNode newCritterNode = new CritterNode(id, inno);
     newCritterNode.jointLink.parentNodeID = parentNode.ID;
     //newCritterNode.jointLink.jointType = CritterJointLink.JointType. // Need to change this so the jointType can vary -- right now it's only HingeX!
     newCritterNode.jointLink.thisNodeID = newCritterNode.ID;
     newCritterNode.jointLink.numberOfRecursions = 0;
     Vector3 newSegmentDimensions = parentNode.dimensions;
     newCritterNode.dimensions = newSegmentDimensions;
     parentNode.attachedChildNodesIdList.Add(newCritterNode.ID);
     newCritterNode.jointLink.attachDir = attachDir.normalized;
     newCritterNode.jointLink.restAngleDir = restAngleDir.normalized;
     CritterNodeList.Add(newCritterNode);
     Debug.Log("AddNewNode(CritterNodeID: " + newCritterNode.ID.ToString() + ", parentNode = " + parentNode.ID.ToString() + ", attachDir = " + newCritterNode.jointLink.attachDir.ToString() + ")" + " restAngleDir: " + restAngleDir.ToString());
 }
    public void AddNewNode(CritterNode parentNode, CritterJointLink jointLink) {
        //Debug.Log("AddNewNode(CritterNode parentNode, CritterJointLink jointLink)");

    }
    public void AddNewNode(CritterNode parentNode) {
        //Debug.Log("AddNewNode(CritterNode parentNode)");

    }
    public void UpdateSegmentSettingsPanel(bool segmentOn, GameObject selectedSegment, bool active)
    {
        if (active)
        {
            panelSegmentSettings.panelOverlay.SetActive(false);
        }
        else
        {
            panelSegmentSettings.panelOverlay.SetActive(true);
        }
        if (selectedSegment != null)
        {
            CritterNode sourceNode = selectedSegment.GetComponent <CritterSegment>().sourceNode;
            panelSegmentSettings.textSegmentID.text = "Segment ID: " + selectedSegment.GetComponent <CritterSegment>().id.ToString();
            panelSegmentSettings.textNodeID.text    = "(Node: " + sourceNode.ID.ToString() + ")";
            if (sourceNode.ID != 0)  // if not the ROOT
            {
                panelSegmentSettings.textParentSegmentID.text = "Parent Segment ID: " + selectedSegment.GetComponent <CritterSegment>().parentSegment.id.ToString();
                panelSegmentSettings.textParentNodeID.text    = "(Node: " + sourceNode.jointLink.parentNodeID.ToString() + ")";
            }
            else
            {
                panelSegmentSettings.textParentSegmentID.text = "Parent Segment ID: ";
                panelSegmentSettings.textParentNodeID.text    = "(Root)";
            }
            Vector3 size = sourceNode.dimensions;
            size.x = (float)Math.Round((double)size.x, 2);
            size.y = (float)Math.Round((double)size.y, 2);
            size.z = (float)Math.Round((double)size.z, 2);
            panelSegmentSettings.textDimensionX.text           = "X: " + size.x.ToString();
            panelSegmentSettings.textDimensionY.text           = "Y: " + size.y.ToString();
            panelSegmentSettings.textDimensionZ.text           = "Z: " + size.z.ToString();
            panelSegmentSettings.sliderDimensionX.value        = size.x;
            panelSegmentSettings.sliderDimensionY.value        = size.y;
            panelSegmentSettings.sliderDimensionZ.value        = size.z;
            panelSegmentSettings.textInheritedScaleFactor.text = "Inherited Scale Factor: " + selectedSegment.GetComponent <CritterSegment>().scalingFactor.ToString();

            Vector3 attachDir = sourceNode.jointLink.attachDir;
            attachDir.x = (float)Math.Round((double)attachDir.x, 2);
            attachDir.y = (float)Math.Round((double)attachDir.y, 2);
            attachDir.z = (float)Math.Round((double)attachDir.z, 2);
            panelSegmentSettings.textAttachDirX.text    = "X: " + attachDir.x.ToString();
            panelSegmentSettings.textAttachDirY.text    = "Y: " + attachDir.y.ToString();
            panelSegmentSettings.textAttachDirZ.text    = "Z: " + attachDir.z.ToString();
            panelSegmentSettings.sliderAttachDirX.value = attachDir.x;
            panelSegmentSettings.sliderAttachDirY.value = attachDir.y;
            panelSegmentSettings.sliderAttachDirZ.value = attachDir.z;

            Vector3 restAngle = sourceNode.jointLink.restAngleDir;
            restAngle.x = (float)Math.Round((double)restAngle.x, 2);
            restAngle.y = (float)Math.Round((double)restAngle.y, 2);
            restAngle.z = (float)Math.Round((double)restAngle.z, 2);
            panelSegmentSettings.textRestAngleX.text    = "X: " + restAngle.x.ToString();
            panelSegmentSettings.textRestAngleY.text    = "Y: " + restAngle.y.ToString();
            panelSegmentSettings.textRestAngleZ.text    = "Z: " + restAngle.z.ToString();
            panelSegmentSettings.sliderRestAngleX.value = restAngle.x;
            panelSegmentSettings.sliderRestAngleY.value = restAngle.y;
            panelSegmentSettings.sliderRestAngleZ.value = restAngle.z;

            panelSegmentSettings.dropdownJointType.value = (int)sourceNode.jointLink.jointType;

            panelSegmentSettings.textNumRecursions.text           = "Recursion Number: " + sourceNode.jointLink.numberOfRecursions.ToString();
            panelSegmentSettings.textRecursionScaleFactor.text    = "Scale Factor: " + sourceNode.jointLink.recursionScalingFactor.ToString();
            panelSegmentSettings.sliderRecursionScaleFactor.value = sourceNode.jointLink.recursionScalingFactor;
            panelSegmentSettings.textRecursionForward.text        = "Forward Bias: " + sourceNode.jointLink.recursionForward.ToString();
            panelSegmentSettings.sliderRecursionForward.value     = sourceNode.jointLink.recursionForward;
            panelSegmentSettings.toggleAttachOnlyToLast.isOn      = sourceNode.jointLink.onlyAttachToTailNode;

            panelSegmentSettings.dropdownSymmetryType.value = (int)sourceNode.jointLink.symmetryType;

            panelSegmentSettings.textJointAngleLimit.text             = "Primary: " + sourceNode.jointLink.jointLimitPrimary.ToString();
            panelSegmentSettings.textJointAngleLimitSecondary.text    = "Secondary: " + sourceNode.jointLink.jointLimitSecondary.ToString();
            panelSegmentSettings.sliderJointAngleLimit.value          = sourceNode.jointLink.jointLimitPrimary;
            panelSegmentSettings.sliderJointAngleLimitSecondary.value = sourceNode.jointLink.jointLimitSecondary;
        }
        else
        {
            panelSegmentSettings.textSegmentID.text  = "Segment ID: none";
            panelSegmentSettings.textNodeID.text     = "Parent ID: none";
            panelSegmentSettings.textDimensionX.text = "X: ";
            panelSegmentSettings.textDimensionY.text = "Y: ";
            panelSegmentSettings.textDimensionZ.text = "Z: ";
            panelSegmentSettings.textAttachDirX.text = "X: ";
            panelSegmentSettings.textAttachDirY.text = "Y: ";
            panelSegmentSettings.textAttachDirZ.text = "Z: ";
            panelSegmentSettings.textRestAngleX.text = "X: ";
            panelSegmentSettings.textRestAngleY.text = "Y: ";
            panelSegmentSettings.textRestAngleZ.text = "Z: ";
        }
    }
    public void RebuildBranchFromGenome(CritterNode node) {  // resets and re-constructs only a branch of the Critter, starting with specified node

    }
 public void BodyCrossover(ref CritterNode clonedCritterNode, CritterNode lessFitNode) {
     // Node dimensions
     if(CheckForMutation(0.5f)) {
         clonedCritterNode.dimensions = lessFitNode.dimensions;
     }
     // Joint Settings - placement, orientation
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.attachDir = lessFitNode.jointLink.attachDir;
     }
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.restAngleDir = lessFitNode.jointLink.restAngleDir;
     }
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.jointLimitPrimary = lessFitNode.jointLink.jointLimitPrimary;
         clonedCritterNode.jointLink.jointLimitSecondary = lessFitNode.jointLink.jointLimitSecondary;
         clonedCritterNode.jointLink.jointType = lessFitNode.jointLink.jointType;
     }
     // Recursion
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.numberOfRecursions = lessFitNode.jointLink.numberOfRecursions;
     }
     // Symmetry
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.symmetryType = lessFitNode.jointLink.symmetryType;
     }
     // Scale Factors, forward Bias, Attach only to Last, etc.
     if (CheckForMutation(0.5f)) {
         clonedCritterNode.jointLink.recursionScalingFactor = lessFitNode.jointLink.recursionScalingFactor;
         clonedCritterNode.jointLink.recursionForward = lessFitNode.jointLink.recursionForward;
         clonedCritterNode.jointLink.onlyAttachToTailNode = lessFitNode.jointLink.onlyAttachToTailNode;
     }
 }
 public void DeleteNode(CritterNode node) {
     int deletedID = node.ID; // id of the node being deleted 
     masterCritterGenome.DeleteNode(deletedID);  // handled within Genome
 }