If you always want to pick the closest one, you just put players in an array with EloPlayer objects (just encapsulate the player and the elo value). Then when you want to get the opponent you do an order n operation to search. Then you do two constant time operations to find the neighbours (if they exist). Then you find which neighbour is closer. So I would say that is pretty decent. Everytime a player joins or quits, you would run a sort on the array (which could be async if you really felt like it). Also, if a player performs a kill or dies, you would need to perform a small update to the array, which shouldn't be too expensive. But if you wanted to you could just ignore this, because it's not like they are going to get 100000 kills in one session and completely change their ranking, they will still be in the same ballpark. This can be dropped to constant time, by being able to retrieve the rank of a player in constant time. There are multiple ways to accomplish this.
Very simple, calculate an ELO for each player, I'll put my system below. Then when you are matching players just do this: PHP: $max = 100;//players MUST be within 100 ELO of each otherif(max($elo1, $elo2) - min($elo1, $elo2) > $max){ return;//or break/continue if its a loop} My ELO calculating system: PHP: class Elo{ private $wins; private $losses; private $elo; public function __construct($wins, $losses) { $this->wins = $wins; $this->losses = $losses; $this->calculate(); } public function calculate() { $wins = $this->wins; $losses = $this->losses; $this->elo = 1200 + (($wins - $losses) * 25); } public function getElo() { return $this->elo; }} ^^ Thats not the whole class, the rest is private (someone is gonna nag me for using a class for a simple function)
i dont think that's truely ELO mathematically speaking, most mathematical things just flew over my head while reading wiki but the elo is deducted off opponent and missing a K factor i feel like it's more sudo ELO
Code: I wrote that for this thread, I have a much longer ELO system that this threads owner probs wouldn't understand.
What I would do is put the players in a group based on their ELO For example 0-100 would be group 1, 100-200 group 2, 200-300 group 3, etc etc. Then you just get all the players who are in the same group as the player and are online and pick a random one to match him/her up with the player
Whoopsies, I was typing the code for what you said. I had to read it a few times before I fully got it. Forgot to paste it , don't have it anymore (didn't save it) .
So easy: $rank = $this->config->get($pl.'-rank'); // EXEMPLE return number if($rank == 0) $rank = 'Joueur'; if($rank == 1) $rank = 'Admin'; echo 'You rank is: '.$rank;