Skip to content

Commit

Permalink
Minor post-grading changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chubercik committed Jun 7, 2023
1 parent 2d06c7c commit 1c579fc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 29 deletions.
18 changes: 12 additions & 6 deletions config/CarConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
* @brief This file contains all the constant values for the car class.
*
* @file CarConfig.h
* @author Mateusz Krakowski
* @date 2023-06-06
* @authors Mateusz Krakowski, Jakub Marcowski
* @date 2023-06-07
*/

#ifndef CARCONFIG_H
#define CARCONFIG_H

class CarConfig {
public:

// Car speed is dependent on the car's torque
// Car speed is dependent on the car's torque
static constexpr float CAR_TORQUE = 2000.0f;



static constexpr float MAX_JOINT_LENGTH = 0.01f;
// Number of vertices in a car's body polygon
static constexpr int CAR_VERTICES = 8;

// F = V^2 * k
// k ≈ 1/2 * ρ * A * C_d ≈ 3.4
// ρ = 1.293 kg/m^3
// A = ? (let's assume 5 m^2)
// C_d = ? (let's assume 1.05)
//
// F = 3.4 * V^2
static constexpr float AIR_RES_FACTOR = 3.4f;
};

#endif // CARCONFIG_H
4 changes: 2 additions & 2 deletions config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file Config.h
* @authors Jakub Marcowski, Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#ifndef CONFIG_H
Expand All @@ -16,7 +16,7 @@ class Config {

// 60 for real time, 120 for fast forward - anything else is undefined behaviour
static constexpr int MAX_FPS = 60;

static constexpr int GROUND_PARTS_RENDERED = 32;

// Exporting to file
Expand Down
8 changes: 6 additions & 2 deletions config/EvolutionaryAlgorithmConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file EvolutionaryAlgorithmConfig.h
* @author Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#ifndef EVOLUTIONARY_ALGORITHM_CONFIG_H
Expand All @@ -12,9 +12,11 @@
class EvolutionaryAlgorithmConfig {
public:
// Evolutionary algorithm parameters
static constexpr int POPULATION_SIZE = 15;

static constexpr int POPULATION_SIZE = 16;

// Boundaries for the chromosomes

static constexpr float MIN_BODY_LENGTH = 1.0f;
static constexpr float MAX_BODY_LENGTH = 5.0f;

Expand All @@ -28,6 +30,7 @@ class EvolutionaryAlgorithmConfig {
static constexpr float MAX_WHEEL_DENSITY = 1000.0f;

// Population initialization hyper parameters

static constexpr float INITIAL_BODY_LENGTH_MEAN = 3.0f;
static constexpr float INITIAL_BODY_LENGTH_VARIANCE = 1.0f;

Expand Down Expand Up @@ -55,6 +58,7 @@ class EvolutionaryAlgorithmConfig {
static constexpr float MUTATION_FACTOR_WHEEL_DENSITY = 20.0f;

// Selection hyper parameters

static constexpr int TOURNAMENT_SIZE = 3; // Has to be equal to or lesser than POPULATION_SIZE
};

Expand Down
5 changes: 2 additions & 3 deletions config/MapGenConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file MapGenConfig.h
* @author Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#ifndef MAPGENCONFIG_H
Expand All @@ -22,10 +22,9 @@ class MapGenConfig {
static constexpr float CAR_STARTING_Y = 650.0;

// Change the mapgen behaviour here

static constexpr float GROUND_DEGREE_DEVIATION = 12.0f;
static constexpr float MAX_GROUND_DEGREE = 50.0f;


};

#endif // MAPGENCONFIG_H
Binary file modified docs/docs_by_doxygen.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions src/Car.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @file Car.cc
* @authors Jakub Marcowski, Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#include "Car.h"
Expand Down Expand Up @@ -97,13 +97,13 @@ std::vector<b2Vec2> createVertices(std::vector<float> lengths) {

std::vector<float> angles;
angles.reserve(lengths.size());
for (int i = 0; i < lengths.size(); i++) {
for (int i = 0; i < lengths.size(); ++i) {
angles.push_back(360.0f / lengths.size());
}
// so that the wheels are set properly (that is - parallel to the ground)
float angle = ((180.0f + (angles.back() / 2)) / 180.0f) * Config::PI;

for (int i = 0; i < lengths.size(); i++) {
for (int i = 0; i < lengths.size(); ++i) {
vertices.emplace_back(lengths[i] * cos(angle), lengths[i] * sin(angle));
angle += (angles[i] / 180.0f) * Config::PI;
}
Expand Down
12 changes: 3 additions & 9 deletions src/GUI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file GUI.cc
* @author Jakub Marcowski
* @date 2023-06-06
* @date 2023-06-07
*/

#include "GUI.h"
Expand All @@ -14,9 +14,6 @@ void renderVelocityPlot(std::vector<Car>& cars, bool paused) {
if (ImPlot::BeginPlot("Velocity")) {
ImPlot::SetupLegend(ImPlotLocation_West, ImPlotLegendFlags_Outside);
for (int i = 0; i < cars.size(); ++i) {
char i_str[11]; // 10 digits + null
sprintf(i_str, "%d", i);

if (!paused) {
cars[i].getVelX()->push_back(cars[i].getVelX()->back() + 1);
cars[i].getVelY()->push_back(cars[i].getVelocity());
Expand All @@ -26,7 +23,7 @@ void renderVelocityPlot(std::vector<Car>& cars, bool paused) {
std::vector<float> v_values_crop = std::vector<float>(
cars[i].getVelY()->end() - Config::VELOCITY_ARRAY_SIZE, cars[i].getVelY()->end());
ImPlot::PushStyleColor(ImPlotCol_Line, SFMLColorToImVec4(cars[i].getBodyColor()));
ImPlot::PlotLine(i_str, &(v_axis_crop[0]), &(v_values_crop[0]),
ImPlot::PlotLine(std::to_string(i).c_str(), &(v_axis_crop[0]), &(v_values_crop[0]),
Config::VELOCITY_ARRAY_SIZE);
ImPlot::PopStyleColor();
}
Expand All @@ -41,9 +38,6 @@ void renderPositionPlot(std::vector<Car>& cars, bool paused) {
if (ImPlot::BeginPlot("Position")) {
ImPlot::SetupLegend(ImPlotLocation_West, ImPlotLegendFlags_Outside);
for (int i = 0; i < cars.size(); ++i) {
char i_str[11];
sprintf(i_str, "%d", i);

if (!paused) {
cars[i].getPosXVec()->push_back(cars[i].getPosXVec()->back() + 1);
cars[i].getPosYVec()->push_back(cars[i].getBody()->body->GetPosition().x);
Expand All @@ -55,7 +49,7 @@ void renderPositionPlot(std::vector<Car>& cars, bool paused) {
std::vector<float>(cars[i].getPosYVec()->end() - Config::VELOCITY_ARRAY_SIZE,
cars[i].getPosYVec()->end());
ImPlot::PushStyleColor(ImPlotCol_Line, SFMLColorToImVec4(cars[i].getBodyColor()));
ImPlot::PlotLine(i_str, &(v_axis_crop[0]), &(v_values_crop[0]),
ImPlot::PlotLine(std::to_string(i).c_str(), &(v_axis_crop[0]), &(v_values_crop[0]),
Config::VELOCITY_ARRAY_SIZE);
ImPlot::PopStyleColor();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file Utility.cc
* @authors Jakub Marcowski, Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#include "Utility.h"
Expand All @@ -17,9 +17,9 @@ void applyAirResistance(Car car) {
//
// F = 3.4 * V^2
car.getBody()->body->ApplyForceToCenter(
b2Vec2(-1.84 * car.getBody()->body->GetLinearVelocity().x *
b2Vec2(-sqrt(CarConfig::AIR_RES_FACTOR) * car.getBody()->body->GetLinearVelocity().x *
abs(car.getBody()->body->GetLinearVelocity().x),
-1.84 * car.getBody()->body->GetLinearVelocity().y *
-sqrt(CarConfig::AIR_RES_FACTOR) * car.getBody()->body->GetLinearVelocity().y *
abs(car.getBody()->body->GetLinearVelocity().y)),
true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @file Utility.h
* @authors Jakub Marcowski, Mateusz Krakowski
* @date 2023-06-06
* @date 2023-06-07
*/

#ifndef UTILITY_H
Expand All @@ -19,6 +19,7 @@
#include "SFML/Graphics.hpp"
#include "EvolutionaryAlgorithm.h"

#include "../config/CarConfig.h"
#include "../config/Config.h"
#include "../config/MapGenConfig.h"
#include "Car.h"
Expand Down

0 comments on commit 1c579fc

Please sign in to comment.