Skip to content

Commit

Permalink
change uniform_int_distribution type from unsigned char to size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed Oct 25, 2023
1 parent 1bba37b commit 24022cc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/bird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

sf::Vector2f Bird::target_gap = {0.f, 0.f};

std::mt19937 Bird::color_engine(std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_int_distribution<unsigned char> Bird::color_rng(0, 255);
std::mt19937 Bird::color_engine(std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_int_distribution<size_t> Bird::color_rng(0, 255);

Bird::Bird()
: sf::RectangleShape({SIZE, SIZE}), time_lived(0.f), speed(JUMP_SPEED * 0.6f), fitness(0.f), dead(false),
Expand Down
4 changes: 2 additions & 2 deletions src/bird.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct Bird : public sf::RectangleShape {
/// The current `Pipe` gap that the bird needs to jump over.
static sf::Vector2f target_gap;

static std::mt19937 color_engine;
static std::uniform_int_distribution<unsigned char> color_rng;
static std::mt19937 color_engine;
static std::uniform_int_distribution<size_t> color_rng;

float time_lived;
float speed;
Expand Down
3 changes: 2 additions & 1 deletion src/genetic_algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void GeneticAlgorithm::get_inputs(Birds &birds, Pipes const &pipes) {

// normalize the input 2 of the neural network
float bird_position_y_range = (WINDOW_HEIGHT - Bird::SIZE / 2.f) - (Bird::SIZE / 2.f);
float input2_normalized = (Bird::target_gap.y - bird.getPosition().y + bird_position_y_range) / bird_position_y_range * 2.f;
float input2_normalized =
(Bird::target_gap.y - bird.getPosition().y + bird_position_y_range) / bird_position_y_range * 2.f;

// feed the normalized input to the network and apply feedforward.
bird.neural_net.update_inputs(std::abs(input1_normalized), input2_normalized);
Expand Down

0 comments on commit 24022cc

Please sign in to comment.