public void mutate(float mutationProb) { Queue <BehaviourNode> toLoop = new Queue <BehaviourNode> (); while (toLoop.Count != 0) { BehaviourNode bn = toLoop.Dequeue(); if (rollDice(mutationProb)) { bn.mutate(); } foreach (BehaviourNode bhvn in bn.getNextNodes()) { toLoop.Enqueue(bhvn); } } }
private void iterate(BehaviourNode bn) { if (bn.getNextNodes() != null && bn.getNextNodes().Count > 0) { for (int i = 0; i < bn.getNextNodes().Count; i++) { if (bn.getNextNodes()[i] != null) { iterate(bn.getNextNodes()[i]); } if (UnityEngine.Random.Range(0.0f, 1.0f) > mutationRate) { bn.mutate(); } } } }
public void mutate(BehaviourNode current, BehaviourNode parent, int i) { if (current is IFunction && Random.Range(0, 1) < functionMutationRate && parent != null) { int randomFunction = Random.Range(0, functions.Count - 1); BehaviourNode function = (BehaviourNode)System.Activator.CreateInstance(functions[randomFunction]); function.setNextNodes(current.getNextNodes()); parent.getNextNodes()[i] = function; } else if (Random.Range(0, 1) < terminalMutationRate) { current.mutate(); } int index = 0; foreach (BehaviourNode child in current.getNextNodes()) { index++; mutate(child, current, index); } }