public void setNetwork(Network _net) { int x = 130; int y = -50; net = _net; List <List <Node> > layers = net.net; for (int i = 0; i < layers.Count; i++) { for (int j = 0; j < layers[i].Count; j++) { GameObject created = Instantiate(nodePrefab); Text title = created.transform.GetChild(1).gameObject.GetComponent <Text>(); Text value = created.transform.GetChild(2).gameObject.GetComponent <Text>(); Button btn = created.transform.GetChild(3).gameObject.GetComponent <Button>(); //btn.name = j.ToString(); string type = layers[i][j].GetType().Name; //Debug.Log("type " + type); bool castWorked = true; NonInputNode nodeArg = null; try { nodeArg = (NonInputNode)layers[i][j]; } catch (InvalidCastException e) { castWorked = false; } if (castWorked) { btn.onClick.AddListener(() => { createNodePanel(nodeArg); }); } string titleText = ""; switch (type) { case "SensoryInputNode": SensoryInputNode siNode = (SensoryInputNode)layers[i][j]; titleText = "sense " + siNode.sensedResource + " " + Helper.neighborIndexToWord(siNode.neighborLandIndex); break; case "OutputNode": OutputNode outNode = (OutputNode)layers[i][j]; titleText = outNode.action.name; break; case "InternalResourceInputNode": InternalResourceInputNode internNode = (InternalResourceInputNode)layers[i][j]; titleText = internNode.sensedResource + " stored"; break; case "InnerInputNode": InnerInputNode innerNode = (InnerInputNode)layers[i][j]; titleText = innerNode.linkedNetName; break; case "PhenotypeInputNode": PhenotypeInputNode phenoNode = (PhenotypeInputNode)layers[i][j]; titleText = "Pheno: " + phenoNode.neighborIndex; break; case "BiasNode": titleText = "Bias Node"; break; default: titleText = ""; break; } double rounded = System.Math.Round((double)layers[i][j].value, 2); value.text = rounded.ToString(); title.text = titleText; created.transform.SetParent(canvas.transform, false); RectTransform transform = created.GetComponent <RectTransform>(); transform.anchoredPosition = new Vector2(x, y); y -= 40; if (j % 8 == 0 && j != 0) { x += 70; y = -50; } instantiated.Add(created); } x += 120; y = -50; } }
public SensoryInputNodeEditor(SensoryInputNode _siNode, int _nodeLayer) { siNode = _siNode; nodeLayer = _nodeLayer; }
public static Node getNewNode(Node oldNode, Creature creatureCopy, Network parentNet) { if (oldNode.GetType().Name == "SensoryInputNode") { SensoryInputNode newNode = (SensoryInputNode)oldNode.clone(); newNode.creature = creatureCopy; return(newNode); } else if (oldNode.GetType().Name == "InternalResourceInputNode") { InternalResourceInputNode newNode = (InternalResourceInputNode)oldNode.clone(); newNode.creature = creatureCopy; return(newNode); } else if (oldNode.GetType().Name == "OutputNode") { OutputNode oldNode2 = (OutputNode)oldNode; OutputNode newNode = (OutputNode)oldNode.clone(); newNode.resetRand(); newNode.parentNet = parentNet; newNode.parentCreature = creatureCopy; newNode.action = getNewAction(newNode.action); //newNode.setActivBehavior(new LogisticActivBehavior()); newNode.prevNodes = new List <Node>(); newNode.assignPrevNodes(); newNode.weights = new List <float>(); for (int i = 0; i < oldNode2.weights.Count; i++) { newNode.weights.Add(oldNode2.weights[i]); } newNode.extraWeights = new List <float>(); for (int i = 0; i < oldNode2.extraWeights.Count; i++) { newNode.extraWeights.Add(oldNode2.extraWeights[i]); } return(newNode); } else if (oldNode.GetType().Name == "NonInputNode") { NonInputNode oldNode2 = (NonInputNode)oldNode; NonInputNode newNode = (NonInputNode)oldNode.clone(); newNode.resetRand(); newNode.parentNet = parentNet; newNode.parentCreature = creatureCopy; //newNode.setActivBehavior(new LogisticActivBehavior()); newNode.prevNodes = new List <Node>(); newNode.assignPrevNodes(); newNode.weights = new List <float>(); for (int i = 0; i < oldNode2.weights.Count; i++) { newNode.weights.Add(oldNode2.weights[i]); } newNode.extraWeights = new List <float>(); for (int i = 0; i < oldNode2.extraWeights.Count; i++) { newNode.extraWeights.Add(oldNode2.extraWeights[i]); } return(newNode); } else if (oldNode.GetType().Name == "BiasNode") { BiasNode oldNode2 = (BiasNode)oldNode; BiasNode newNode = oldNode2.clone(); return(newNode); } else if (oldNode.GetType().Name == "InnerInputNode") { InnerInputNode oldNode2 = (InnerInputNode)oldNode; InnerInputNode newNode = oldNode2.clone(); newNode.parentCreature = creatureCopy; /* * Debug.Log("linked network layer number: " + oldNode2.linkedNodeNetworkLayer); * Debug.Log("net name: " + oldNode2.linkedNetName); * Debug.Log("node index: " + newNode.linkedNodeIndex); */ Network linkedNetwork = creatureCopy.networks[oldNode2.linkedNodeNetworkLayer][oldNode2.linkedNetName]; newNode.linkedNode = linkedNetwork.net[linkedNetwork.net.Count - 1][newNode.linkedNodeIndex]; return(newNode); } // called when template is being copied else if (oldNode.GetType().Name == "PhenotypeInputNode") { PhenotypeInputNode oldNode2 = (PhenotypeInputNode)oldNode; PhenotypeInputNode newNode = (PhenotypeInputNode)oldNode.clone(); // copy phenotype newNode.parentCreat = creatureCopy; int length = oldNode2.phenotype.Length; newNode.phenotype = new bool[length]; for (int i = 0; i < newNode.phenotype.Length; i++) { newNode.phenotype[i] = oldNode2.phenotype[i]; } return(newNode); } else if (oldNode.GetType().Name == "CommInputNode") { //TODO return(null); } else if (oldNode.GetType().Name == "MemoryInputNode") { //TODO return(null); } else { Debug.LogError("Didn't find correct type of node to add"); return(null); } }