11#include < cstdint>
2+ #include < iostream>
23#include < stdexcept>
34#include < unistd.h>
45#include " population.h"
78#include " chromosome.h"
89#include " gene.h"
910
11+ using std::cout;
12+ using std::endl;
1013using std::invalid_argument;
1114using Game::Board;
1215using Chromosomes::Chromosome;
@@ -25,7 +28,7 @@ namespace Genetic{
2528 this ->board_h = board_h;
2629 this ->board_w = board_w;
2730
28- this ->generate_food_positions (total_food, board_w, board_h );
31+ this ->generate_food_positions ();
2932 vec2 first_food_pos = this ->food_positions .at (0 );
3033
3134 for (size_t i = 0 ; i < this ->total_ind ; i++){
@@ -44,9 +47,9 @@ namespace Genetic{
4447 }
4548 }
4649
47- void Population::generate_food_positions (uint8_t total, uint8_t w, uint8_t h ){
48- for (size_t _ = 0 ; _ < total ; _++)
49- this ->food_positions .push_back (vec2{(int16_t )random_int (0 , h- 1 ), (int16_t )random_int (0 , w -1 )});
50+ void Population::generate_food_positions (){
51+ for (size_t _ = 0 ; _ < this -> total_food ; _++)
52+ this ->food_positions .push_back (vec2{(int16_t )random_int (0 , this -> board_h - 1 ), (int16_t )random_int (0 , this -> board_w -1 )});
5053 // TODO: refactor this random position to a especialist class or something like this
5154 }
5255
@@ -156,9 +159,13 @@ namespace Genetic{
156159 }
157160
158161 void Population::next_gen (){
162+ cout << " gen: " << this ->gen << endl;
163+ cout << " best fit: " << this ->best_fitness << endl;
164+ cout << " best score: " << this ->best_score << endl << endl;
165+
159166 this ->gen ++;
160167 this ->best_score = 0 ;
161- std::cout << " next gen: " << this -> gen << " \n " ;
168+
162169 Individual** parents = this ->select_parents ();
163170 Chromosome* offspring = this ->generate_offspring (parents[0 ]->player ->get_chromossome (), parents[1 ]->player ->get_chromossome ());
164171 delete parents;
@@ -167,10 +174,9 @@ namespace Genetic{
167174 uint64_t offspring_ch_size = offspring->get_size ();
168175
169176 this ->clear ();
170- std::cout << " no segmentaion fault\n " ;
171177 this ->individuals .clear ();
172178 this ->food_positions .clear ();
173- this ->generate_food_positions (total_food, board_w, board_h );
179+ this ->generate_food_positions ();
174180 vec2 first_food_pos = this ->food_positions .at (0 );
175181
176182 this ->individuals .clear ();
0 commit comments