Esempio n. 1
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();
    }