/// <summary> /// Create a template of a PhenotypeNetwork, to use on sensing adjacent creatures. /// </summary> /// <param name="phenoNetEditor">Wrapper for PhenotypeNetwork.</param> /// <param name="layer">Layer in which network exists (probably 0).</param> /// <param name="name">Name of network.</param> /// <param name="hiddenNodesPerLayer">Nodes per hidden layer.</param> /// <param name="layersHiddenNodes">Number of hidden layers in the network.</param> /// <param name="outputActionNames">Names of output actions, whose output networks will be connected to this network.</param> /// <param name="hiddenNodeActiv">The type of activation function used by the hidden nodes.</param> /// <param name="outputNodeActiv">The type of activation function used by the output nodes. Note: the output of this function should be in the range [0,1].</param> public static void createPhenotypeNet(PhenotypeNetworkEditor phenoNetEditor, int layer, string name, int hiddenNodesPerLayer, int layersHiddenNodes, List <string> outputActionNames, ActivationBehaviorTypes hiddenNodeActiv, ActivationBehaviorTypes outputNodeActiv) { phenoNetEditor.setInLayer(layer); // called by default with index of layer user clicked phenoNetEditor.setName(name); phenoNetEditor.createInputNodes(); // set index of output layer based on hidden nodes int outputLayer = layersHiddenNodes + 1; // for every hidden layer for (int i = 0; i < layersHiddenNodes; i++) { phenoNetEditor.insertNewLayer(i + 1); // add every node in that layer for (int j = 0; j < hiddenNodesPerLayer; j++) { makeHiddenNode(phenoNetEditor, hiddenNodeActiv, i + 1); } } for (int i = 0; i < outputActionNames.Count; i++) { makeOutputNode(phenoNetEditor, outputNodeActiv, outputActionNames[i], outputLayer); } }
/* * 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 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(); }