SuperTuxKart
ranking.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2024 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef RANKING_HPP
20 #define RANKING_HPP
21 
22 #include <map>
23 #include <memory>
24 #include <vector>
25 #include <stdint.h>
26 
27 class XMLNode;
29 
31 {
32  uint32_t online_id;
33  double raw_score;
34  double score;
35  double max_score;
36  double deviation;
37  uint64_t disconnects;
38  unsigned races;
39 
40  RankingEntry(uint32_t online_id = -1);
41 };
42 
44  uint32_t online_id;
45  bool is_eliminated;
46  double time;
47  bool handicap;
48 };
49 
51 {
52  RankingEntry entry;
53  std::weak_ptr<NetworkPlayerProfile> profile;
54 };
55 
56 class Ranking
57 {
58 private:
59  // A map that stores the actual scores.
60  std::map<uint32_t, RankingEntryAndProfile> m_entries;
61 
62  // A map that stores the score before the last series of computeNewRankings calls has started.
63  std::map<uint32_t, RankingEntry> m_old_entries;
64 
65  static double getModeFactor(bool time_trial);
66  static double getModeSpread(bool time_trial);
67  static double getTimeSpread(double time);
68  static double scalingValueForTime(double time);
69  static double computeH2HResult(double player1_time, double player2_time);
70  static double computeDataAccuracy(double player1_rd, double player2_rd,
71  double player1_scores, double player2_scores,
72  int player_count, bool handicap_used);
73 public:
74  void computeNewRankings(std::vector<RaceResultData>& data, bool time_trial);
75  void cleanup();
76  void fill(uint32_t online_id, const XMLNode* result, std::shared_ptr<NetworkPlayerProfile> npp);
77  bool has(uint32_t online_id);
78  double getDelta(uint32_t online_id);
79  const RankingEntry getScores(uint32_t online_id) const;
80  const RankingEntry getTemporaryPenalizedScores(uint32_t online_id) const;
81 };
82 
83 #endif
Contains the profile of a player.
Definition: network_player_profile.hpp:42
Definition: ranking.hpp:57
static double scalingValueForTime(double time)
Compute the scaling value of a given time This is linear to race duration, getTimeSpread takes care o...
Definition: ranking.cpp:324
static double computeH2HResult(double player1_time, double player2_time)
Computes the score of a head-to-head minimatch.
Definition: ranking.cpp:335
static double computeDataAccuracy(double player1_rd, double player2_rd, double player1_scores, double player2_scores, int player_count, bool handicap_used)
Computes a relative factor indicating how much informative value the new race result gives us.
Definition: ranking.cpp:388
static double getModeFactor(bool time_trial)
Returns the mode race importance factor, used to make ranking move slower in more random modes.
Definition: ranking.cpp:283
static double getTimeSpread(double time)
Returns the time spread factor.
Definition: ranking.cpp:314
static double getModeSpread(bool time_trial)
Returns the mode spread factor, used so that a similar difference in skill will result in a similar r...
Definition: ranking.cpp:294
void computeNewRankings(std::vector< RaceResultData > &data, bool time_trial)
Compute the new player's rankings used in ranked servers.
Definition: ranking.cpp:56
utility class used to parse XML files
Definition: xml_node.hpp:48
Definition: ranking.hpp:43
Definition: ranking.hpp:51
Definition: ranking.hpp:31