Added getting fitness and lowered board size
This commit is contained in:
parent
99e99d9233
commit
b6da05660f
@ -16,13 +16,11 @@ int GenerateRandomNumber(int generationLimit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GeneticDefaults::GeneticDefaults(void) {
|
GeneticDefaults::GeneticDefaults(void) {
|
||||||
size = 8;
|
size = 4;
|
||||||
length = 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneticDefaults::GeneticDefaults(unsigned int size, unsigned int length) {
|
GeneticDefaults::GeneticDefaults(unsigned int size) {
|
||||||
this->size = size;
|
this->size = size;
|
||||||
this->length = length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneticChess::GeneticChess(void) {
|
GeneticChess::GeneticChess(void) {
|
||||||
@ -51,10 +49,11 @@ void GeneticChess::Print(void) {
|
|||||||
|
|
||||||
// Gets the fitness of the population
|
// Gets the fitness of the population
|
||||||
unsigned int GeneticChess::GetFitness(void) {
|
unsigned int GeneticChess::GetFitness(void) {
|
||||||
int fitness = 0;
|
unsigned int fitness = 0;
|
||||||
for (int i : board) {
|
for (unsigned int i : board) {
|
||||||
if (!IsQueenThreatened(i)) { fitness++; }
|
if (!IsQueenThreatened(i)) { fitness++; }
|
||||||
}
|
}
|
||||||
|
std::cout << fitness << std::endl;
|
||||||
return fitness;
|
return fitness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,8 @@ struct GeneticDefaults {
|
|||||||
const float kProbabilityMutation = 0.001; //mutation probability (typical val.)
|
const float kProbabilityMutation = 0.001; //mutation probability (typical val.)
|
||||||
const unsigned int generationLimit = 10000; //number of generations (something huge)
|
const unsigned int generationLimit = 10000; //number of generations (something huge)
|
||||||
unsigned int size; //population size (change to something even)
|
unsigned int size; //population size (change to something even)
|
||||||
unsigned int length; //string length (don't change)
|
|
||||||
GeneticDefaults(void);
|
GeneticDefaults(void);
|
||||||
GeneticDefaults(unsigned int size, unsigned int length); //custom generation sizes
|
GeneticDefaults(unsigned int size); //custom generation sizes
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeneticChess {
|
class GeneticChess {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
int main(){
|
int main(){
|
||||||
GeneticChess population;
|
GeneticChess population;
|
||||||
population.Print();
|
population.Print();
|
||||||
|
population.GetFitness();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
unsigned char population[N] = {0};
|
unsigned char population[N] = {0};
|
||||||
|
Loading…
Reference in New Issue
Block a user