Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modes/world_with_rank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "tracks/graph.hpp"
#include "tracks/track.hpp"
#include "tracks/track_sector.hpp"
#include "utils/gp_scoring.hpp"
#include "utils/scoring/scoring.hpp"
#include "utils/log.hpp"

#include <iostream>
Expand Down
167 changes: 0 additions & 167 deletions src/utils/gp_scoring.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/lobby_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "utils/team_manager.hpp"
#include "utils/tournament.hpp"
#include "utils/lobby_gp_manager.hpp"
#include "utils/gp_scoring.hpp"
#include "utils/scoring/scoring.hpp"
#include "utils/crown_manager.hpp"
#include "network/game_setup.hpp"
#include "network/database_connector.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/utils/lobby_gp_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "network/network_string.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/server_config.hpp"
#include "utils/gp_scoring.hpp"
#include "utils/scoring/scoring.hpp"
#include "utils/string_utils.hpp"
#include "utils/team_manager.hpp"

Expand Down
91 changes: 91 additions & 0 deletions src/utils/scoring/exponential_gap_scoring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2025 kimden
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "utils/scoring/exponential_gap_scoring.hpp"
#include "utils/string_utils.hpp"

#include <cmath>
#include <stdexcept>


void ExponentialGapScoring::fromIntParamString(const std::string& input)
{
auto argv = StringUtils::split(input, ' ');
m_pole_points = Scoring::parse<int>(argv, 0);
m_fastest_lap_points = Scoring::parse<int>(argv, 1);
m_win_points = Scoring::parseThousandth(argv, 2);
m_time_log_unit = Scoring::parseThousandth(argv, 3);
m_decrease = Scoring::parseThousandth(argv, 4);
m_continuous = Scoring::parse<int>(argv, 5);

m_allow_negative = true;
m_allow_pure_negative = false; // kimden: pay attention
m_round = true;
} // fromIntParamString
//-----------------------------------------------------------------------------

void ExponentialGapScoring::fromString(const std::string& input)
{

} // fromString
//-----------------------------------------------------------------------------

void ExponentialGapScoring::refreshCustomScores(int num_karts,
std::vector<int>& score_for_position)
{
score_for_position.clear();
score_for_position.resize(num_karts, 0);
} // refreshCustomScores
//-----------------------------------------------------------------------------

int ExponentialGapScoring::getScoreForPosition(int p, float time,
std::map<int, float>& race_times,
const std::vector<int>& score_for_position) const
{
race_times[p] = time;
double delta = time - race_times[1];
if (race_times[1] < 1e-6) // just in case
return 0;

delta = log(time / race_times[1]) / log(2);
double points = m_win_points;
bool continuous = (m_continuous != 0);
double time_step = m_time_log_unit;
double decrease = m_decrease;
delta /= time_step;
if (!continuous)
delta = floor(delta);
points -= delta * decrease;

if (points < 0.0)
points = 0.0;

if (m_round)
points = round(points);

return points;
} // getScoreForPosition
//-----------------------------------------------------------------------------

bool ExponentialGapScoring::canGetScoreForPosition(int p, const std::map<int, float>& race_times) const
{
if (p == 1 || race_times.count(1))
return true;
return false;
} // canGetScoreForPosition
//-----------------------------------------------------------------------------
51 changes: 51 additions & 0 deletions src/utils/scoring/exponential_gap_scoring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2025 kimden
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#ifndef EXPONENTIAL_GAP_SCORING_HPP
#define EXPONENTIAL_GAP_SCORING_HPP

#include "utils/scoring/scoring.hpp"

class ExponentialGapScoring: public Scoring
{
private:
double m_win_points;
double m_continuous;
double m_time_log_unit;
double m_decrease;

public:
void fromIntParamString(const std::string& input) final;

void fromString(const std::string& input) final;

bool isStandard() const final { return false; }

void refreshCustomScores(int num_karts, std::vector<int>& score_for_position) final;

int getScoreForPosition(int p, float time,
std::map<int, float>& race_times,
const std::vector<int>& score_for_position) const final;

bool canGetScoreForPosition(int p, const std::map<int, float>& race_times) const final;

std::string toString() const;
};


#endif // EXPONENTIAL_GAP_SCORING_HPP
44 changes: 44 additions & 0 deletions src/utils/scoring/fixed_scoring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2025 kimden
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "utils/scoring/fixed_scoring.hpp"


void GPScoring::refreshCustomScores(int num_karts,
std::vector<int>& score_for_position)
{
score_for_position.clear();
for (unsigned i = 2; i < m_params.size(); i++)
score_for_position.push_back(m_params[i]);
score_for_position.resize(num_karts, 0);
} // refreshCustomScores

int GPScoring::getScoreForPosition(int p, float time,
std::map<int, float>& race_times,
const std::vector<int>& score_for_position) const
{
race_times[p] = time;
return score_for_position[p - 1];
} // getScoreForPosition
//-----------------------------------------------------------------------------

bool GPScoring::canGetScoreForPosition(int p, const std::map<int, float>& race_times) const
{
return true;
} // canGetScoreForPosition
//-----------------------------------------------------------------------------
Loading