37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
#include "chess.hpp"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
int main(int argc, char* argv[]) {
|
|
InitializeGenerator();
|
|
GeneticRules genetics;
|
|
if (argc == 2) { genetics.boardSize = atoi(argv[1]); }
|
|
std::cout << "argc: " << argc << std::endl;
|
|
std::vector<Individual> population(genetics.populationSize, genetics.boardSize);
|
|
for (int i = 0; i < genetics.populationSize; ++i) { population[i].Init(genetics.boardSize); }
|
|
std::vector<int> selected(genetics.populationSize, -1);
|
|
int generationCount = 0;
|
|
std::cout << generationCount << ':' << std::endl;
|
|
PrintPopulation(population);
|
|
|
|
while (generationCount < genetics.generationLimit) {
|
|
Selection(population, selected);
|
|
Crossover(population, selected, genetics);
|
|
Mutation(population, genetics);
|
|
std::cout << generationCount << ':' << std::endl;
|
|
PrintPopulation(population);
|
|
for (auto i : population) {
|
|
if (i.GetFitness() == genetics.boardSize) {
|
|
std::cout << "Max fit reached." << std::endl;
|
|
return 0;
|
|
}
|
|
}
|
|
++generationCount;
|
|
}
|
|
if (generationCount == genetics.generationLimit) {
|
|
std::cout << "Generation limit reached." << std::endl;
|
|
}
|
|
return 0;
|
|
}
|