Ignore:
Timestamp:
05/18/23 14:19:34 (12 months ago)
Author:
Maciej Komosinski
Message:

Changed the default behavior of modifier genes in f1 and f4 to GenePropsOps_New05: the coefficient of change is set to 0.5 for all properties and for both increase and decrease, which ensures an equal distribution of target property values with a relatively fast convergence to minimal and maximal values; the four "biological" properties are no longer aggregated and normalized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geneprops.h

    r1039 r1242  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1919
    2020
     21class GenePropsOp
     22{
     23public:
     24        virtual ~GenePropsOp() {}
     25        virtual double increase(double value) const = 0;
     26        virtual double decrease(double value) const = 0;
     27        void apply(double &value, char modif) const;
     28};
    2129
     30class GenePropsOp_Old : public GenePropsOp
     31{
     32        double minvalue, maxvalue, defvalue, change, revchange;
     33public:
     34        GenePropsOp_Old(double minvalue, double maxvalue, double defvalue, double change, double revchange = -1);
     35        double increase(double value) const;
     36        double decrease(double value) const;
     37        friend class GenePropsOps_New05;
     38};
     39
     40class GenePropsOp_NormalizedAndScaled : public GenePropsOp
     41{
     42        GenePropsOp_Old normalized;
     43public:
     44        GenePropsOp_NormalizedAndScaled(double change) :normalized(-1, 1, 0, change) {}
     45        virtual double scale(double value) const { return value; }
     46        virtual double scaleInv(double value) const { return value; }
     47        double increase(double value) const { return scale(normalized.increase(scaleInv(value))); }
     48        double decrease(double value) const { return scale(normalized.decrease(scaleInv(value))); }
     49};
     50
     51class GenePropsOp_Exponential : public GenePropsOp_NormalizedAndScaled
     52{
     53        double a, b, c;
     54        double log_a;
     55        bool linear;
     56public:
     57        GenePropsOp_Exponential(double minvalue, double maxvalue, double defvalue, double change = 0.5);
     58        double scale(double) const;
     59        double scaleInv(double) const;
     60};
     61
     62class GenePropsOps
     63{
     64public:
     65        ~GenePropsOps();
     66
     67        GenePropsOp* length;
     68        GenePropsOp* curvedness;
     69        GenePropsOp* weight;
     70        GenePropsOp* friction;
     71        GenePropsOp* muscle_power;
     72        GenePropsOp* assimilation;
     73        GenePropsOp* stamina;
     74        GenePropsOp* ingestion;
     75        GenePropsOp* twist;
     76        GenePropsOp* energy;
     77        GenePropsOp* cred, *cgreen, *cblue;
     78        bool use_normalizebiol4;
     79};
     80
     81class GenePropsOps_Old : public GenePropsOps
     82{
     83public:
     84        GenePropsOps_Old();
     85};
     86
     87class GenePropsOps_New05 : public GenePropsOps_Old
     88{
     89public:
     90        GenePropsOps_New05();
     91};
     92
     93class GenePropsOps_Exponential : public GenePropsOps
     94{
     95public:
     96        GenePropsOps_Exponential();
     97};
    2298
    2399/**
     
    29105 * parents (prop) modified with the prop.propagateAlong() method.
    30106 * "Biological" properties (assimilation, stamina, muscle strength and
    31  * ingestion) should be normalized after modification with normalizeBiol4().
     107 * ingestion) can be normalized after modification with normalizeBiol4().
    32108 */
    33109struct GeneProps
     
    55131
    56132        static GeneProps standard_values;
     133        static GenePropsOps* standard_ops;
     134        static GenePropsOps* getStandardOps();
    57135
    58136        /**
     
    62140
    63141        /**
    64          * Normalizes biological properties (muscle_power,
    65          * assimilation, stamina, and ingestion). This method is called in
    66          * executeModifier() when any of the biological properties is modified. All values
    67          * of those properties sum up to 1.
     142         * Normalizes biological properties (muscle_power, assimilation, stamina, and ingestion).
     143         * This method is called in executeModifier() when any of the biological properties is modified
     144         * and \a use_normalizebiol4 is true. All values of those properties sum up to 1.
    68145         */
    69146        void normalizeBiol4();
     
    75152         * @return 0 if the provided character was property modifier, -1 otherwise
    76153         */
    77         int executeModifier(char modif);
     154        int executeModifier(char modif, GenePropsOps* ops = NULL);
     155        int executeModifier_Legacy(char modif);
    78156
    79157        /**
Note: See TracChangeset for help on using the changeset viewer.