Android Development & Technology
  • Elo Rating Calculation for Games (from Chess)

    Posted on June 17th, 2010 chris 1 comment

    Recently I’ve implemented a rating system for an Android game and found the Elo rating system from chess to be a very good fit and easy to implement. The idea of the ELO system is to increase or reduce points proportional to the strength difference of the players. A player with more points is expected to win, thus if he only reaches a draw will loose points and the weaker player will gain some.

    For the examples we use a K factor of 32, which is used by FIDE for rating beginners (a lower K factor is used for masters and will reduce the number of points won/lost).

    Points Player 1 before Points Player 2 before Winner Points Player 1 after Points Player 2 after
    1500 1600 Player 1 1520 1579
    1500 1600 Draw 1504 1595
    1500 1600 Player 2 1488 1611

    This is the algorithm implemented in Java for calculating the ratings:

    // Returns an array of two doubles: [0] is the new rating for player A, [1] for player B
    //
    // Parameters:
    //   status: 0 = draw, 1 = player A won, 2 = player B won
    //   RA, RB: the players points before the game
    private double[] calcElo(int status, double RA, double RB) {
    	double QA = Math.pow(10, RA/400);
    	double QB = Math.pow(10, RB/400);
    
    	// set the desired k factor
    	double k = 32;
    
    	double EA = QA / (QA + QB);
    	double EB = QB / (QA + QB);	    	
    
    	double SA = 0.5; // draw
    	double SB = 0.5; // draw
    	if (status == 1) {
    		SA = 1;
    		SB = 0;
    	} else if (status == 2) {
    		SA = 0;
    		SB = 1;
    	}
    
    	double[] res = new double[2];
    	res[0] = RA + (k * (SA - EA));
    	res[1] = RB + (k * (SB - EB));
    	return res;
    }
     

    One Response to “Elo Rating Calculation for Games (from Chess)”

    1. [...] more from the original source: Elo Rating Calculation for Games (from Chess) | 4 Feet Software Tagged with: elo • from-chess • increase-or-reduce • rating-system • [...]

imprint
Sponsored links: