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