|
29 | 29 | #include <chrono> |
30 | 30 |
|
31 | 31 |
|
32 | | -template<typename T> |
33 | | -std::string tree_to_string(T const & t) |
| 32 | + |
| 33 | + |
| 34 | +//[ant_move_test |
| 35 | +bool ant_move_test() |
34 | 36 | { |
35 | | - std::ostringstream oss; |
36 | | - oss << gpcxx::simple(t) ; |
37 | | - return oss.str(); |
38 | | -} |
| 37 | + size_t const board_size_x { 32 }; |
| 38 | + size_t const board_size_y { 32 }; |
| 39 | + ant_example::board const the_board { board_size_x , board_size_y }; |
| 40 | + ant_example::ant an_ant { the_board.pos_2d_to_1d( { 0, 0 } ), ant_example::east }; |
| 41 | + |
| 42 | + |
| 43 | + an_ant.move(the_board); |
| 44 | + |
| 45 | + bool position_is_valid = an_ant.pos() == the_board.pos_2d_to_1d( { 1, 0 } ); |
| 46 | + bool step_count_is_valid = an_ant.steps_done() == 1; |
| 47 | + |
| 48 | + |
| 49 | + return position_is_valid && step_count_is_valid ; |
| 50 | +} |
| 51 | +//] |
39 | 52 |
|
40 | 53 |
|
41 | 54 | int main( int argc , char *argv[] ) |
@@ -100,20 +113,6 @@ int main( int argc , char *argv[] ) |
100 | 113 | init_tree_generator( individum ); |
101 | 114 | //] |
102 | 115 |
|
103 | | - /* |
104 | | - auto tree_hasher = [](tree_type const & t){ return std::hash<std::string>{}(tree_to_string(t));}; |
105 | | -
|
106 | | - |
107 | | - std::unordered_set<std::size_t> test ; |
108 | | - |
109 | | - for(tree_type const t : population) |
110 | | - { |
111 | | - test.insert(tree_hasher(t)); |
112 | | - std::cout << tree_hasher(t) << "\t" << tree_to_string(t) << std::endl; |
113 | | - } |
114 | | - std::cout << test.size() << std::endl; |
115 | | - if(true) return 1; |
116 | | - */ |
117 | 116 | //[evolver_definition |
118 | 117 | using evolver_type = gpcxx::static_pipeline< population_type , fitness_type , rng_type > ; |
119 | 118 | evolver_type evolver( number_elite , mutation_rate , crossover_rate , reproduction_rate , rng ); |
@@ -171,7 +170,6 @@ int main( int argc , char *argv[] ) |
171 | 170 | auto fittest_individual_position = std::distance( fitness.begin(), std::min_element( fitness.begin(), fitness.end() ) ); |
172 | 171 | tree_type const & fittest_individual = population[fittest_individual_position]; |
173 | 172 |
|
174 | | -// std::cout << std::hash<std::string>{}(tree_to_string(fittest_individual)) << std::endl; |
175 | 173 | // cat artificial_ant_fittest_individual.dot | dot -Tsvg | display - |
176 | 174 | std::ofstream("artificial_ant_fittest_individual.dot") << gpcxx::graphviz( fittest_individual , false ); |
177 | 175 |
|
|
0 commit comments