From 72b40aec2addc7b28170ba9364bc0429149b3299 Mon Sep 17 00:00:00 2001 From: majortom6 Date: Sun, 26 Feb 2017 07:07:11 -0600 Subject: -added more detailed mutation function, eventually a normal distrobution will be implemented -added roll function, which takes a float ie (.15) and returns a true that percent of the time --- inc/constants.hpp | 6 ++++-- inc/dna.hpp | 3 +++ inc/functions.hpp | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/constants.hpp b/inc/constants.hpp index 518f2ac..6cb2982 100644 --- a/inc/constants.hpp +++ b/inc/constants.hpp @@ -22,6 +22,8 @@ const int CREATURE_EXP_PREG_TIME = 100; const int CREATURE_EXP_AGE = 1000000; const int CREATURE_SIZE_MAX = 10; const float CREATURE_SPEED = .1; +const float CREATURE_MUTATION_PERCENT = .25; +const float CREATURE_MUTATION_CHANCE = .05; // Resource const int RESOURCE_SIZE_START = 1; @@ -37,8 +39,8 @@ const float CREATURE_SIDES = 4.0; const float RESOURCE_SIDES = 10; // Quadtree -const int MAX_OBJECTS = 5; -const int MAX_LEVELS = 6; +const int MAX_OBJECTS = 10; +const int MAX_LEVELS = 10; // Camera const float MOVE_AMOUNT = .2; diff --git a/inc/dna.hpp b/inc/dna.hpp index d7312f6..b549c27 100644 --- a/inc/dna.hpp +++ b/inc/dna.hpp @@ -2,6 +2,7 @@ #define dna_h #include "constants.hpp" +#include "functions.hpp" class DNA { @@ -20,6 +21,8 @@ class DNA int sizeMax; float speed; + float mutationPercent; + float mutationChance; }; #endif diff --git a/inc/functions.hpp b/inc/functions.hpp index b0ecb65..ef6d555 100644 --- a/inc/functions.hpp +++ b/inc/functions.hpp @@ -1,6 +1,7 @@ #ifndef functions_h #define functions_h +#include #include #include "rectangle.hpp" @@ -17,4 +18,11 @@ static float getRandom(float x){ return (-x + static_cast (rand()) / (static_cast (RAND_MAX/(x-(-x))))); } +static bool roll(float x){ + float y = (float)(rand()%101)/100; + if(x >= y) + return true; + else + return false; +} #endif -- cgit v1.2.3