I implement elo algorithm however it was working in quite opposite way as i mix results (set win where is lose and opposite..) That little detail fail my results - thats why question is - how can i reverse that ?
I have only new Elo and old elo as i was garhering statistics..
My algorithm looks exactly like on wiki: https://en.wikipedia.org/wiki/Elo_rating_system#Theory
which is:
public class EloAlgorithm {
public static Integer calculateRating(Integer myRating, Integer opponentRating, EloGameResultValue result) {
myRating += calculateEloDelta(myRating, opponentRating, result);
if (myRating<0){
return 0;
}
return myRating;
}
private static Integer calculateEloDelta(Integer myRating, Integer opponentRating, EloGameResultValue result){
Double myChanceToWin = 1 / (1 + Math.pow(10, (opponentRating - myRating) / 400));
Long eloDelta = Math.round(getKFactor(myRating) * (result.getValue() - myChanceToWin));
return eloDelta.intValue();
}
private static double getKFactor(Integer myRating) {
if(myRating < 2100) return 32.0;
else if(myRating >= 2100 && myRating < 2400) return 24;
else return 16;
}
}
i tried to reverse it but probably i did a mistake in my calculations:
public static Integer fetchOponentRatingFromDifference(int myOldRating, int myNewRating, EloGameResultValue result){
double delta = myNewRating - myOldRating;
double k = getKFactor(myOldRating);
double myChanceToWin = (k* result.getValue() - difference)/k ;
double log = Math.log10(1/myChanceToWin - 1);
Double resultToReturn = 400*log + myOldRating;
return (int)Math.round(resultToReturn);
}
Can you please help me find a mistake in it or reccomend better solution?
EDIT: As was requested:
I test it via JUnit
public class EloValueBinaryFinderTest {
@Test
public void eloValueFinderTest(){
System.out.println(
EloValueBinaryFinder.fetchOponentRatingFromDifference(952,968)
);
}
}
however main method with this will be :
public class EloValueBinaryFinderTest {
public static void main(String... args){
System.out.println(
EloValueBinaryFinder.fetchOponentRatingFromDifference(952,968)
);
}
}
EloGameResultValue as was necessary is just an enum:
public enum EloGameResultValue {
WIN(1),
DRAW(0.5),
LOSE(0);
Double value;
EloGameResultValue(double value) {
this.value = value;
}
public Double getValue() {
return value;
}
public Boolean isWin() {
if(value.equals(1.0)){
return true;
}
if(value.equals(0.0)){
return false;
}
return null;
}
}