Skip to content

Commit

Permalink
tweaked some parameters and remove debugging console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed Oct 25, 2023
1 parent 94d6832 commit a8c8a8a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 36 deletions.
6 changes: 0 additions & 6 deletions src/bird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ void Birds::draw(sf::RenderTarget &target, sf::RenderStates states) const {
for (auto &bird: collection) {
if (!bird.dead) {
target.draw(bird, states);

// a note to self : for debugging purposes / remove later
sf::CircleShape test(5.f, 3);
test.setFillColor(sf::Color::Yellow);
test.setPosition(Bird::target_gap);
target.draw(test, states);
}
}
}
2 changes: 1 addition & 1 deletion src/bird.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct Bird : public sf::RectangleShape {
};

struct Birds : public sf::Drawable {
static constexpr size_t INITIAL_POPULATION = 60;
static constexpr size_t INITIAL_POPULATION = 512;

std::vector<Bird> collection;
size_t population;
Expand Down
4 changes: 2 additions & 2 deletions src/ffnn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct FFNN {
static constexpr size_t HIDDEN = 5;
static constexpr size_t OUTPUT = 1;

/// \brief 20% chance to mutate a weight.
static constexpr size_t MUTATION_CHANCE_THRESHOLD = 20;
/// \brief 30% chance to mutate a weight.
static constexpr size_t MUTATION_CHANCE_THRESHOLD = 30;

/// \brief 50% chance to choose from parentA's weight.
static constexpr size_t WEIGHT_SELECTION_CHANCE_THRESHOLD = 50;
Expand Down
26 changes: 0 additions & 26 deletions src/genetic_algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,7 @@ void GeneticAlgorithm::rank_fitness(Birds &birds) {
bird.fitness = base_gap_close_fitness + bird.time_lived * 20.f;
}

// sort birds from greatest to least fitness.
std::cout << "unsorted fitness :\n";
for (auto &bird: birds.collection) {
std::cout << " bird.fitness = " << bird.fitness << '\n';
}
std::cout << "\n";

std::sort(birds.collection.begin(), birds.collection.end(), [](Bird &a, Bird &b) { return a.fitness > b.fitness; });

std::cout << "sorted fitness :\n";
for (auto &bird: birds.collection) {
std::cout << " bird.fitness = " << bird.fitness << '\n';
}
std::cout << "\n\n";
}

void GeneticAlgorithm::apply_mutations(Birds &birds) {
Expand All @@ -72,21 +59,8 @@ void GeneticAlgorithm::apply_mutations(Birds &birds) {
birds.collection[i].apply_random_mutation();
}

// randomly select mutated bad birds to keep.
std::cout << "sorted bad bird fitness :\n";
for (auto &bird: birds.collection) {
std::cout << " bird.fitness = " << bird.fitness << '\n';
}
std::cout << "\n";

std::shuffle(birds.collection.begin() + fit_size, birds.collection.end(), FFNN::engine);

std::cout << "shuffled bad bird fitness :\n";
for (auto &bird: birds.collection) {
std::cout << " bird.fitness = " << bird.fitness << '\n';
}
std::cout << "\n";

// breed the good birds to fill the missing population.
constexpr size_t unfit_size = (Birds::INITIAL_POPULATION - fit_size) * MUTATION_KEEP_BAD;
constexpr size_t spliced_size = fit_size + unfit_size;
Expand Down
2 changes: 1 addition & 1 deletion src/pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct PipePair : public sf::Drawable {
static constexpr float GAP = 110.f;

/// top pipe's minimum height.
static constexpr float MIN_HEIGHT = static_cast<float>(WINDOW_HEIGHT) / 24.f;
static constexpr float MIN_HEIGHT = static_cast<float>(WINDOW_HEIGHT) / 40.f;

/// top pipe's maximum height.
static constexpr float MAX_HEIGHT = static_cast<float>(WINDOW_HEIGHT) - MIN_HEIGHT - GAP;
Expand Down

0 comments on commit a8c8a8a

Please sign in to comment.