예제 #1
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();
    }