Skip to content

Instantly share code, notes, and snippets.

@stuntguy3000
Last active August 29, 2015 14:12
Show Gist options
  • Save stuntguy3000/0365c050671ff7f6ff30 to your computer and use it in GitHub Desktop.
Save stuntguy3000/0365c050671ff7f6ff30 to your computer and use it in GitHub Desktop.
package be.multicu.core.util;
/**
*
* @author Codepanda
*/
public class Rating {
private static int MAX_POINTS = 20;
private static int MIN_POINTS = 4;
/**
* This method is used to determine the points for two players. This system
* is based on the ELO system and has a min and max amount of points.
* @param winner The current points of the winner
* @param loser The current points of the loser
* @return int This returns the point difference to be added/removed from players
*/
public static int getELOPoints(int winner, int loser) {
float elo = (float) (1f / (1f + Math.pow(10f, ((looser - winner) / 800f))));
int points = (int) Math.round(20 * (1f - elo));
if (points < MIN_POINTS) {
points = MIN_POINTS;
} else if (points > MAX_POINTS) {
points = MAX_POINTS;
}
return points;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment