[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: DungeonMaker 1.0 released
On Monday 11 June 2001 14:42, you wrote:
<snip>
> The other option would be to have the program that uses the DM library
> automatically rate dungeons, maybe as part of dynamic difficulty balancing,
> but that can be done much easier. A genetic algorithm is a fairly solid
> chunk of code.
!?!
========
class CBot {
private:
char genes[8];
public:
CBot(char *seed) {memcpy(seed, genes, 8);}
void RunAI(void) {
for (i = 0; i < 8; i++) {
if (genes[i]) {
switch(i) {
case 0:
break;
case 1:
// etc
}
}
}
char GetGene(int i) {return genes[i]);
}
class CGenePool {
private:
char genes[8]; // Assume 8 different genes
public:
CGenePool() {Init()};
void Init(void) {
for( int i = 0; i < 8l i++)
genes[i]++;
}
void EndInit(void) {
for (int i = 0; i < 8; i++)
genes[i]--;
}
CBot *NewBot(void) {
CBot *bot;
char seed[8];
for (int i = 0; i < 8; i++) {
if ((genes[i] && (rand()%5 > 3) ||
(rand() % 10 > 7)) {
seed[i] = 1;
} else {seed[i] = 0;}
}
bot = new CBot(seed);
return bot;
}
void KillBot(CBot *bot) {
for Ii = 0; i < 8; i++) {
genes[i] -= bot->GetGene(i);
}
delete bot;
}
};
======
Not really a chunk of code....
That example is for bots, not dungeons, but the principles are the same, and
it is easilly adaptable. Maybe you might want to read my new book when it's
released, Advanced AI Programming Techniques for Games (there's going to be a
better implementation in there, instead of a small section of 1 chapter
explaining it).
> The thing is, I will need an evolutionary engine for my next project
> anyway, and writing it for the DungeonMaker first would help to ensure that
> it is independent of the program that uses it. Is there interest out there
> for a general implementation of the genetic algorithm, or is there a free
> implementation available already?
Feel free to use the code above. It's explained in detail in 'Linux Game
Programming', and is less likely to have typos than the sample above, but the
theories are the same, and should be easy to grasp, even you should
understand it with a little thought :) ...
If anyone at Creature Labs is lurking on this list (I know there is), feel
free to comment...
Nurgle
---------------------------------------------------------------------
To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.dk
For additional commands, e-mail: linuxgames-help@sunsite.dk