Solved Rating system

Discussion in 'Plugin Development' started by Irantwomiles, Mar 1, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Irantwomiles

    I'm trying to make a rating system for my plugin. I want to match people with the same/close rating to each other. I have a list that is filled with people and their rating and I want to check if 1 persons rating is similar to another person, I'm not quite sure how I should go about this.
     
  2. Offline

    Zombie_Striker

    @Irantwomiles
    Is the rating an integer value, or an enum/object value? If it is an integer value, check if the absolute first players score minus the other players score is less than a certain range. If it is, match them together.
     
  3. Offline

    Irantwomiles

    Ah yea, sorry. It is kind of like an elo system, so they are integer values. My problem is searching the list for the correct people to match. How would I go about checking a list of like 100 people who each have different values and match 2 of them up.

    EDIT: I was thinking of searching the first player and going through the list and finding someone, but then that would be very inefficient in my mind.
     
  4. Offline

    mine-care

    @Irantwomiles You can perform a double search:
    Code:
    
    foreach valueFromList as int A: 
        int CLOSEST = -1;//Put an invalid number
        foreach valueFromList as int B exclude A: 
           if  abs(B-A) < CLOSEST then:
              CLOSEST = indexOfB;
           endIf
       endLoop
    endLoop
    
    
    Essentially you have an outer loop going through all the players in a list and getting their rating, and then an inner loop going through the list again and finding the closest entry to the one of the outer loop.
    How close they are is determined by the variable 'closest' which holds the index of the closest element to A. Refer to the pseudocode above i hope it helps ;) (Its really rough i know :( )
     
  5. Offline

    Irantwomiles

    Ok, that makes sense, I didn't think about it that way. So something like this?

    Code:
    
    for(String str: list) 
    {
      Player player   //get player from str
      int min = player.getRating() - 20; //lets pretend thats a thing.
      int max = player.getRating() + 20;
    
      for(String str2 : list)
         Player matched //get player from str2
         if(matched != player)
          {
            if(matched.getRating() <= max && matched.getRating() >= min)
             {
                   //start matched between those players. 
             }
          }
    }
    
    
     
  6. Offline

    mine-care

    @Irantwomiles Hmm that may work but what i had in mind is shown in a new version of your code bellow:

    Code:
    
    for(int indexOne ... ){//Loop through the list based on indexes, not with an enchanced for loop.
       Player player //get player from str
       int closest = -1;//invalid list index to start with.
       for(int indexTwo ...){//Same as the outer loop
       Player matched //get player from str2
          if(matched != player){
             if(closest == -1){//The following if-else system is a litle flawed logic wise but it ilustrates the point.
                closest = indexTwo;
             }else if( Math.abs(matched.getRating()-player.getRating()) < Math.abs(player.getRating()-list.get(closest)){
                 //So here we know that the difference between the rating of the matched player and the one from the outer loop
                 //is smaller than that between the matched player and the previously considered closest player.
                 closest = indexTwo;
             }
          }
       }
    //At this stage 'closest' is the index of the Player who is the closest to 'player'
    //In other words, Player closest = getPlayer(list.get(closest)); is the player whose rating is the closest to 'player'
    }
    
    
    
    I hope that makes it a bit clearer. Sorry if there are logic flaws, its late... If there are let me know ill correct it tomorrow ;)
     
    Irantwomiles likes this.
  7. Offline

    Irantwomiles

    Ok, I kinda understand that. I tried the method I put up and it seems to work fine with at least 2 players so we'll see. Thanks for the help! I'll marked solved for now.
     
  8. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page