public void UpdateScores(string winnerName) { // Rn = Ro + K(W - We) // We = 1 / (exp10(-dr / 400) + 1) var dao = new UserDAOService(); double avg = this.GetDifScore(); double add = 32 * (1 - (1 / (Math.Pow(10, -avg / 400) + 1))); double lose = 32 * (-(1 / (Math.Pow(10, -avg / 400) + 1))); int newScore; if (players.ContainsKey(winnerName)) { if (players[winnerName].IsComputer == false) { newScore = (int)Math.Round(dao.FindUserByName(winnerName).Score + add); dao.UpdateScore(winnerName, newScore); } } foreach (var p in players.Values) { if (!p.IsComputer) { if (p.ID != winnerName) { newScore = (int)Math.Round(dao.FindUserByName(p.ID).Score + lose); dao.UpdateScore(p.ID, newScore); } } } }
public double GetDifScore() { int min = 100000, max = -100000; var dao = new UserDAOService(); foreach (var player in players.Values) { var p = dao.FindUserByName(player.ID); int s = p == null?1000:p.Score; if (s < min) { min = s; } if (s > max) { max = s; } } return(max - min); }