private void UpdateTeamStatistics(Match match)
        {
            using (var seasonTeamStatsticsRepository = _repositoryFactory.CreateRepository<SeasonTeamStatistics>())
             {
            string seasonId = match.SeasonId;
            var homeTeamStatistics = seasonTeamStatsticsRepository.Find(x => x.TeamId == match.HomeTeamId && x.SeasonId == seasonId).Single();
            var awayTeamStatistics = seasonTeamStatsticsRepository.Find(x => x.TeamId == match.AwayTeamId && x.SeasonId == seasonId).Single();

            char homeMatchResult = 'D';
            char awayMatchResult = 'D';

            if (!match.EndedInDraw())
            {
               if (match.GetWinner().Id == homeTeamStatistics.TeamId)
               {
                  homeMatchResult = 'W';
                  awayMatchResult = 'L';
               }
               else
               {
                  homeMatchResult = 'L';
                  awayMatchResult = 'W';
               }
            }

            homeTeamStatistics.MatchResults += homeMatchResult + ",";
            awayTeamStatistics.MatchResults += awayMatchResult + ",";

            _repository.RegisterUpdate(homeTeamStatistics);
            _repository.RegisterUpdate(awayTeamStatistics);
             }
        }
Beispiel #2
0
        public void Play(Match match)
        {
            // Totally random match results for now...
             // Possible stuff contains 5 zeroes, 4 ones, 3 twos, 3 threes, etc.
             var possibleStuff = new Dictionary<int, float> { { 0, 5 }, { 1, 4 }, { 2, 3 }, { 3, 3 }, { 4, 2 }, { 5, 1 } };

             match.HomeScore = possibleStuff.RandomElementByWeight(x => x.Value).Key;
             match.AwayScore = possibleStuff.RandomElementByWeight(x => x.Value).Key;

             // Take penalty shoot out, if necessary.
             bool matchEndedInDraw = match.HomeScore == match.AwayScore;
             if (matchEndedInDraw && !match.DrawPermitted)
             {
            var possiblePenaltyScores = new Dictionary<int, float> { { 5, 5 }, { 4, 5 }, { 3, 4 }, { 2, 1 }, { 1, 1 } };

            match.HomePenaltyScore = possiblePenaltyScores.RandomElementByWeight(x => x.Value).Key;
            match.AwayPenaltyScore = possiblePenaltyScores.RandomElementByWeight(x => x.Value).Key;
            match.PenaltiesTaken = true;

            // Randomly pick a winner if the penalty shootout also ended undecisive.
            bool penaltyDraw = match.HomePenaltyScore == match.AwayPenaltyScore;
            if (penaltyDraw)
            {
               bool homeTeamWins = _randomizer.GetRandomBoolean();
               if (homeTeamWins)
               {
                  match.HomePenaltyScore++;
               }
               else
               {
                  match.AwayPenaltyScore++;
               }
            }
             }

             match.MatchStatus = MatchStatus.Ended;

             //TODO Onderstaande nog afmaken...

             // Determine the best team.
             //Team bestTeam = match.HomeTeam;
             //Team worstTeam = match.AwayTeam;
             //if (match.AwayTeam.Rating > match.HomeTeam.Rating)
             //{
             //   bestTeam = match.AwayTeam;
             //   worstTeam = match.HomeTeam;
             //}

             //// Determine difference between teams.
             //decimal ratio = bestTeam.Rating / worstTeam.Rating;

             //const decimal maxRatioWorstTeamCanWin = 2;
             //const decimal maxRatioDrawPossible = 2;

             //// Can the worst team win?
             //bool worstTeamCanWin = ratio <= maxRatioWorstTeamCanWin;
             //// Is a draw possible?
             //bool drawPossible = ratio <= maxRatioDrawPossible;
        }
Beispiel #3
0
 public Match Get(Match match)
 {
     using (var matchRepository = new RepositoryFactory().CreateMatchRepository())
      {
     // Get the match from the database.
     var foundMatch = matchRepository.GetOne(match.Id);
     return foundMatch;
      }
 }
Beispiel #4
0
        public static Match CreateMatch(Team homeTeam = null, Team awayTeam = null)
        {
            var match = new Match
             {
            DrawPermitted = true,
            HomeTeam = homeTeam,
            AwayTeam = awayTeam,
            MatchStatus = homeTeam == null && awayTeam == null ? MatchStatus.TeamsUndefined : MatchStatus.NotStarted
             };

             return match;
        }
Beispiel #5
0
        public static MatchResource Create(Match match)
        {
            var matchResource = new MatchResource(match.Id)
             {
            HomeScore = match.HomeScore,
            AwayScore = match.AwayScore,
            Date = match.Date.ToString(),
            Played = match.MatchStatus == MatchStatus.Ended,
            PenaltiesTaken = match.PenaltiesTaken
             };

             if (match.PenaltiesTaken)
             {
            matchResource.HomePenaltyScore = match.HomePenaltyScore;
            matchResource.AwayPenaltyScore = match.AwayPenaltyScore;
             }

             return matchResource;
        }
Beispiel #6
0
 private void Play(Match match)
 {
     // Check whether match still has to be played.
      bool matchCanBePlayed = match.MatchStatus == MatchStatus.NotStarted;
      if (matchCanBePlayed)
      {
     // Play match.
     new MatchPlayer().Play(match);
      }
      else
      {
     string message = $"Match with ID '{match.Id}' has already been played";
     throw new ConflictException(message);
      }
 }
Beispiel #7
0
        private MatchResource GetMatchResource(Match match)
        {
            var links = new TeamLinks(match.HomeTeamId);
             var homeTeamResource = TeamResourceFactory.Create(match.HomeTeam, links, false);

             links = new TeamLinks(match.AwayTeamId);
             var awayTeamResource = TeamResourceFactory.Create(match.AwayTeam, links, false);

             string competitionName = match.Round.CompetitionName;
             string roundName = match.Round.Name;

             var matchResource = MatchResourceFactory.Create(match);
             matchResource.HomeTeam = homeTeamResource;
             matchResource.AwayTeam = awayTeamResource;
             matchResource.Competition = competitionName;
             matchResource.Round = roundName;

             return matchResource;
        }
Beispiel #8
0
 /// <summary>
 /// Determines whether the specified match already exists in the list of matches by looking at the home and away teams.
 /// </summary>
 /// <param name="matches">The matches.</param>
 /// <param name="match">The match.</param>
 /// <returns>True or false.</returns>
 public static bool MatchExists(this List<Match> matches, Match match)
 {
     return matches.Any(m => (m.HomeTeam.Equals(match.HomeTeam) && m.AwayTeam.Equals(match.AwayTeam))
                               || (m.HomeTeam.Equals(match.AwayTeam) && m.AwayTeam.Equals(match.HomeTeam)));
 }