Ignore:
Timestamp:
03/29/18 22:52:36 (6 years ago)
Author:
Maciej Komosinski
Message:

More strict parsing of the repetition counter; bug fixes; improved docs [refs #62]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/oper_f4.cpp

    r760 r767  
    2020#define F4_MODIFIERS_VISUAL "" //not supported in f4
    2121#define F4_MODIFIERS_RARE "EeWwAaSs" //expdef would need to handle these properly/specifically to ensure reasonable behavior, and hardly any expdef does. Modifying initial energy of a creature as a result of its genes (Ee) is in general not a good idea. Weight (Ww) works only in water, and in water sinking/going up should usually be caused by real "intentional" activity of a creature, not by its inherited weight. For assimilation (Aa), there is a dedicated parameter in CreaturesGroup. Stamina (Ss) is no longer needed as destructive collisions are not supported, and even if they were, some expdef would need to impose reasonable restrictions on the value of this parameter (e.g. similar to normalizeBiol4()) so there is some cost associated with it, and the specific consequences of destructions should be defined as needed.
    22 #define F4_MODIFIERS "LlRrCcQqFfMmIi" F4_MODIFIERS_RARE F4_MODIFIERS_VISUAL
     22#define F4_MODIFIERS ",LlRrCcQqFfMmIi" F4_MODIFIERS_RARE F4_MODIFIERS_VISUAL
    2323const char *Geno_f4::all_modifiers = F4_MODIFIERS;
     24
     25// codes that can be changed (apart from being added/deleted)
     26#define MUT_CHAN_CODES "<[#"
     27#define REP_MAXCOUNT 19
    2428
    2529#define FIELDSTRUCT Geno_f4
     
    134138        // ! the genotype is g->child (not g) !
    135139
    136         // codes that can be changed (apart being added/deleted)
    137 #define MUT_CHAN_CODES "<[#"
    138 #define ADD_SIMPLE_CODES ",XlLcCrRaAiIsSmMfFwWeEN@|"
    139 #define REP_MAXCOUNT 19
    140 
    141140        // do the mutation
    142141        // pick a random node
     
    176175                                else
    177176                                {
    178                                         f4_node *n4 = new f4_node(rndclass->getName().c_str(), n2, n2->pos); //TODO move this above
     177                                        f4_node *n4 = new f4_node(rndclass->getName().c_str(), n2, n2->pos);
    179178                                        if (rndclass->getPreferredInputs() != 0)
    180179                                        {
     
    280279                        // choose a simple node from ADD_SIMPLE_CODES
    281280                        n1->parent->removeChild(n1);
    282                         f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos);
     281                        //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos);
     282                        int modifierid = GenoOperators::getRandomChar(all_modifiers, excluded_modifiers.c_str());
     283                        f4_node *n2 = new f4_node(all_modifiers[modifierid], n1->parent, n1->parent->pos);
    283284                        n2->addChild(n1);
    284285                        n1->parent = n2;
     
    717718}
    718719
    719 
    720 
    721720uint32_t Geno_f4::style(const char *g, int pos)
    722721{
     
    727726#define STYL4CAT_DIGIT "0123456789."
    728727#define STYL4CAT_REST "XN<># "
    729         if (!strchr(STYL4CAT_MODIFIC STYL4CAT_NEUMOD STYL4CAT_DIGIT STYL4CAT_REST, ch))
     728
     729        if (!isalpha(ch) && !isdigit(ch) &&  !strchr("<>-+[]:,.@|#*/=!\t",ch)) {
    730730                return GENSTYLE_CS(0, GENSTYLE_INVALID);
     731        }
    731732        uint32_t style = GENSTYLE_CS(0, GENSTYLE_STRIKEOUT); //default, should be changed below
    732733        if (strchr("X ", ch))              style = GENSTYLE_CS(0, GENSTYLE_NONE);
     
    737738        if (strchr(STYL4CAT_MODIFIC, ch))   style = GENSTYLE_RGBS(100, 100, 100, GENSTYLE_NONE);
    738739        if (strchr(STYL4CAT_NEUMOD, ch))    style = GENSTYLE_RGBS(0, 150, 0, GENSTYLE_NONE);
     740        if (isalpha(ch)) {
     741                int p = pos;
     742                while (p > 0) {
     743                        p--;
     744                        if (!isalpha(g[p])) {
     745                                if (isupper(g[p+1]) && (g[p] == ':' || g[p] == '[')) { // name of neuron class
     746                                        style = GENSTYLE_RGBS(150,0,150,GENSTYLE_ITALIC);
     747                                }
     748                                else { // property
     749                                        style = GENSTYLE_RGBS(255,140,0,GENSTYLE_BOLD);
     750                                }
     751                        }
     752                }
     753        }
    739754        return style;
    740755}
Note: See TracChangeset for help on using the changeset viewer.