Exemple #1
0
    /// <summary>
    /// load the creature editor menu using the ecosystem editor
    /// </summary>
    public void loadCreatMenu(EcosystemEditor ec)
    {
        ecoCreator      = ec;
        creatureCreator = ec.creatureCreator;
        uIParent.SetActive(true);

        //TODO: load information into menu from prev created creature
    }
Exemple #2
0
 public EditorSelectionManager(CreatureEditor editor,
                               Transform selectionArea,
                               Texture2D mouseDeleteTexture)
 {
     this.editor             = editor;
     this.selectionArea      = selectionArea;
     this.mouseDeleteTexture = mouseDeleteTexture;
     selectionArea.gameObject.SetActive(false);
 }
Exemple #3
0
    /// <summary>
    /// Create a series of output network for different actions, but otherwise identical.
    /// </summary>
    /// <param name="ce">Creature wrapper object.</param>
    /// <param name="netLayer">Layer in which the output networks belong (probably last layer).</param>
    /// <param name="names">Names of output networks to be made (could be any name) and their associated actions (must use exact action names).</param>
    /// <param name="hiddenLayerNum">Number of hidden layers in the network.</param>
    /// <param name="nodesPerLayer">Nodes per hidden layer.</param>
    /// <param name="hiddenActiv">The type of activation function used by the hidden nodes.</param>
    /// <param name="outputActiv">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 createOutputNetworks(CreatureEditor ce, int netLayer, Dictionary <string, string> names, int hiddenLayerNum, int nodesPerLayer,
                                            ActivationBehaviorTypes hiddenActiv, ActivationBehaviorTypes outputActiv)
    {
        OutputNetworkEditor outNetCreator;

        foreach (string netName in names.Keys)
        {
            outNetCreator = (OutputNetworkEditor)ce.addNetwork(NetworkType.output);
            createOutputNetwork(outNetCreator, names[netName], netLayer, netName, ce.creature.actionPool[names[netName]], hiddenLayerNum, nodesPerLayer,
                                hiddenActiv, outputActiv, ce.creature.networks);
            // user clicks save on creature creator
            ce.saveNetwork();
        }
    }
Exemple #4
0
 /// <summary>
 /// Set basic parameters for a creature type.
 /// </summary>
 /// <param name="ce">Creature wrapper.</param>
 /// <param name="name">Name of creature.</param>
 /// <param name="phenotype">Phenotype of creature (potentially sensed by other creatures).</param>
 /// <param name="turnTime">The amount of time given for a creature's turn. It's recommended to use the same turn time for all creatures.</param>
 /// <param name="maxHealth">The maximum possible health a creature can achieve.</param>
 /// <param name="initialHealth">The initial health of the creature when a population is created. Note that a child inherits the health of it's parent, and doesn't use this value.</param>
 /// <param name="actionClearInterval">The action queue is cleared at intervals of this number of steps.</param>
 /// <param name="actionClearSize">The size that the action queue must reach before it is cleared.</param>
 /// <param name="mutationDeviation">The initial amount of mutation that occurs with reproduction.</param>
 /// <param name="color">The color of the creature.</param>
 /// <param name="usePhenoNet">Chose wether creature should sense the phenotypes of it's neighbors. If so, you must create a phenotype network template.</param>
 /// <param name="mutationDeviationFraction">The number that the mutation deviation is multiplied by each time a creature reproduces. This new deviation is passed on to the child. This can be used to slowy reduce the amount of variability in the population.</param>
 /// <param name="lowestMutationDeviation">The lowest value that the mutation deviation can reach, even with the mutationDeviationFraction.</param>
 /// <param name="mutationType">The type of mutation being used.</param>
 public static void setCreatureStats(CreatureEditor ce, string name, int phenotype, float turnTime, float maxHealth, float initialHealth,
                                     int actionClearInterval, int actionClearSize, float mutationDeviation, ColorChoice color, bool usePhenoNet,
                                     float mutationDeviationFraction, float lowestMutationDeviation, MutationDeviationCoefficientType mutationType)
 {
     ce.setSpecies(name);
     ce.setPhenotype(phenotype);
     ce.setTurnTime(turnTime);
     ce.setMaxHealth(maxHealth);
     ce.setInitialHealth(initialHealth);
     ce.setActionClearInterval(actionClearInterval);
     ce.setActionClearSize(actionClearSize);
     ce.setMutationStandardDeviation(mutationDeviation);
     ce.setColor(color);
     ce.setUsePhenotypeNet(usePhenoNet);
     ce.setAnnealMutationFraction(mutationDeviationFraction);
     ce.setBaseMutationDeviation(lowestMutationDeviation);
     ce.setMutationCoeffType(mutationType);
 }
Exemple #5
0
    /*
     * 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();
    }
Exemple #6
0
 // user picks layer to create node in, initializing a node creator
 public ActionEditor(CreatureEditor cc)
 {
     creatureCreator = cc;
 }
Exemple #7
0
    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();
    }
Exemple #8
0
    /*       **************************************************************************************************************************       */



    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();
    }
Exemple #9
0
    /*
     * 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();
    }
Exemple #10
0
 public OutputNetworkEditor(OutputNetwork net, CreatureEditor parentCreatureCreator) : base(net, parentCreatureCreator)
 {
 }
Exemple #11
0
 public PhenotypeNetworkEditor(PhenotypeNetwork net, CreatureEditor parentCreatureCreator) : base(net, parentCreatureCreator)
 {
 }
 /// <summary>
 /// Creature new creature
 /// </summary>
 public CreatureEditor addCreature()
 {
     creatureCreator = new CreatureEditor(new Creature(ecosystem.abilityPointsPerCreature), this);
     return(creatureCreator);
 }
 public NetworkEditor(Network net, CreatureEditor parentCreatureCreator)
 {
     network = net;
     this.parentCreatureCreator = parentCreatureCreator;
     initializeNetwork();
 }