Android Open Source - it.alcacoop.fourinaline E L O Rating Manager






From Project

Back to project page it.alcacoop.fourinaline.

License

The source code is released under:

GNU General Public License

If you think the Android project it.alcacoop.fourinaline listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.alcacoop.fourinaline.utils;
/*  w ww . ja va 2 s .c  o m*/
import it.alcacoop.fourinaline.FourInALine;
import it.alcacoop.fourinaline.logic.MatchState;


public class ELORatingManager {
  
  private final static String SINGLE_BOARD = "CgkItK3my54ZEAIQHA";
  private final static String MULTI_BOARD = "CgkItK3my54ZEAIQHQ";
  
  private final static double CONVERT_ADDENDUM = 1500.00;
  private double matchValue;

  private static ELORatingManager instance;
  private double currentRating = 0.00; // in ELO
  private double opponentRating = 0.00; // in ELO
  
  private ELORatingManager() {}
  
  public synchronized static ELORatingManager getInstance() {
    if (instance == null) instance = new ELORatingManager();
    return instance;
  }
  
  public void setRatings(double opponentRating) {
    if (MatchState.matchType == 2) {
      this.opponentRating = opponentRating + CONVERT_ADDENDUM;
      this.currentRating = Double.parseDouble(FourInALine.Instance.gameOptionPrefs.getString("MULTIBOARD", "0")) + CONVERT_ADDENDUM;
    } else if (MatchState.matchType == 0) {
      this.opponentRating = opponentRating;
      this.currentRating = Double.parseDouble(FourInALine.Instance.gameOptionPrefs.getString("SINGLEBOARD", "0")) + CONVERT_ADDENDUM;
    }
  }

  public void syncLeaderboards() {
    long score = (long)(Double.parseDouble(FourInALine.Instance.gameOptionPrefs.getString("MULTIBOARD", "0")) * 100);
    
    if (score>0)
      FourInALine.Instance.nativeFunctions.gserviceSubmitRating(score, MULTI_BOARD);
    
    score = (long)(Double.parseDouble(FourInALine.Instance.gameOptionPrefs.getString("SINGLEBOARD", "0")) * 100);
    if (score>0)
      FourInALine.Instance.nativeFunctions.gserviceSubmitRating(score, SINGLE_BOARD);
  }

  
  public void updateRating(int server, double increment) {
    FourInALine.Instance.gameOptionPrefs.flush();
    FourInALine.Instance.nativeFunctions.gserviceUpdateState();
  }
  
  public void updateRating(boolean youWin) {
    if (!youWin) return;
    
    int matchLevel = MatchState.nMatchTo;
    double wp = 1/(Math.pow(10, (Math.abs(currentRating - opponentRating) * Math.sqrt(matchLevel)/2000)) + 1);
    matchValue = 4*Math.sqrt(matchLevel);

    if (currentRating <= opponentRating) {
      currentRating += matchValue * (1-wp);
    }
    else {
      currentRating += matchValue * wp;
    }
    updatePreferences(Math.round((currentRating - CONVERT_ADDENDUM) * 100) / 100d );
    long score = (long)((currentRating - CONVERT_ADDENDUM) * 100);

    if (MatchState.matchType == 2) {
      FourInALine.Instance.nativeFunctions.gserviceSubmitRating(score, MULTI_BOARD);
    } else if (MatchState.matchType == 0) {
      FourInALine.Instance.nativeFunctions.gserviceSubmitRating(score, SINGLE_BOARD);
    }
  }
  
  private void updatePreferences(double newRating) {
    if (newRating<0) newRating=0.00; //FIX ON OLD RATING CALCULATOR
    if (MatchState.matchType == 3) {
      FourInALine.Instance.gameOptionPrefs.putString("MULTIBOARD", newRating + "");
    } else if (MatchState.matchType == 0) {
      FourInALine.Instance.gameOptionPrefs.putString("SINGLEBOARD", newRating + "");
    }
    
    FourInALine.Instance.gameOptionPrefs.flush();
    FourInALine.Instance.nativeFunctions.gserviceUpdateState();
  }

}




Java Source Code List

android.UnusedStub.java
it.alcacoop.fourinaline.BaseGServiceApplication.java
it.alcacoop.fourinaline.FourInALineDesktop.java
it.alcacoop.fourinaline.FourInALine.java
it.alcacoop.fourinaline.GServiceApplication.java
it.alcacoop.fourinaline.GServiceInterface.java
it.alcacoop.fourinaline.MainActivity.java
it.alcacoop.fourinaline.NativeFunctions.java
it.alcacoop.fourinaline.PrivateDataManager.java
it.alcacoop.fourinaline.PurchaseActivity.java
it.alcacoop.fourinaline.SoundManager.java
it.alcacoop.fourinaline.actors.BoardImage.java
it.alcacoop.fourinaline.actors.Board.java
it.alcacoop.fourinaline.actors.ChatBox.java
it.alcacoop.fourinaline.actors.Checker.java
it.alcacoop.fourinaline.actors.FixedButtonGroup.java
it.alcacoop.fourinaline.actors.IconButton.java
it.alcacoop.fourinaline.actors.ParticleEffectActor.java
it.alcacoop.fourinaline.actors.PlayerBlock.java
it.alcacoop.fourinaline.actors.UIDialog.java
it.alcacoop.fourinaline.billingutils.Base64DecoderException.java
it.alcacoop.fourinaline.billingutils.Base64.java
it.alcacoop.fourinaline.billingutils.IabException.java
it.alcacoop.fourinaline.billingutils.IabHelper.java
it.alcacoop.fourinaline.billingutils.IabResult.java
it.alcacoop.fourinaline.billingutils.Inventory.java
it.alcacoop.fourinaline.billingutils.Purchase.java
it.alcacoop.fourinaline.billingutils.Security.java
it.alcacoop.fourinaline.billingutils.SkuDetails.java
it.alcacoop.fourinaline.client.GwtLauncher.java
it.alcacoop.fourinaline.fsm.FSM.java
it.alcacoop.fourinaline.gservice.GServiceClient.java
it.alcacoop.fourinaline.gservice.GServiceCookieMonster.java
it.alcacoop.fourinaline.gservice.GServiceMessages.java
it.alcacoop.fourinaline.gservice.GServiceNetHandler.java
it.alcacoop.fourinaline.layers.BaseScreen.java
it.alcacoop.fourinaline.layers.GameScreen.java
it.alcacoop.fourinaline.layers.MatchOptionsScreen.java
it.alcacoop.fourinaline.layers.MenuScreen.java
it.alcacoop.fourinaline.layers.OptionsScreen.java
it.alcacoop.fourinaline.layers.SplashScreen.java
it.alcacoop.fourinaline.logic.AIExecutor.java
it.alcacoop.fourinaline.logic.MatchState.java
it.alcacoop.fourinaline.util.Base64DecoderException.java
it.alcacoop.fourinaline.util.Base64.java
it.alcacoop.fourinaline.util.GServiceGameHelper.java
it.alcacoop.fourinaline.util.GameHelperUtils.java
it.alcacoop.fourinaline.utils.AchievementsManager.java
it.alcacoop.fourinaline.utils.AppDataManager.java
it.alcacoop.fourinaline.utils.ELORatingManager.java
org.gojul.fourinaline.model.AlphaBeta.java
org.gojul.fourinaline.model.DefaultEvalScore.java
org.gojul.fourinaline.model.EvalScore.java
org.gojul.fourinaline.model.GameModel.java