Ignore:
Timestamp:
09/09/23 15:10:49 (8 months ago)
Author:
Maciej Komosinski
Message:

fH, fB, fL: improved default parameter values, syntax coloring and code logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fL/fL_general.cpp

    r973 r1273  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    99#include <iterator>
    1010
    11 const char *fL_part_names[FL_PART_PROPS_COUNT] = { "dn", "fr", "ing", "as" };
    12 const char *fL_part_fullnames[FL_PART_PROPS_COUNT] = { "details", "friction", "ingestion", "assimilation" };
    13 
    14 const char *fL_joint_names[FL_JOINT_PROPS_COUNT] = { "stif", "rotstif", "stam" };
    15 const char *fL_joint_fullnames[FL_JOINT_PROPS_COUNT] = { "stiffness", "rotation stiffness", "stamina" };
     11const char *fL_part_names[FL_PART_PROPS_COUNT] = { "fr" }; // "dn", "ing", "as" };
     12const char *fL_part_fullnames[FL_PART_PROPS_COUNT] = { "friction" }; // "density", "ingestion", "assimilation" };
     13
     14const char *fL_joint_names[FL_JOINT_PROPS_COUNT] = { "rotstif" }; //"stif", , "stam" }; //see the comment to fH_joint_names in fH_general.cpp
     15const char *fL_joint_fullnames[FL_JOINT_PROPS_COUNT] = { "rotation stiffness" }; //"stiffness", "stamina" };
    1616
    1717#define FIELDSTRUCT fL_Word
     
    502502        fL_Word *stick = new fL_Word(true);
    503503        stick->name = "S";
    504         stick->npar = 8;
     504        stick->npar = FL_PART_PROPS_COUNT + FL_JOINT_PROPS_COUNT + 1; //MacKo 2023-07: was hardcoded "8" but crashed when the number of props in Part and Joint was decreased; I think it should be like it is now (4+3+1 - or another value depending on prop counts)
    505505        for (int i = 0; i < FL_PART_PROPS_COUNT; i++)
    506506        {
    507507                stick->mut.addProperty(NULL, fL_part_names[i], "s", fL_part_fullnames[i], fL_part_fullnames[i], PARAM_CANOMITNAME, 0, -1);
    508508        }
    509 
    510509        for (int i = 0; i < FL_JOINT_PROPS_COUNT; i++)
    511510        {
     
    10961095                                        {
    10971096                                                delete newpart;
    1098                                                 logMessage("fL_Builder", "developModel", LOG_ERROR,
    1099                                                         "Error parsing word parameter");
     1097                                                logMessage("fL_Builder", "developModel", LOG_ERROR, "Error parsing word parameter");
    11001098                                                return 1;
    11011099                                        }
     
    11231121                                                if (word->parevals[FL_PART_PROPS_COUNT + i]->evaluateRPN(jointprop) != 0)
    11241122                                                {
    1125                                                         logMessage("fL_Builder", "developModel", LOG_ERROR,
    1126                                                                 "Error parsing word parameter");
     1123                                                        logMessage("fL_Builder", "developModel", LOG_ERROR, "Error parsing word parameter");
    11271124                                                        delete newjoint;
    11281125                                                        return 1;
     
    11531150                                }
    11541151                                model->addNeuro(neu);
     1152
     1153
     1154                                // MacKo 2023-07: embody (i.e., attach to body) sensors and effectors.
     1155                                // Ad hoc modification; should be reconsidered as it was added without reminding and understanding of the entire logic of the phenotype development and assumptions, and may not be "the best performing" or "the most reasonable" approach. Without this embodiment, genotypes with sensors and effectors not attached to body had warnings (such neurons "could not be initialized") so such genotypes were not accepted when creatwarnfail==1; even with creatwarnfail==0, non-embodied sensor and effector neurons were useless.
     1156                                //printf("Neuron: -------------- %s\n", details.c_str());
     1157                                switch (neu->getClass()->getPreferredLocation())
     1158                                {
     1159                                case NeuroClass::PrefLocation::PREFER_PART: //attach to currstate.currpart
     1160                                        if (currstate.currpart != NULL)
     1161                                                neu->attachToPart(currstate.currpart);
     1162                                        break;
     1163                                case NeuroClass::PrefLocation::PREFER_JOINT: //attach to the last joint incident with currstate.currpart
     1164                                        if (currstate.currpart != NULL)
     1165                                        {
     1166                                                Joint *j = NULL;
     1167                                                for (int i = 0; i < model->getJointCount(); i++)
     1168                                                {
     1169                                                        Joint *jj = model->getJoint(i);
     1170                                                        if (jj->part1 == currstate.currpart || jj->part2 == currstate.currpart)
     1171                                                                j = jj;
     1172                                                }
     1173                                                if (j != NULL)
     1174                                                        neu->attachToJoint(j);
     1175                                        }
     1176                                        break;
     1177                                default:
     1178                                        break;
     1179                                }
     1180
     1181
    11551182                                if (using_mapping) neu->addMapping(IRange(word->begin, word->end));
    11561183                                if (neu->getClass()->getPreferredInputs() != 0)
     
    12511278                        {
    12521279                                connsbuffer[i].second->addInput(connsbuffer[i].second, weight);
    1253                                 if (using_mapping) neu->addMapping(
     1280                                if (using_mapping) connsbuffer[i].second->addMapping( //MacKo 2023-07: changed 'neu' (which is NULL here so crashed) to connsbuffer[i].second (no guarantee this is a proper fix, only inspired by the analogy to the difference in both branches of "if" in the line above)
    12541281                                        IRange((*connsbuffer[i].first)->begin,
    12551282                                                (*connsbuffer[i].first)->end));
Note: See TracChangeset for help on using the changeset viewer.