I simply decided to make new one now and the text seems to just flow out of my head.
Sooo... I abandonned the SDL-Project for several reasons. They include me working alone, being to lazy to put the written code into a proper class (or classes), writing interfaces, namespaces and all that stuff.
Next time I'll make a plan even if it is just a test. I mean I don't wanna rewrite the code, but when I have it I seem to get to moving the stuff thinking where it should belong without having a real plan.
Another reason is, that I've waited for my bug-report to get some news on. I though it might be fixed or looked at quite soon. And then Source-mods.
But about two weeks ago I decided to start a new little project. Hey, somehow I have to waste the time at school while having programming-lessons.
I don't wanna say I'm übergood or anything, it's just that the language sucks (Java) and our teacher is lame.
The project is genetic algorithm.
It's nothing new or really awesome, but I like it quite much as somewhen (couple of years ago) my motivation (after some failed attempts) to learn C++ was to code something like that.
My plan was to code living beings which will interact with each other and depending on the stats fight, feed, mate and all that stuff.
Genetic Algorithm is the same thing, just very, very simplified:
You have so called chromosomes. They could consist of a simple (const-sized) array of booleans. On creation the booleans are given random values.
All chromosomes have a fitness. The fitness can be determined of the stats, in our case the boolean-array - we could simply use the amount of true-values.
The higher the fitness, the better the chromosome and the higher the chance of mating.
When mating, some children are generated depending on their parents' stats.
The parents die, the children can get mutated with a certain probability and the whole thing starts again.
So, what's the point?
Well, this algorithm can be used for some practical stuff, like finding some optimal solution... wikipedia has a sweet list.
I myself am doing it to not get out of "plain, normal" C++-training and - as already stated - to waste time at school; It can't hurt, can it?
Programming-intern I use arrays for the stats. The type is determined via template-classes. I was using std::vectors at first, but it cannot give your references when using std::vector
so I made a preprocessor-define for switching.
I use function-pointers for the initializers (like, how to determine the fitness, the initial value, ...).
I am gonna move some stuff into interfaces so you can (like any of you would wanna modify the code LOL) easily adapt the code.
And I just finished the mating and a mutating-stub. There is a little bug I worked around with a hack: I use operator+ for mating - not giving back a referance but a new object, so you could use it like
a = box+box;
box is a chromosome_box
and simply a storage for multiple chromosomes. I don't simply use a vector or array for some neat stuff.
So, back to the bug: After box+box gives back a chromosome
, the function holding a (in my case main) calls the destructor on a.
What. The. Fuck.
I don't know how to resolve it, but chromosome
I was considering to use Boost for this project. But I'm probably too lazy to get in touch with it. Boost is amazing though - and you don't even have to build it except for 4-5 features or summin.
Well, I won't give you a demo (yet) of this genetic algorithm thing without a name because it simply gives out 10 chromosomes (with 8 stats/bools each), mutates, oiutput them, mates two, outputs the child, mutates child, outputs child, awating keypress to exit.
And the code does not use the said interfaces yet. So a no here, too. I will probably make it open source as I don't care quite much and maybe two or three will even look at the code (well... one can dream...).
But something to look forward to: I'll include my "base-header" with it. It will make it available to easily use UNICODE with one preprocessor-directive (also uses wstrings, wchars, win- and woutputs) and adapts to the system (eg. 32-bit systems will typedef uint_t as unsigned int and float_t as float, 64-bit systems will typedef uint_t as unsigned long long and float_t as double).
Also some other neat things, put these are the main features.
Right now, only Windows and MSVS is supported (others will probably output an error when compiling), but it is very easy adaptable.
I wonder if anybody is gonna care about the post I just wrote.
So, please leave a comment if you like, dislike, getting interested or whatever on this project.