n-queens/src/n_queens.cpp

36 lines
823 B
C++
Raw Normal View History

2023-09-23 22:52:21 -05:00
#include "chess.hpp"
#include "genetic_algorithm.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
unsigned char population[N] = {0};
int selected[N] = {-1};
int generation_count = 0;
int i;
srand(time(NULL));
//basic genetic algorithm skeleton
init_population(population);
print_population(population);
while (generation_count < G) {
do_selection(population, selected);
do_crossover(population, selected);
do_mutation(population);
printf("%4d: ", generation_count);
print_population(population);
for (i = 0; i < N; i++) {
if (population[i] == 0xFF) {
printf("Max fit reached.\n");
return 0;
}
}
generation_count++;
}
return 0;
}