- Timestamp:
- 03/29/24 23:30:34 (8 months ago)
- Location:
- cpp
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_math.cpp
r1280 r1298 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 3Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #include <sstream> 9 9 #include <algorithm> // std::min() 10 #include <common/log.h> 11 12 13 unsigned int rndUint(int limit_exclusive) 14 { 15 if (limit_exclusive < 0) 16 { 17 logPrintf("", "rndUint", LOG_ERROR, "rndUint(negative: %d)", limit_exclusive); 18 return 0; 19 } 20 else return rndUint((unsigned int)limit_exclusive); 21 } 22 10 23 11 24 RandomGenerator &rndGetInstance() … … 125 138 #include <fenv.h> 126 139 140 #ifdef __CYGWIN__ //since my cygwin update in 2024 (g++ (GCC) 11.4.0), these two are no longer found: 141 #define feenableexcept(x) 142 #define fedisableexcept(x) 143 #endif 144 127 145 namespace fpExcept 128 146 { … … 203 221 204 222 #endif 223 -
cpp/common/nonstd_math.h
r1275 r1298 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #ifdef _MSC_VER 10 10 #define _USE_MATH_DEFINES //after this is defined, the next #include <math.h> or <cmath> will define M_PI etc. 11 #include <math.h> // w vc2008 dzia�a�o tu <cmath>, ale w vc2010 juz nie bo "co�" (jaki� inny .h stl'a?) includuje wcze�niej <cmath> bez _USE_MATH_DEFINES, a <cmath> includuje <math.h> (ale tylko raz bo ma "include guards" jak kazdy.h)11 #include <math.h> //in vc2008, <cmath> worked here, but no longer in vc2010 because "something" (some other .h from stl?) earlier includes <cmath> without _USE_MATH_DEFINES, and <cmath> includes <math.h> (just once because it has "include guards" like any other .h) 12 12 #include <float.h> 13 13 //#define isnan(x) _isnan(x) //since 2014 we use std::isnan() 14 14 #define finite(x) _finite(x) 15 #else // m.in. __BORLANDC__15 #else //e.g. __BORLANDC__ 16 16 #include <math.h> 17 17 #endif … … 25 25 inline double rndDouble(double limit_exclusive) { return rndGetInstance().getDouble() * limit_exclusive; } 26 26 inline unsigned int rndUint(unsigned int limit_exclusive) { return (unsigned int)(rndGetInstance().getDouble() * limit_exclusive); } //returns random from 0..limit_exclusive-1 27 inline unsigned int rndUint(size_t limit_exclusive) {return rndUint((unsigned int)limit_exclusive);} //just an overload with size_t argument 28 unsigned int rndUint(int limit_exclusive); //just an overload with int argument 27 29 inline void rndSetSeed(unsigned int seed) { rndGetInstance().setSeed(seed); } 28 30 inline unsigned int rndRandomizeSeed() { return rndGetInstance().randomize(); } -
cpp/frams/genetics/f4/f4_oper.cpp
r1274 r1298 253 253 return GENOPER_OPFAIL; 254 254 255 node_mutated = candidate_nodes[rndUint( (unsigned int)candidate_nodes.size())];255 node_mutated = candidate_nodes[rndUint(candidate_nodes.size())]; 256 256 f4_Node *node_mutated_parent = node_mutated->parent; 257 257 -
cpp/frams/genetics/fB/fB_oper.cpp
r1273 r1298 252 252 { 253 253 std::list<SString> tokenized = tokenizeSequence(line); 254 int rndid = rndUint( (int)tokenized.size()); // select random letter from genotype254 int rndid = rndUint(tokenized.size()); // select random letter from genotype 255 255 // increment/decrement character - when overflow happens, this method 256 256 // uses the "reflect" approach … … 291 291 std::list<SString> tokenized = tokenizeSequence(line); 292 292 std::list<SString>::iterator it = tokenized.begin(); 293 int rndid = rndUint( (int)tokenized.size()); // select random insertion point293 int rndid = rndUint(tokenized.size()); // select random insertion point 294 294 std::advance(it, rndid); 295 295 NeuroClass *cls = getRandomNeuroClass(Model::SHAPETYPE_BALL_AND_STICK); … … 312 312 chg = 1.0 / line.length(); 313 313 std::list<SString> tokenized = tokenizeSequence(line); 314 int rndid = rndUint( (int)tokenized.size()); // select random insertion point314 int rndid = rndUint(tokenized.size()); // select random insertion point 315 315 std::list<SString>::iterator it = tokenized.begin(); 316 316 std::advance(it, rndid); … … 326 326 std::list<SString> tokenized = tokenizeSequence(line); 327 327 std::list<SString>::iterator it = tokenized.begin(); 328 int rndid = rndUint( (int)tokenized.size()); // select random deletion point328 int rndid = rndUint(tokenized.size()); // select random deletion point 329 329 std::advance(it, rndid); 330 330 tokenized.erase(it); … … 348 348 for (int i = 0; i < 4; i++) 349 349 { 350 cuts[i] = rndUint( (int)tokenized.size());350 cuts[i] = rndUint(tokenized.size()); 351 351 } 352 352 std::sort(cuts.begin(), cuts.end()); -
cpp/frams/genetics/fF/fF_oper.cpp
r1280 r1298 49 49 par.load(gene); 50 50 static const int propsToMutate[] = fF_PROPS_TO_MUTATE; 51 int which = rndUint( (unsigned int)std::size(propsToMutate));51 int which = rndUint(std::size(propsToMutate)); 52 52 bool mutated_ok = GenoOperators::mutatePropertyNaive(par.param, propsToMutate[which]); 53 53 if (mutated_ok) -
cpp/frams/genetics/fL/fL_oper.cpp
r1273 r1298 181 181 else 182 182 { 183 int rid = rndUint( (unsigned int)creature->rules.size());183 int rid = rndUint(creature->rules.size()); 184 184 list = &creature->rules[rid]->objsucc; 185 185 numparams = creature->rules[rid]->objpred->npar; … … 313 313 if (creature->rules.size() > 0) 314 314 { 315 int ruleid = rndUint( (unsigned int)creature->rules.size());315 int ruleid = rndUint(creature->rules.size()); 316 316 if (!creature->rules[ruleid]->condeval) 317 317 { … … 350 350 if (wordswithnorules.size() > 0) 351 351 { 352 int predid = rndUint( (unsigned int)wordswithnorules.size());352 int predid = rndUint(wordswithnorules.size()); 353 353 fL_Rule *newrule = new fL_Rule(0, 0); 354 354 fL_Word *pred = new fL_Word(); … … 362 362 else if (creature->rules.size() > 0) 363 363 { 364 int ruleid = rndUint( (unsigned int)creature->rules.size());364 int ruleid = rndUint(creature->rules.size()); 365 365 fL_Rule *newrule = new fL_Rule(0, 0); 366 366 fL_Word *pred = new fL_Word(); … … 465 465 else 466 466 { 467 int rndid = rndUint( (unsigned int)list->size());467 int rndid = rndUint(list->size()); 468 468 std::list<fL_Word *>::iterator it = list->begin(); 469 469 std::advance(it, rndid); … … 492 492 int tmp = 0; 493 493 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 494 int rndid = rndUint( (unsigned int)list->size());494 int rndid = rndUint(list->size()); 495 495 std::list<fL_Word *>::iterator it = list->begin(); 496 496 std::advance(it, rndid); … … 541 541 int tmp = 0; 542 542 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 543 int rndid = rndUint( (unsigned int)list->size());543 int rndid = rndUint(list->size()); 544 544 std::list<fL_Word *>::iterator selectedword = list->begin(); 545 545 std::advance(selectedword, rndid); … … 555 555 int numpars = 0; 556 556 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 557 int rndid = rndUint( (unsigned int)list->size());557 int rndid = rndUint(list->size()); 558 558 std::list<fL_Word *>::iterator it = list->begin(); 559 559 std::advance(it, rndid); … … 587 587 if (available.size() > 0) 588 588 { 589 int newnameid = rndUint( (unsigned int)available.size());589 int newnameid = rndUint(available.size()); 590 590 (*selectedword)->name = available[newnameid]->name; 591 591 } … … 762 762 for (int i = 0; i < numselrules; i++) 763 763 { 764 int rulid = rndUint( (unsigned int)from->rules.size());764 int rulid = rndUint(from->rules.size()); 765 765 fL_Rule *rul = from->rules[rulid]; 766 766 fL_Rule *newrule = new fL_Rule(0, 0);
Note: See TracChangeset
for help on using the changeset viewer.