Elo system update
This commit is contained in:
64
Assets/Scripts/Game/EloSystem.cs
Normal file
64
Assets/Scripts/Game/EloSystem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
using Fusion;
|
||||
|
||||
namespace Hallucinate.Game
|
||||
{
|
||||
public static class EloSystem
|
||||
{
|
||||
public static EloResult Calculate(
|
||||
int ratingA, int ratingB,
|
||||
int gamesPlayedA, int gamesPlayedB,
|
||||
float resultA) // 1=win, 0=lose, 0.5=draw
|
||||
{
|
||||
float eA = 1f / (1f + Mathf.Pow(10f, (ratingB - ratingA) / 400f));
|
||||
int kA = GetK(ratingA, gamesPlayedA);
|
||||
int kB = GetK(ratingB, gamesPlayedB);
|
||||
|
||||
int nA = Mathf.Max(100, Mathf.RoundToInt(ratingA + kA * (resultA - eA)));
|
||||
int nB = Mathf.Max(100, Mathf.RoundToInt(ratingB + kB * ((1 - resultA) - (1 - eA))));
|
||||
|
||||
return new EloResult(nA, nB, nA - ratingA, nB - ratingB);
|
||||
}
|
||||
|
||||
private static int GetK(int r, int g) =>
|
||||
g < 30 ? 40 : r < 1200 ? 32 : r < 2000 ? 24 : 16;
|
||||
|
||||
public static string GetRank(int rating)
|
||||
{
|
||||
if (rating < 800) return "Iron";
|
||||
if (rating < 1000) return "Bronze";
|
||||
if (rating < 1200) return "Silver";
|
||||
if (rating < 1500) return "Gold";
|
||||
if (rating < 1800) return "Platinum";
|
||||
if (rating < 2100) return "Diamond";
|
||||
return "Master";
|
||||
}
|
||||
|
||||
public static string GetRankColor(int rating)
|
||||
{
|
||||
if (rating < 800) return "#8A8A8A";
|
||||
if (rating < 1000) return "#CD7F32";
|
||||
if (rating < 1200) return "#C0C0C0";
|
||||
if (rating < 1500) return "#FFD700";
|
||||
if (rating < 1800) return "#4DC8A0";
|
||||
if (rating < 2100) return "#7B6EE8";
|
||||
return "#E84D8A";
|
||||
}
|
||||
}
|
||||
|
||||
public struct EloResult : INetworkStruct
|
||||
{
|
||||
public int NewRatingA;
|
||||
public int NewRatingB;
|
||||
public int DeltaA;
|
||||
public int DeltaB;
|
||||
|
||||
public EloResult(int nA, int nB, int dA, int dB)
|
||||
{
|
||||
NewRatingA = nA;
|
||||
NewRatingB = nB;
|
||||
DeltaA = dA;
|
||||
DeltaB = dB;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user