Skip to content

Commit

Permalink
Document Elo class
Browse files Browse the repository at this point in the history
New: documentation for all Elo methods
  • Loading branch information
Zong Zheng Li committed Jul 26, 2013
1 parent fa82c1a commit 1d4a6e4
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Source/Utilities/Elo.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
using System;

namespace AbsoluteZero {

/// <summary>
/// Provides Elo calculation methods.
/// </summary>
static class Elo {

/// <summary>
/// The maximum magnitude for results.
/// </summary>
public const Int32 MaximumMagnitude = 999;
private const Double Sigma = 1.96;

/// <summary>
/// The standard deviation for the error bound calculations.
/// </summary>
private const Double Sigma = 1.96;

/// <summary>
/// Returns the difference in Elo between two players given wins, losses, and
/// draws between matches they've played.
/// </summary>
/// <param name="wins">The number of wins for the calculating player.</param>
/// <param name="losses">The number of losses for the calculating player.</param>
/// <param name="draws">The number of draws.</param>
/// <returns>The difference in Elo from the perspective of the calculating player.</returns>
public static Double GetDifference(Int32 wins, Int32 losses, Int32 draws) {
return GetDifference((wins + .5 * draws) / (wins + losses + draws));
}

/// <summary>
/// Returns the difference in Elo between two players given one of their
/// scores where score = (wins + draws / 2) / n and n is the number of
/// matches played.
/// </summary>
/// <param name="score">The score of the calculating player.</param>
/// <returns>The difference in Elo from the perspective of the calculating player.</returns>
public static Double GetDifference(Double score) {
Double value = -400 * Math.Log10(1 / score - 1);
if (Math.Abs(value) > MaximumMagnitude)
return Math.Sign(value) * MaximumMagnitude;
return value;
}

/// <summary>
/// Returns the error bound for the Elo difference calculation between two
/// players given the wins, losses, and draws between matches they've
/// played.
/// </summary>
/// <param name="wins">The number of wins for the calculating player.</param>
/// <param name="losses">The number of losses for the calculating player.</param>
/// <param name="draws">The number of draws.</param>
/// <returns>The error bound for the Elo difference calculation. </returns>
public static Double GetError(Int32 wins, Int32 losses, Int32 draws) {
Double totalGames = wins + losses + draws;
Double score = (wins + .5 * draws) / totalGames;
Expand Down

0 comments on commit 1d4a6e4

Please sign in to comment.