/// <summary> /// Create a network that senses some or all of the creature's internal resource levels. /// </summary> /// <param name="netCreator">Network wrapper.</param> /// <param name="layer">Layer of network (probably 0).</param> /// <param name="name">Name of network.</param> /// <param name="resourcesToSense">A list of the internal resources that the network should sense.</param> /// <param name="outputActions">A list of the output actions that should be associated with this network (through output nodes connected to output networks).</param> /// <param name="hiddenLayerNum">Number of hidden layers.</param> /// <param name="nodesPerLayer">Number of nodes per hidden layer.</param> /// <param name="hiddenActiv">Activation function for hidden nodes.</param> /// <param name="outputActiv">Activation function for output nodes.</param> public static void makeInternalInputNetwork(NetworkEditor netCreator, int layer, string name, List <string> resourcesToSense, List <string> outputActions, int hiddenLayerNum, int nodesPerLayer, ActivationBehaviorTypes hiddenActiv, ActivationBehaviorTypes outputActiv) { netCreator.setInLayer(layer); // called by default with index of layer user clicked netCreator.setName(name); // for every resource for (int i = 0; i < resourcesToSense.Count; i++) { makeInternalResourceInputNode(netCreator, resourcesToSense[i]); } int outputLayer = hiddenLayerNum + 1; // for every hidden layer for (int i = 0; i < hiddenLayerNum; i++) { netCreator.insertNewLayer(i + 1); // add every node in that layer for (int j = 0; j < nodesPerLayer; j++) { makeHiddenNode(netCreator, hiddenActiv, i + 1); } } for (int i = 0; i < outputActions.Count; i++) { makeOutputNode(netCreator, outputActiv, outputActions[i], outputLayer); } }
/// <summary> /// Resets netCreator, allowing for the creation of a new network. /// </summary> public NetworkEditor addNetwork(NetworkType type) { switch (type) { case NetworkType.regular: netCreator = new NetworkEditor(new Network(), this); break; case NetworkType.phenotype: netCreator = new PhenotypeNetworkEditor(new PhenotypeNetwork(), this); break; case NetworkType.output: netCreator = new OutputNetworkEditor(new OutputNetwork(), this); break; case NetworkType.comm: // TODO break; default: Debug.LogError("Invalid network type"); break; } return(netCreator); }
private IEnumerable <INeuralNetworkMetadata> GenerateNewGeneration(int maxNumberOfNetworks) { var editor = NetworkEditor.CreateRandom(new DoubleRange(-5, 5), new DoubleRange(-5, 5)); for (int i = 0; i < maxNumberOfNetworks; i++) { var nn = SimpleNeuralNetworkFactory.Create(_nrOfInputs, _nrOfHidden, _nrOfOutputs); editor.Manipulate(nn); yield return(new NeuralNetworkMetadata(nn, 0)); } }
/// <summary> /// Create a node that senses the level of a resource stored in the Creature. /// </summary> /// <param name="netCreator">Network wrapper.</param> /// <param name="sensedResource">Resource to be sensed.</param> public static void makeInternalResourceInputNode(NetworkEditor netCreator, string sensedResource) { NodeEditor nodeCreator = netCreator.addNode(0); // add to first layer // user sets node type to sensory input node nodeCreator.setCreator(NodeCreatorType.internalResNodeEditor); InternalResInputNodeEditor irnc = (InternalResInputNodeEditor)nodeCreator.getNodeCreator(); irnc.setSensedResource(sensedResource); // user clicks save on node editor netCreator.saveNode(); }
/// <summary> /// Add a hidden node to a particular network. /// </summary> /// <param name="netCreator">Wrapper for Network.</param> /// <param name="activationType">Activation type for hidden node.</param> /// <param name="layer">Layer in which hidden node is to be added.</param> public static void makeHiddenNode(NetworkEditor netCreator, ActivationBehaviorTypes activationType, int layer) { // user adds node to second layer NodeEditor nodeCreator = netCreator.addNode(layer); nodeCreator.setCreator(NodeCreatorType.hiddenNode); HiddenNodeEditor hne = (HiddenNodeEditor)nodeCreator.getNodeCreator(); hne.setActivationFunction(activationType); netCreator.saveNode(); // user clicks save on network creator }
/// <summary> /// Make a first layer node that gets its value from a node in the last layer of another network. /// </summary> /// <param name="netCreator">Network wrapper.</param> /// <param name="layer">Layer in which node is to be added.</param> /// <param name="linkedNetName">Name of the linked network.</param> /// <param name="linkedNetIndex">Layer of linked network in layers of networks.</param> /// <param name="linkedNodeIndex">The index of the linked node in that final layer of the linked network.</param> public static void makeInnerInputNode(NetworkEditor netCreator, int layer, string linkedNetName, int linkedNetIndex, int linkedNodeIndex) { // user adds nodes to input layer (0) NodeEditor nodeCreator = netCreator.addNode(layer); // user adds inner input node nodeCreator.setCreator(NodeCreatorType.innerInputNodeCreator); InnerInputNodeEditor iinc = (InnerInputNodeEditor)nodeCreator.getNodeCreator(); // the inner input node gets its value from net1's output node at index 0 iinc.setLinkedNode(linkedNetName, linkedNodeIndex, linkedNetIndex); // user clicks save on node editor netCreator.saveNode(); }
/// <summary> /// Create a node to sense the level of a particular resource from a particular neighboring square. /// </summary> /// <param name="netCreator">Network wrapper.</param> /// <param name="landIndex">Index of neighboring land square to sense: 0: center, 1: up, 2: down, 3: left, 4: right.</param> /// <param name="sensedResource">Resource to be sensed.</param> public static void makeSensoryInputNode(NetworkEditor netCreator, int landIndex, string sensedResource) { NodeEditor nodeCreator = netCreator.addNode(0); // user sets node type to sensory input node nodeCreator.setCreator(NodeCreatorType.siNodeCreator); // the sensory node editor gets it's sensory input node creator from nodeCreator SensoryInputNodeEditor sinc2 = (SensoryInputNodeEditor)nodeCreator.getNodeCreator(); // the sinc is used to set properties on the sensory input node sinc2.setLandIndex(landIndex); sinc2.setSensedResource(sensedResource); // user clicks save on node editor netCreator.saveNode(); }
private IEnumerable <INeuralNetworkMetadata> CreateNewSurvivorGeneration(INeuralNetworkMetadata[] survivors, int survivorGenerationSize) { var nrOfSurvivors = survivors.Count(); int nrOfVariationsPerSurvivor = survivorGenerationSize / nrOfSurvivors; var varyWeightsEditor = NetworkEditor.CreateVaryWeights(new DoubleRange(0.8, 1.2)); foreach (var survivor in survivors) { _swarm.Add(survivor); for (int i = 0; i < nrOfVariationsPerSurvivor; i++) { var nn = survivor.Network.Clone(); varyWeightsEditor.Manipulate(nn); yield return(new NeuralNetworkMetadata(nn, survivor.Generation)); } } }
void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) { if (myLst.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { myLst.ItemContainerGenerator.StatusChanged -= new EventHandler(ItemContainerGenerator_StatusChanged); myLst.ScrollIntoView(((S5FunctionBlock)myBlock).Networks[netzwerknr - 1]); DependencyObject depObj = myLst.ItemContainerGenerator.ContainerFromIndex(netzwerknr - 1); NetworkEditor nedt = depObj.TryFindChild <NetworkEditor>(); Network netw = ((S5FunctionBlock)myBlock).Networks[netzwerknr - 1]; int anz = 0; for (int q = 0; q < zeile - 1; q++) { anz += netw.AWLCode[q].ToString().Length + 2; } nedt.ShowLine(zeile, anz, netw.AWLCode[zeile - 1].ToString().Length); } }
/// <summary> /// Create a node that connects the networks to actions. These nodes belong in the last layer of the last networks. /// </summary> /// <param name="netCreator">Network wrapper.</param> /// <param name="activationType">Activation type: should have an output in the range: [0,1] to be associated with a probability.</param> /// <param name="action">Action that the node is associated with.</param> /// <param name="layer">Layer in which to place node (final layer).</param> public static void makeOutputNode(NetworkEditor netCreator, ActivationBehaviorTypes activationType, string action, int layer) { // user adds node to second layer NodeEditor nodeCreator = netCreator.addNode(layer); nodeCreator.setCreator(NodeCreatorType.outputNodeCreator); OutputNodeEditor onc = (OutputNodeEditor)nodeCreator.getNodeCreator(); if (!netCreator.parentCreatureCreator.creature.actionPool.ContainsKey(action)) { Debug.LogError("invalid action key for output node"); } else { Action a = netCreator.parentCreatureCreator.creature.actionPool[action]; onc.setAction(a); onc.setActivationFunction(activationType); netCreator.saveNode(); } // user clicks save on network creator }
/* * create creature, * create and save creature resource, * create creature network, * create network node, * add resource to node, * save creature to founder creatures dict and species dict */ public void addSpecies(string name, ColorChoice color, float mutationDeviation, string primaryConsume, string dependentOn, string produces, float mutationDeviationFraction, float lowestMutationDeviation, bool nonLinearPhenotypeNet, int phenotype, int turnTime) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, phenotype, turnTime, 1000, 700, 3, 10, mutationDeviation, color, true, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // user edits: List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); //Debug.Log("resource added to creature: " + ecosystemResources[0]); // add creature resource store for primary resource that creature needs ResourceEditor resourceCreator = cc.addResource(); EcoCreationHelper.addCreatureResource(resourceCreator, primaryConsume, 100, 90, 1, 90, 5, 20, 1); cc.saveResource(); // add creature resource store for resouce creature produces // Note: Creature 1 doesn't need this resource to survive (no health gain or drain) resourceCreator = cc.addResource(); EcoCreationHelper.addCreatureResource(resourceCreator, produces, 100, 90, 0, 90, 0, 20, 1); cc.saveResource(); // add creature resource store for resouce creature is dependent on resourceCreator = cc.addResource(); // high starting level, so that population doesn't die out immediately EcoCreationHelper.addCreatureResource(resourceCreator, dependentOn, 100, 90, 1, 50, 1, 5, 1); cc.saveResource(); // for reference later List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // generates movement actions with a resource cost cc.generateMovementActions(primaryConsume, 5); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eat" + primaryConsume, 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, primaryConsume); cc.saveAction(); // create action for consuming Resource that creature is dependent on ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eat" + dependentOn, 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, dependentOn); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { primaryConsume, 20 }, { dependentOn, 50 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // action for converting with a 1 to 2 ratio ae = cc.addAction(); ae.setCreator(ActionCreatorType.convertEditor); ConvertEditor convEdit = (ConvertEditor)ae.getActionCreator(); resourceCosts = new Dictionary <string, float>() { { primaryConsume, 1 } }; EcoCreationHelper.setBasicActionParams(convEdit, "convert" + primaryConsume + "To" + produces, 1, 10, resourceCosts); Dictionary <string, float> startResources = new Dictionary <string, float>() { { primaryConsume, 1f } }; Dictionary <string, float> endResources = new Dictionary <string, float>() { { produces, 10f } }; EcoCreationHelper.setConvertActionParams(convEdit, 5, startResources, endResources); cc.saveAction(); // action for depositing B ae = cc.addAction(); ae.setCreator(ActionCreatorType.depositEditor); DepositEditor depEdit = (DepositEditor)ae.getActionCreator(); // no resource costs for depositing EcoCreationHelper.setBasicActionParams(depEdit, "deposit" + produces, 1, 10, null); EcoCreationHelper.setDepositActionParams(depEdit, 0, produces, 10); cc.saveAction(); // user opens networks creator for that creature /**** phenotype network template ****/ PhenotypeNetworkEditor phenoNetCreator = (PhenotypeNetworkEditor)cc.addNetwork(NetworkType.phenotype); List <string> phenoOutputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; if (nonLinearPhenotypeNet) { EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 4, 2, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); } else { EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 0, 0, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); } // Note: don't call saveNetwork(), call savePhenotypeNetwork() cc.savePhenotypeNetwork(); //Debug.Log("finished creating phenotype net"); // create network to sense external resource levels /**** net1 ****/ // user adds a network NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); List <string> resourcesToSense = creatureResources; // sense resources creature can store List <string> outputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "externalNet", resourcesToSense, outputActions, 1, 6, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally resourcesToSense = creatureResources; // use all output actions again outputActions = new List <string>() { "deposit" + produces, "convert" + primaryConsume + "To" + produces, "reproduce", "eat" + dependentOn, "eat" + primaryConsume, "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 1, 6, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetEat" + primaryConsume, "eat" + primaryConsume }, { "outNetEat" + dependentOn, "eat" + dependentOn }, { "outNetRepro", "reproduce" }, { "outNetDeposit" + produces, "deposit" + produces }, { "outNetConvert", "convert" + primaryConsume + "To" + produces } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); //cc.creature.printNetworks(); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
public void addPlant(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 1, 100, 1000, 700, 3, 10, mutationDeviation, color, false, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "energy", 1000, 800, 1, 900, 10, 100, 1); cc.saveResource(); resourceCreator = cc.addResource(); ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 20, 0, 90, 0, 20, 0); cc.saveResource(); // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); List <string> predatorList = new List <string>() { "cow" }; cc.addDefenseAbilities(predatorList); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>(); // no resource cost // set parameters EcoCreationHelper.setBasicActionParams(cle, "photosynth", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "energy"); cc.saveAction(); ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { "energy", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "energy", 30 }, { "vitamin", 10 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // user opens networks creator for that creature // user adds a network /* * NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); * List<string> resourcesToSense = creatureResources; // sense resources creature can store * List<string> outputActions = new List<string>() * { * "reproduce", * "photosynth", * "eatVitamin", * }; * * EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "SensoryNet", resourcesToSense, outputActions, 0, 0, * ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); * * * // user clicks save on network creator * cc.saveNetwork(); */ // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally List <string> resourcesToSense = creatureResources; // use all output actions again List <string> outputActions = new List <string>() { "reproduce", "photosynth", "eatVitamin", }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetPhoto", "photosynth" }, { "outNetRepro", "reproduce" }, { "outNetEatVit", "eatVitamin" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
/* ************************************************************************************************************************** */ public void addCarnivore(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation, string prey) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 3, 100, 1000, 700, 3, 10, mutationDeviation, color, true, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "energy", 1000, 800, 1, 900, 5, 200, 1); cc.saveResource(); /* * resourceCreator = cc.addResource(); * ecosystemResources = new List<string>(ecosystem.resourceOptions.Keys); * EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 10, 0, 90, 0, 20, 0); * cc.saveResource(); */ // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // TODO create default actions for creature action pool, and example user made action // (should use add an action creator to creature creator) cc.generateMovementActions("energy", .5f); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); // if predator List <string> preyList = new List <string>() { "cow" }; cc.addAttackAbilities(preyList); cc.saveAbilities(); // create action for consuming primary resource /* * ae = cc.addAction(); * ae.setCreator(ActionCreatorType.consumeCreator); * cle = (ConsumeFromLandEditor)ae.getActionCreator(); * // define resource costs * resourceCosts = new Dictionary<string, float>() * { * {"energy", 1}, * }; * // set parameters * EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); * EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); * cc.saveAction(); */ //createAttackAction ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.attackEditor); AttackEditor attackEdit = (AttackEditor)ae.getActionCreator(); Dictionary <string, float> resourceCosts = new Dictionary <string, float> { { "energy", .2f } }; EcoCreationHelper.setBasicActionParams(attackEdit, "eatCow", 1, 10, resourceCosts); EcoCreationHelper.setAttackActionParams(attackEdit, "cow", 1, .9f); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "energy", 200 }, //{"vitamin", 10} }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally List <string> resourcesToSense = creatureResources; // use all output actions again List <string> outputActions = new List <string>() { "reproduce", "eatCow", //"eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight", }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); PhenotypeNetworkEditor phenoNetCreator = (PhenotypeNetworkEditor)cc.addNetwork(NetworkType.phenotype); List <string> phenoOutputActions = new List <string>() { "reproduce", "eatCow", //"eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight", }; EcoCreationHelper.createPhenotypeNet(phenoNetCreator, 0, "phenotypeNet", 0, 0, phenoOutputActions, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // Note: don't call saveNetwork(), call savePhenotypeNetwork() cc.savePhenotypeNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetRepro", "reproduce" }, //{"outNetEatVit", "eatVitamin" }, { "outNetEatCow", "eatCow" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }
/* * create creature, * create and save creature resource, * create creature network, * create network node, * add resource to node, * save creature to founder creatures dict and species dict */ public void addSpecies(string name, ColorChoice color, float mutationDeviation, bool useHiddenNodes, float mutationDeviationFraction, float lowestMutationDeviation, bool loadPrev, int turnTime) { // when user clicks to start species creation process: CreatureEditor cc = ecoCreator.addCreature(); EcoCreationHelper.setCreatureStats(cc, name, 3, turnTime, 1000, 700, 3, 10, mutationDeviation, color, false, mutationDeviationFraction, lowestMutationDeviation, MutationDeviationCoefficientType.exponentialDecay); // add resource for the creature to store ResourceEditor resourceCreator = cc.addResource(); List <string> ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "grass", 100, 80, 1, 90, 10, 20, 1); cc.saveResource(); resourceCreator = cc.addResource(); ecosystemResources = new List <string>(ecosystem.resourceOptions.Keys); EcoCreationHelper.addCreatureResource(resourceCreator, "vitamin", 100, 10, 0, 90, 0, 20, 0); cc.saveResource(); // for future reference List <string> creatureResources = new List <string>(cc.creature.storedResources.Keys); // TODO create default actions for creature action pool, and example user made action // (should use add an action creator to creature creator) cc.generateMovementActions("grass", 5); /* MUST GENERATE ACTIONS AND ADD THEM TO CREATURE'S ACTION POOL BEFORE CREATING OUTPUT NODES FOR THOSE ACTIONS */ // add default abilities for consuming resources cc.addDefaultResourceAbilities(); cc.saveAbilities(); // create action for consuming primary resource ActionEditor ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); ConsumeFromLandEditor cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs Dictionary <string, float> resourceCosts = new Dictionary <string, float>() { { "grass", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatGrass", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "grass"); cc.saveAction(); ae = cc.addAction(); ae.setCreator(ActionCreatorType.consumeCreator); cle = (ConsumeFromLandEditor)ae.getActionCreator(); // define resource costs resourceCosts = new Dictionary <string, float>() { { "grass", 1 }, }; // set parameters EcoCreationHelper.setBasicActionParams(cle, "eatVitamin", 1, 10, resourceCosts); EcoCreationHelper.setConsumeParams(cle, 0, "vitamin"); cc.saveAction(); // create action for reproduction ae = cc.addAction(); ae.setCreator(ActionCreatorType.reproduceCreator); ReproActionEditor rae = (ReproActionEditor)ae.getActionCreator(); // high resource costs for reproduction resourceCosts = new Dictionary <string, float>() { { "grass", 40 }, { "vitamin", 10 } }; EcoCreationHelper.setBasicActionParams(rae, "reproduce", 1, 10, resourceCosts); // no special params to set for reproduction yet cc.saveAction(); // user opens networks creator for that creature // user adds a network NetworkEditor netCreator = cc.addNetwork(NetworkType.regular); List <string> resourcesToSense = creatureResources; // sense resources creature can store List <string> outputActions = new List <string>() { "reproduce", "eatGrass", "eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeSensoryInputNetwork(netCreator, 0, "SensoryNet", resourcesToSense, outputActions, 1, 9, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); // sense internal levels of resources NetworkEditor InternalNetCreator = cc.addNetwork(NetworkType.regular); // sense all creature resources again, this time internally resourcesToSense = creatureResources; // use all output actions again outputActions = new List <string>() { "reproduce", "eatGrass", "eatVitamin", "moveUp", "moveDown", "moveLeft", "moveRight" }; EcoCreationHelper.makeInternalInputNetwork(InternalNetCreator, 0, "internalNet", resourcesToSense, outputActions, 1, 9, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); // user clicks save on network creator cc.saveNetwork(); Dictionary <string, string> actionNameByNetName = new Dictionary <string, string>() { { "outNetUp", "moveUp" }, { "outNetDown", "moveDown" }, { "outNetLeft", "moveLeft" }, { "outNetRight", "moveRight" }, { "outNetEat", "eatGrass" }, { "outNetRepro", "reproduce" }, { "outNetEatVit", "eatVitamin" } }; EcoCreationHelper.createOutputNetworks(cc, 1, actionNameByNetName, 0, 0, ActivationBehaviorTypes.LogisticAB, ActivationBehaviorTypes.LogisticAB); if (loadPrev) { cc.loadWeightsFromFile(); } // adds creature to list of founders ecoCreator.addToFounders(); // saves founders to ecosystem species list ecoCreator.saveFoundersToSpecies(); }