You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/03/25 22:54:50 UTC

svn commit: r1305126 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo: EloRankingCalculator.java PlayersRank.java

Author: simonetripodi
Date: Sun Mar 25 20:54:49 2012
New Revision: 1305126

URL: http://svn.apache.org/viewvc?rev=1305126&view=rev
Log:
virtualize the way to get/set the player ranking

Added:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java   (with props)
Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java?rev=1305126&r1=1305125&r2=1305126&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/EloRankingCalculator.java Sun Mar 25 20:54:49 2012
@@ -22,7 +22,6 @@ package org.apache.commons.graph.elo;
 import static java.lang.Math.pow;
 
 import org.apache.commons.graph.DirectedGraph;
-import org.apache.commons.graph.Mapper;
 
 final class EloRankingCalculator<P>
 {
@@ -35,12 +34,12 @@ final class EloRankingCalculator<P>
 
     private final DirectedGraph<P, GameResult> tournamentGraph;
 
-    private final Mapper<P, Double> playerRanking;
+    private final PlayersRank<P> playerRanking;
 
     private final int kFactor;
 
     public EloRankingCalculator( DirectedGraph<P, GameResult> tournamentGraph,
-                                 Mapper<P, Double> playerRanking, int kFactor )
+                                 PlayersRank<P> playerRanking, int kFactor )
     {
         this.tournamentGraph = tournamentGraph;
         this.playerRanking = playerRanking;
@@ -105,7 +104,7 @@ final class EloRankingCalculator<P>
     private void updateRanking( P player, double kFactor, double sFactor, double eFactor )
     {
         double newRanking = playerRanking.map( player ) + ( kFactor * ( sFactor - eFactor ) );
-        // TODO find a way to set the new calculated ranking to the current player
+        playerRanking.update( player, newRanking );
     }
 
 }

Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java?rev=1305126&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java Sun Mar 25 20:54:49 2012
@@ -0,0 +1,30 @@
+package org.apache.commons.graph.elo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Mapper;
+
+public interface PlayersRank<P>
+    extends Mapper<P, Double>
+{
+
+    void update( P player, Double ranking );
+
+}

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/elo/PlayersRank.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain