//Compare two lineups in a specific way. private void CompareLineups(TeamMatch lower, TeamMatch higher, bool isLower, PlayersToCompare compare, RankingCompareType rankingType) { //Get players in the team matches. var lowerPlayerPositions = GetPlayerPositions(lower, true); var higherPlayerPositions = GetPlayerPositions(higher, true); foreach (var lowerPlayerPosition in lowerPlayerPositions) { //Find positions to compare with. Dictionary <Player, List <Lineup.PositionType> > playersPositionsToCompare = GetPlayerPositionsToCompare(lowerPlayerPosition, higherPlayerPositions, compare); //Compare 2 positions. foreach (var higherPlayerPos in playersPositionsToCompare) { //If rankingtype is level, compare the players' levels. //Else, compare category points in the positions that the upper player plays in. if (rankingType == RankingCompareType.Level) { if (!CheckPoints(lowerPlayerPosition.Key.Rankings.LevelPoints, higherPlayerPos.Key.Rankings.LevelPoints)) { AddRuleBreaks(lower, lowerPlayerPosition.Key, higher, higherPlayerPos.Key, isLower); } } else { if (!CompareAbovePlayerPositions(lowerPlayerPosition, higherPlayerPos, rankingType)) { AddRuleBreaks(lower, lowerPlayerPosition.Key, higher, higherPlayerPos.Key, isLower); } } } } }
private async Task <CareerPlayerTeamStatistic> Load(TeamMatch teamMatch, GameXPlayer playerGame) { var teamID = this.DetermineOposingTeamID(teamMatch, playerGame); var statistic = await this._careerPlayerTeamStatisticRepository.Get(playerGame.Game.AssociationID, playerGame.Player.ID, playerGame.Game.SeasonID, teamID); if (statistic == null) { statistic = new CareerPlayerTeamStatistic { Association = new Association { ID = playerGame.Game.AssociationID }, Party = new Common.Domain.Entities.Player { ID = playerGame.Player.ID }, Season = new Season { ID = playerGame.Game.SeasonID }, Team = new Common.Domain.Entities.Team { ID = teamID } }; } return(statistic); }
public List <RuleBreak> Rule(TeamMatch match) { _ruleBreaks = new List <RuleBreak>(); Dictionary <int, int> playerCount; foreach (var group in match.Lineup) { playerCount = new Dictionary <int, int>(); foreach (var pos in group.Positions) { if (pos.Player != null) { if (!playerCount.ContainsKey(pos.Player.Member.Id)) { playerCount.Add(pos.Player.Member.Id, 0); } playerCount[pos.Player.Member.Id]++; } if (Lineup.PositionType.Double.HasFlag(group.Type) && pos.OtherPlayer != null) { if (!playerCount.ContainsKey(pos.OtherPlayer.Member.Id)) { playerCount.Add(pos.OtherPlayer.Member.Id, 0); } playerCount[pos.OtherPlayer.Member.Id]++; } } playerCount.Where(p => p.Value > 1).ToList().ForEach(p => AddRuleBreaks(p.Key, group)); } return(_ruleBreaks); }
public List <RuleBreak> Rule(TeamMatch match) { _ruleBreaks = new List <RuleBreak>(); foreach (var group in match.Lineup) { for (int i = 0; i < group.Positions.Count; i++) { var pos = group.Positions[i]; if (group.Type == Lineup.PositionType.MixDouble) { CheckMixSex(pos, i); } else { if (pos.Player != null && !SexGood(group.Type, pos.Player.Sex)) { _ruleBreaks.Add(new RuleBreak((group.Type, i), 0, "Player sex does not match position!")); } if (Lineup.PositionType.Double.HasFlag(group.Type) && pos.OtherPlayer != null && !SexGood(group.Type, pos.OtherPlayer.Sex)) { _ruleBreaks.Add(new RuleBreak((group.Type, i), 1, "Player sex does not match position!")); } } } } return(_ruleBreaks); }
private async Task <CareerTeamStatistic> Load(TeamMatch teamMatch, Common.Domain.Entities.Team team) { var key = new CareerTeamStatistic { Party = new Common.Domain.Entities.Team() { ID = team.ID }, Season = new Season() { ID = teamMatch.TeamFixture.Season.ID }, CompetitionEventTypeID = teamMatch.TeamFixture.CompetitionRound.CompetitionEvent.CompetitionEventTypeID, CompetitionID = teamMatch.TeamFixture.CompetitionID }; var statistic = await this._careerTeamStatisticRepository.Get(key); if (statistic == null) { statistic = new CareerTeamStatistic { Party = new Common.Domain.Entities.Team { ID = team.ID }, Season = new Season { ID = teamMatch.TeamFixture.Season.ID }, CompetitionEventTypeID = teamMatch.TeamFixture.CompetitionRound.CompetitionEvent.CompetitionEventTypeID, CompetitionID = teamMatch.TeamFixture.CompetitionID }; } return(statistic); }
public async Task OverrideAndCalculate(TeamMatch match, short homeGames, short homeChalks, short awayGames, short awayChalks, MatchCalculationEngine engineConfiguration) { match.HomeGameScore = homeGames; match.HomeChalkScore = homeChalks; match.AwayGameScore = awayGames; match.AwayChalkScore = awayChalks; if (match.HomeChalkHandicap.HasValue) { match.HomeChalkScore += match.HomeChalkHandicap; } if (match.AwayChalkHandicap.HasValue) { match.AwayChalkScore += match.AwayChalkHandicap; } if (engineConfiguration.BonusPointTypeID != BonusPointTypes.None) { this.CalculateBonusPoints(match, engineConfiguration); } var resultEngine = await this._matchResultCalculationEngineFactory.Create(engineConfiguration.MatchResultCalculationEngineID); await resultEngine.Calculate(match); match.SetComplete(); }
public async Task Remove(TeamMatch teamMatch, GameXPlayer playerGame) { var data = await this.Load(teamMatch, playerGame); data.Remove(playerGame); await this._careerPlayerTeamStatisticRepository.Save(data); }
public List <RuleBreak> Rule(TeamMatch match) { _ruleBreaks = new List <RuleBreak>(); foreach (var group in match.Lineup) { CheckPositions(group.Positions, group.Type); } return(_ruleBreaks); }
/// <summary> /// Adds or updates a TeamMatch /// </summary> /// <param name="match"> TeamMatch </param> public void AddOrUpdateTeamMatch(TeamMatch match) { if (backend.MatchList.Contains(match)) { backend.MatchList.Remove(match); } backend.MatchList.Add(match); backend.SubmitmatchListChanges(); UpdateScores(); UpdateRankings(); }
//Compares 2 lineups for rulebreaks. private void CompareLineups(TeamMatch match, TeamMatch otherMatch) { //Finds the higher ranked match and compares according to those rules. if (match.TeamIndex > otherMatch.TeamIndex) { CompareLineupByLeague(match, otherMatch, true); } else { CompareLineupByLeague(otherMatch, match, false); } }
public void TestTeamMatchType() { PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var teamMatch1 = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 1, 2 } }; var teamMatch2 = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Competition, dateTime = teamMatch1.dateTime, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 1, 2 } }; Assert.AreEqual(teamMatch1, teamMatch2, " - TeamMatch Equals does not return true for cloned matches"); Assert.IsTrue(teamMatch1 == teamMatch2, " - TeamMatch '==' does not return true for cloned matches"); player3 = new PlayerType() { Name = "test5", Mail = "test5", Tag = "test5" }; player4 = new PlayerType() { Name = "test5", Mail = "test6", Tag = "test6" }; team2 = new TeamType() { Name = "team3", Members = new List<PlayerType>() { player3, player4 } }; teamMatch2 = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 3, 4 } }; Assert.AreNotEqual(teamMatch1, teamMatch2, " - TeamMatch Equals returns true for different teammatches"); Assert.IsTrue(teamMatch1 != teamMatch2, " - TeamMatch '!=' does not return true for different teammatches"); }
private string GetMatchResultLabel(TeamMatch tm) { Common.EResult result = (Common.EResult)Enum.Parse(typeof(Common.EResult), tm.Result.ToString()); switch (result) { case Common.EResult.Draw: return "<span style='color: blue;'>R </span>"; case Common.EResult.Loose: return "<span style='color: red;'>P </span>"; case Common.EResult.Win: return "<span style='color: green;'>Z </span>"; default: return string.Empty; } }
public void TestGetMatches() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; PlayerType player5 = new PlayerType() { Name = "test5", Mail = "test5", Tag = "test5" }; PlayerType player6 = new PlayerType() { Name = "test6", Mail = "test6", Tag = "test6" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); playerLogic.AddOrUpdatePlayer(player5); playerLogic.AddOrUpdatePlayer(player6); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.Solo }; var game2 = new GameType() { Name = "game2", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); gameLogic.AddOrUpdateGame(game2); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var team3 = new TeamType() { Name = "team3", Members = new List<PlayerType>() { player5, player6 } }; var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; var match2 = new SoloMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player3 }, Scores = new List<int>() { 1, 2 } }; var match3 = new TeamMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); matchLogic.AddOrUpdateSoloMatch(match2); matchLogic.AddOrUpdateTeamMatch(match3); var matches = matchLogic.GetMatches(game2, ParticipantTypes.All, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 2) && (matches.Contains(match2)) && (matches.Contains(match3))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.Solo, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 1) && (matches.Contains(match2))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.Team, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 1) && (matches.Contains(match3))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.All, MatchCategories.Competition); Assert.IsTrue((matches.Count == 0), " - MatchManipulator \"GetMatches\" Not OK"); }
public void TestSimpleTeamMatchManipulations() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var teamLogic = (ITeamManipulations)getInterfaceImplementation(typeof(ITeamManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.Team }; var game2 = new GameType() { Name = "game2", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); gameLogic.AddOrUpdateGame(game2); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var match1 = new TeamMatch() { GameID = game1, Category = MatchCategories.Competition, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateTeamMatch(match1); matchLogic = null; matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); Assert.IsTrue(matchLogic.GetMatchesAll(game1).Contains(match1), " - MatchManipulator does not persist new TeamMatch"); var match = matchLogic.GetMatchesAll(game1).First() as TeamMatch; match.Scores = new List<int>() { 2, 3 }; matchLogic.AddOrUpdateTeamMatch(match); matchLogic = null; matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); Assert.IsTrue((((matchLogic.GetMatchesAll(game1).First() as TeamMatch).Scores.Contains(2)) && ((matchLogic.GetMatchesAll(game1).First() as TeamMatch).Scores.Contains(2))), " - MatchManipulator does not persist TeamMatch changes"); }
public void TestTeamTournamentGamePoints() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var teamLogic = (ITeamManipulations)getInterfaceImplementation(typeof(ITeamManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); var rankingLogic = (IRankingSource)getInterfaceImplementation(typeof(IRankingSource)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; PlayerType player5 = new PlayerType() { Name = "test5", Mail = "test5", Tag = "test5" }; PlayerType player6 = new PlayerType() { Name = "test6", Mail = "test6", Tag = "test6" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); playerLogic.AddOrUpdatePlayer(player5); playerLogic.AddOrUpdatePlayer(player6); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var team3 = new TeamType() { Name = "team3", Members = new List<PlayerType>() { player5, player6 } }; var match1 = new TeamMatch() { GameID = game1, Category = MatchCategories.Tournament, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2, team3 }, Scores = new List<int>() { 1, 3, 2 } }; matchLogic.AddOrUpdateTeamMatch(match1); var rankings = rankingLogic.GetGameRankingsAll(game1, ParticipantTypes.All); Assert.IsTrue(rankings.Count == 6, $" - getGameRankingsAll, expected count = {4}, was: {rankings.Count}"); foreach (var player in team1.Members) { var rank = rankings.Where(r => r.Player == player).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 0, $" - getGameRankingsAll, points: expected 0, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); } foreach (var player in team2.Members) { var rank = rankings.Where(r => r.Player == player).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 12, $" - getGameRankingsAll, points: expected 12, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); } foreach (var player in team3.Members) { var rank = rankings.Where(r => r.Player == player).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 6, $" - getGameRankingsAll, points: expected 6, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); } }
public void TestMatchSerialisation() { var DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); ClearAllData(DAL); Assert.IsNotNull(DAL.MatchList, "DAL property \"RankingList\" is null after calling \"ClearAllData\""); Assert.IsTrue(DAL.MatchList.Count == 0, "DAL property \"RankingList\" is not empty after calling \"ClearAllData\""); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; var soloMatch = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; DAL.MatchList.Add(soloMatch); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var teamMatch = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 3, 4 } }; DAL.MatchList.Add(teamMatch); Assert.IsTrue(DAL.MatchList.Count == 2, "Count for DAL property \"MatchList\" != 2 after adding two matches."); DAL.SubmitmatchListChanges(); // destroy DAL & force reload from files... DAL = null; DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); Assert.IsNotNull(DAL.MatchList, "DAL property \"MatchList\" is null after creating a new instance of the DAL."); Assert.IsTrue(DAL.MatchList.Count == 2, "Added matches were not persisted."); bool soloMatchFound = false; bool teamMatchFound = false; for (int i = 0; i < 2; i++) { if (DAL.MatchList[i] is SoloMatch) { soloMatchFound = true; var match = DAL.MatchList[i] as SoloMatch; Assert.AreEqual(match.GameID,soloMatch.GameID, $"SoloMatch.GameID not OK after serialisation. Expected: {soloMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, soloMatch.Category, $"SoloMatch.Category not OK after serialisation. Expected: {soloMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, soloMatch.dateTime, $"SoloMatch.dateTime not OK after serialisation. Expected: {soloMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Players[0], soloMatch.Players[0], $"SoloMatch.Players[0] not OK after serialisation. Expected: {soloMatch.Players[0]}, was: {match.Players[0]}"); Assert.AreEqual(match.Scores[1], soloMatch.Scores[1], $"SoloMatch.Scores[1] not OK after serialisation. Expected: {soloMatch.Scores[1]}, was: {match.Scores[1]}"); } else if (DAL.MatchList[i] is TeamMatch) { teamMatchFound = true; var match = DAL.MatchList[i] as TeamMatch; Assert.AreEqual(match.GameID, teamMatch.GameID, $"TeamMatch.GameID not OK after serialisation. Expected: {teamMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, teamMatch.Category, $"TeamMatch.Category not OK after serialisation. Expected: {teamMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, teamMatch.dateTime, $"TeamMatch.dateTime not OK after serialisation. Expected: {teamMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Teams[0].Name, teamMatch.Teams[0].Name, $"TeamMatch.Teams[0] not OK after serialisation. Expected: {teamMatch.Teams[0]}, was: {match.Teams[0]}"); Assert.AreEqual(match.Scores[1], teamMatch.Scores[1], $"TeamMatch.Scores[1] not OK after serialisation. Expected: {teamMatch.Scores[1]}, was: {match.Scores[1]}"); } } Assert.IsTrue(soloMatchFound, "SoloMatch not persisted"); Assert.IsTrue(teamMatchFound, "TeamMatch not persisted"); }
public void AddOrUpdateTeamMatch(TeamMatch match) { throw new NotImplementedException(); }