Perhaps this would help:
#include <map>
As you can see that a player, which is a class object that associates a player’s name with an account and maintains data confidentiality, can use auxiliary functions to set and receive values, there is a default constructor to create an empty game object to fill in later, plus an explicit constructor that with the exception of at least the std string for the name, and evaluation is an option. If the score is left empty, you have a player who exists before any match, and as soon as the match ends, you can use the setScore method. There are operators to check if Player1 == Player2 or! = And <and> operators that return true or false for if statements. And if you want to compare two players and return one player or another based on if the rating is equal to> or <there are two functions that do this for you. All the tools are in this nice little class, and you can even expand it.
I used std :: array, since we know that there should be only 2 players in a match, for example, in a chess game. Now, if you need more players, you can either increase the number of elements in the array, if the value is small, say less than 10 or 20 per max, if there are more players, then you want to switch std :: array to std :: vector of Player objects or std :: vector pointers to Player objects awaiting your needs. The map simply binds unsigned as a key or index using std :: array or std :: vector players. The index on the map makes it enjoyable, since each match or game is unique, and normal maps do not allow duplicate keys. In addition, using unsigned makes the map [] an assignment designator much more readable.
Of course, you can always create a function that will be used either in two Players using the permalink or two player pointers, and they will install these players on the map for you.
You can also create your own map in advance with a bunch of player’s objects, everyone has unique names without points, and then after each match you can go through the for loop using an iterator to update all the points, and then create another function to go through through your entire map to sort each match by the highest value of the first or second, etc. This is just a recommendation on how you can achieve what you have stated. There is never an exact "right path", since there are many ways to achieve the desired results when writing a program.
source share