From eaf1486d9c5bdfdae815bee98bb59406440e7f4a Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 10 Jun 2016 20:52:38 +0800 Subject: [PATCH 1/6] Remove misleading-FPS info in soccer mode profiling As it will increase with the total polycount of the soccer field. Now just use total frame elapsed to estimate AI performance. --- src/modes/soccer_world.cpp | 8 ++------ src/modes/soccer_world.hpp | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 97282d25d..87823d7e8 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -54,7 +54,6 @@ SoccerWorld::SoccerWorld() : WorldWithRank() } m_frame_count = 0; - m_start_time = irr_driver->getRealTime(); m_use_highscores = false; m_red_ai = 0; m_blue_ai = 0; @@ -601,11 +600,8 @@ void SoccerWorld::enterRaceOverState() if (UserConfigParams::m_arena_ai_stats) { - float runtime = (irr_driver->getRealTime()-m_start_time)*0.001f; - Log::verbose("Soccer AI profiling", "Number of frames: %d, Average FPS: %f", - m_frame_count, (float)m_frame_count/runtime); - Log::verbose("Soccer AI profiling", "Time for a team to have 30 goals: %f", - runtime); + Log::verbose("Soccer AI profiling", "Frames elapsed for a team to win" + "with 30 goals: %d", m_frame_count); // Goal calculation int red_own_goal = 0; diff --git a/src/modes/soccer_world.hpp b/src/modes/soccer_world.hpp index 071233653..129137618 100644 --- a/src/modes/soccer_world.hpp +++ b/src/modes/soccer_world.hpp @@ -302,7 +302,6 @@ private: /** Profiling usage */ int m_frame_count; - int m_start_time; public: From bbc61480a4e8864180a2683abf9748822e967e72 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 10 Jun 2016 21:11:55 +0800 Subject: [PATCH 2/6] Fix missing white-space --- src/modes/soccer_world.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 87823d7e8..a6109fb55 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -601,7 +601,7 @@ void SoccerWorld::enterRaceOverState() if (UserConfigParams::m_arena_ai_stats) { Log::verbose("Soccer AI profiling", "Frames elapsed for a team to win" - "with 30 goals: %d", m_frame_count); + " with 30 goals: %d", m_frame_count); // Goal calculation int red_own_goal = 0; From 023dbe196815b851a921ccef4cb3f11ed0ad192c Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 11 Jun 2016 15:31:58 +0800 Subject: [PATCH 3/6] More statistics in soccer mode profiling --- src/modes/soccer_world.cpp | 41 ++++++++++++++++++++++++++++++++++++-- src/modes/soccer_world.hpp | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index a6109fb55..d7e53f78b 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -37,6 +37,7 @@ #include "utils/constants.hpp" #include +#include #include //----------------------------------------------------------------------------- /** Constructor. Sets up the clock mode etc. @@ -211,6 +212,13 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal) m_goal_sound->play(); if (m_ball_hitter != -1) { + if (UserConfigParams::m_arena_ai_stats) + { + const int elapsed_frame = m_goal_frame.empty() ? 0 : + std::accumulate(m_goal_frame.begin(), m_goal_frame.end(), 0); + m_goal_frame.push_back(m_frame_count - elapsed_frame); + } + ScorerData sd; sd.m_id = m_ball_hitter; sd.m_correct_goal = isCorrectGoal(m_ball_hitter, first_goal); @@ -600,8 +608,37 @@ void SoccerWorld::enterRaceOverState() if (UserConfigParams::m_arena_ai_stats) { - Log::verbose("Soccer AI profiling", "Frames elapsed for a team to win" - " with 30 goals: %d", m_frame_count); + Log::verbose("Soccer AI profiling", "Total frames elapsed for a team" + " to win with 30 goals: %d", m_frame_count); + + // Goal time statistics + std::sort(m_goal_frame.begin(), m_goal_frame.end()); + + const int mean = std::accumulate(m_goal_frame.begin(), + m_goal_frame.end(), 0) / m_goal_frame.size(); + + // Prevent overflow if there is a large frame in vector + double squared_sum = 0; + for (const int &i : m_goal_frame) + squared_sum = squared_sum + (double(i - mean) * double(i - mean)); + + // Use sample st. deviation (n−1) as the profiling can't be run forever + const int stdev = int(sqrt(squared_sum / (m_goal_frame.size() - 1))); + + int median = 0; + if (m_goal_frame.size() % 2 == 0) + { + median = (m_goal_frame[m_goal_frame.size() / 2 - 1] + + m_goal_frame[m_goal_frame.size() / 2]) / 2; + } + else + { + median = m_goal_frame[m_goal_frame.size() / 2]; + } + + Log::verbose("Soccer AI profiling", "Frames elapsed for each goal:" + " min: %d max: %d mean: %d median: %d standard deviation: %d", + m_goal_frame.front(), m_goal_frame.back(), mean, median, stdev); // Goal calculation int red_own_goal = 0; diff --git a/src/modes/soccer_world.hpp b/src/modes/soccer_world.hpp index 129137618..5875d6c4f 100644 --- a/src/modes/soccer_world.hpp +++ b/src/modes/soccer_world.hpp @@ -302,6 +302,7 @@ private: /** Profiling usage */ int m_frame_count; + std::vector m_goal_frame; public: From d1d591ca34b97ed6235eca6313ca2bde5d11f3ab Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 11 Jun 2016 15:58:17 +0800 Subject: [PATCH 4/6] Fix compiler warning --- src/modes/soccer_world.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index d7e53f78b..d3c00fb41 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -656,9 +656,9 @@ void SoccerWorld::enterRaceOverState() red_own_goal++; } - int red_goal = ((m_red_scorers.size() - blue_own_goal) >= 0 ? + int red_goal = ((int(m_red_scorers.size()) - blue_own_goal) >= 0 ? m_red_scorers.size() - blue_own_goal : 0); - int blue_goal = ((m_blue_scorers.size() - red_own_goal) >= 0 ? + int blue_goal = ((int(m_blue_scorers.size()) - red_own_goal) >= 0 ? m_blue_scorers.size() - red_own_goal : 0); Log::verbose("Soccer AI profiling", "Red goal: %d, Red own goal: %d," From 1e1093dccc20139af55081bd036cbebc0fe2a33d Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 12 Jun 2016 08:09:28 +0800 Subject: [PATCH 5/6] Fix default value of m_angular_damping --- src/physics/physical_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index cd8e21012..7f7d0fa90 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -111,7 +111,7 @@ void PhysicalObject::Settings::init() m_linear_factor = Vec3(1.0f, 1.0f, 1.0f); m_angular_factor = Vec3(1.0f, 1.0f, 1.0f); m_linear_damping = 0.0f; - m_angular_damping = 0.0f; + m_angular_damping = 0.5f; m_reset_when_too_low = false; m_flatten_kart = false; } // Settings From 143bc2618e16f3734f38792508456fbf7c9ad25b Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 13 Jun 2016 09:09:18 +0800 Subject: [PATCH 6/6] Remove a unneeded setting --- src/physics/physical_object.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 7f7d0fa90..9e7abd0fc 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -111,6 +111,7 @@ void PhysicalObject::Settings::init() m_linear_factor = Vec3(1.0f, 1.0f, 1.0f); m_angular_factor = Vec3(1.0f, 1.0f, 1.0f); m_linear_damping = 0.0f; + // Make sure that the cones stop rolling by defining angular friction != 0. m_angular_damping = 0.5f; m_reset_when_too_low = false; m_flatten_kart = false; @@ -521,8 +522,6 @@ void PhysicalObject::init(const PhysicalObject::Settings& settings) btRigidBody::btRigidBodyConstructionInfo info(m_mass, m_motion_state, m_shape, inertia); - // Make sure that the cones stop rolling by defining angular friction != 0. - info.m_angularDamping = 0.5f; m_body = new btRigidBody(info); m_user_pointer.set(this); m_body->setUserPointer(&m_user_pointer);