public void Delete(Match match) { _matches.Remove(match); }
public void Add(Match match) { _matches.Add(match); }
public void Add(Match match) { Db.Matches.Add(match); }
private void VerifyMatch(Match match, bool commit=true) { match.Winner.Rating += match.WinnerRatingDelta; match.Loser.Rating += match.LoserRatingDelta; if (match.Tied) { match.Winner.Ties += 1; match.Loser.Ties += 1; match.Winner.Streak = match.Loser.Streak = 0; } else { match.Loser.Loses += 1; match.Loser.Streak = 0; match.Winner.Wins += 1; match.Winner.Streak += 1; } match.Verified = true; match.Resolved = DateTime.Now; if (commit) _repository.CommitChanges(); }
public Match GenerateMatch(int boardId, string winnerName, string loserName, bool tie = false) { var board = _repository.GetBoardByIdWithCompetitors(boardId); if(board == null) throw (new ServiceException("Can not find challenge board.")); if (DateTime.Now >= board.End) throw (new ServiceException("This challenge board has ended.")); var winner = board.Competitors.Active().FindCompetitorByName(winnerName); var loser = board.Competitors.Active().FindCompetitorByName(loserName); if(winner == null) throw (new ServiceException("You are not part of this challenge board.")); if (loser == null) throw (new ServiceException("Can not find opponent.")); if (loser.Name == winner.Name) throw (new ServiceException("You can't play yourself.")); var match = new Match { Board = board, Tied = tie, Winner = winner, Loser = loser, Created = DateTime.Now, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification) }; var unresolvedMatches = _repository.GetUnresolvedMatchesByBoardId(boardId, false).ToList(); // Figure unverified ratings. Parses and sums unverified matches var unverifiedWinnerRank = winner.CalculateUnverifiedRank(unresolvedMatches); var unverifiedLoserRank = loser.CalculateUnverifiedRank(unresolvedMatches); // Run scoring calculation IScoringSystem system = new StandardElo(); var eloResult = system.Calculate(board.StartingRating, unverifiedWinnerRank, unverifiedLoserRank, tie); match.WinnerRatingDelta = eloResult.WinnerDelta.RoundToWhole(); match.LoserRatingDelta = eloResult.LoserDelta.RoundToWhole(); match.WinnerEstimatedRating = unverifiedWinnerRank + match.WinnerRatingDelta; match.LoserEstimatedRating = unverifiedLoserRank + match.LoserRatingDelta; return (match); }
public static IRepository CreatePopulatedRepository() { var repository = new InMemoryRepository(); var competitorOwnerProfile = new UserProfile { UserId = 0, UserName = "******" }; var competitorProfile1 = new UserProfile { UserId = 1, UserName = "******" }; var competitorProfile2 = new UserProfile { UserId = 2, UserName = "******" }; var boardOwner = new Competitor { Name = competitorOwnerProfile.UserName, ProfileUserId = 0, Profile = competitorOwnerProfile, Rating = 1500, }; var competitor1 = new Competitor { Name = competitorProfile1.UserName, ProfileUserId = 1, Profile = competitorProfile1, Rating = 1500, }; var competitor2 = new Competitor { Name = competitorProfile2.UserName, ProfileUserId = 2, Profile = competitorProfile2, Rating = 1500, }; var board = new Board { BoardId = 1, AutoVerification = 1, Created = DateTime.Now, Description = "Test Board", End = DateTime.Now.AddDays(30), Name = "Test Board", Owner = boardOwner, Started = DateTime.Now, StartingRating = 1500, Competitors = new[] { boardOwner, competitor1, competitor2 } }; // Unresolved match var match1 = new Match { Board = board, Created = DateTime.Now, Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 1, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Unresolved match var match2 = new Match { Board = board, Created = DateTime.Now, Loser = competitor1, Winner = competitor2, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 2, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Unresolved match var match3 = new Match { Board = board, Created = DateTime.Now, Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 3, LoserRatingDelta = -10, WinnerRatingDelta = 10 }; // Resolved Match [Verified] var match4 = new Match { Board = board, Created = DateTime.Now.AddDays(-7), Loser = competitor1, Winner = competitor2, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 4, LoserRatingDelta = -10, WinnerRatingDelta = 10, Resolved = DateTime.Now.AddHours(board.AutoVerification), Verified = true }; // Resolved Match [Rejected] var match5 = new Match { Board = board, Created = DateTime.Now.AddDays(-7), Loser = competitor2, Winner = competitor1, VerificationDeadline = DateTime.Now.AddHours(board.AutoVerification), MatchId = 4, LoserRatingDelta = -10, WinnerRatingDelta = 10, Resolved = DateTime.Now.AddHours(board.AutoVerification), Rejected = true }; board.Matches = new[] { match1, match2, match3 }; // Boards repository.Add(board); // User Profiles repository.Add(competitorOwnerProfile); repository.Add(competitorProfile1); repository.Add(competitorProfile2); // Competitors repository.Add(boardOwner); repository.Add(competitor1); repository.Add(competitor2); // Matches repository.Add(match1); repository.Add(match2); repository.Add(match3); repository.Add(match4); repository.Add(match5); return (repository); }