Basic algorithm
I would sort the players by their rank, since high-ranking players always repelled low-paying ones. Then you start with the player with the highest rank, give him what he requested (if he is really the highest, he will always win, so you can also give him everything that he requested). Then I will start with the second largest. If he asked for something already taken highest, try to find a slot nearby and assign him this slot. Now comes the third highest. If he asks for something already taken at the highest, move it to the slot next to it. If this slot is already occupied by the second highest, move it to the slot even further. Continue with all the other players.
Some settings to consider:
If several players can have the same rank, you may need to implement some “justice”. All players with equal rank will have a random order to each other if you sort them, for example. using quicksort. You can get some justice if you do not make this player for the player, but take the title. You start with the highest rank and the first player of that rank. Process his first request. However, before processing your second request, process the first request of the next player with the highest rank, and then the third player with the highest rank. The algorithm is the same as above, but provided that you have 10 players and player 1-4 is the highest and players 5-7 are low and players 8-10 are very low and each player makes 3 requests, you treat them like
Player 1 - Request 1 Player 2 - Request 1 Player 3 - Request 1 Player 4 - Request 1 Player 1 - Request 2 Player 2 - Request 2 :
So you have justice. You can also choose randomly in the ranking class every time, this can also provide some fairness.
You can realize justice even by rank. For example. if you have 4 digits you can say
Rank 1 - 50% Rank 2 - 25% Rank 3 - 12,5% Rank 4 - 6,25%
(Only approximate values, you can use a different key than always multiply by 0.5, for example, multiply by 0.8, causing the numbers to decrease more slowly)
Now you can say that you are starting to process with rank 1, however, as soon as 50% of all Rank 1 requests are completed, you go to level 2 and make sure that 25% of their requests are completed and so on. Thus, even a Rank 4 user can defeat a Rank 1 user by defeating the original algorithm somewhat, however you offer some fairness. Even a 4th rank player can sometimes receive his request; he will not be “dry”. Otherwise, a Rank 1 player planning each request simultaneously with a Rank 4 player ensures that a 4th rank player has no chance of receiving one request. Thus, there is at least a small chance to get it.
After you make sure that each of them has processed their minimum percentage (and the higher the rank, the higher it is), you return to the beginning, starting from the first rank 1 and processing the rest of your queries, and then the rest of Rank 2, etc. d.
And last but not least:. You can determine the maximum slot offset. If a slot is taken, the application should search in the nearest slot still for free. However, what if this nearest slot is very far away? If I ask for a slot on Monday at 4 p.m., and the application finds the next free one to be on Wednesday at 9 a.m., this is not very useful for me, is it? I may not have time on Wednesday. Thus, you can limit the search for a slot on the same day and say that the slot can be no more than 3 hours. If no slots are found in this range, cancel the request. In this case, you need to tell the player "We are sorry, but we could not find any nearby slots for you, please request a slot for a different date / time, and we will see if we find a suitable slot for you."