Matching algorithm

Matching algorithms in the game generally appear in combat functions, such as 3v3, 1v1, 50v50, 10v10, and the combat functions that are divided into three forces. A global manager is used to match the participating players and generate the participating players for each battle. The matching rules can be based on the player's combat power, level or registration time sequence,
or random combination. Common matching algorithms are as follows:

(1) Single-loop matching algorithm
For example, there are 4 ABCD players, and the required matching combinations under the single-loop rule are AB, AC, AD, BC, BD, CD, then: the
first round of competition is:
AB CD

The second round is:
AD BC

The third round is:
AC BD

Prepare two queues, starting from subscript 1 to traverse the data of all participating players (if the array is ABCD), one queue for players with odd numbers, and one for players with even numbers. For example, queue 1 is for C, and queue 2 is for players. Put the BD player, and player A has a variable tmpuser, the
outer loop traverses the game rounds, the inner loop traverses the queue 2 players, and then if the subscript is 0, tmpuser plays with C, that is, A and C play, otherwise queue 1 The player with subscript i-1 and the player with subscript i in queue 2 are matched together, that is, the other group is played by B and D.
After this round of matching, the players in queue 1 and queue 2 are updated. The update method is clockwise circular update, that is: (C moves to the end of queue 2, B moves to the beginning of queue 1)
   C B
       -> 
BD DC

Then match the players in the second round, namely AD BC, and so on, and then update the players in queue 1 and queue 2:
    B D
        ->
DC CB

That is, the player in the third round is AC DB

At the same time, in order to distinguish each game, an id number can be set for each game, that is, the id numbers of AB CD AD BC AC BD can be set to 1 2 3 4 5 6 respectively.

Guess you like

Origin blog.csdn.net/Ftworld21/article/details/108126834