示例#1
0
        /// <summary>
        /// Gets the data that is displayed in the <see cref="Player"/>.
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        public PlayerScoreItem GetPlayerScoreItem(StandardMatch match)
        {
            var legs = this.GetLegs(match);

            this.LegsByPlayer = this.GetLegsByPlayer(legs).ToList();

            var score = match.Format - this.LegsByPlayer.Last().Scores.Sum();

            int legsWon;

            if (match.StandardMatchType == StandardMatchType.Sets)
            {
                legsWon = this.GetNumberWonLegsInSet(match);
            }
            else
            {
                legsWon = this.GetNumberWonLegs();
                ;
            }

            return(new PlayerScoreItem(
                       this.Player.Name,
                       score,
                       GetThrowoutAdvice(score),
                       this.LegsByPlayer.Last().DartsThrown.Sum(),
                       GetAverage(),
                       GetSetsWon(match),
                       legsWon));
        }
示例#2
0
        /// <summary>
        /// Gets the number of sets that are won by a player.
        /// </summary>
        /// <param name="match">The match for which the number of sets won has to be retrieved.</param>
        /// <returns>The number of sets won by the provided player.</returns>
        private int GetSetsWon(StandardMatch match)
        {
            if (match.StandardMatchType == StandardMatchType.Legs)
            {
                return(0);
            }

            var setsPlayed      = match.SetsPlayed.Value;
            var listOfLegsInSet = setsPlayed.Select(x => x.Legs);

            var setsCount = 0;

            foreach (var set in listOfLegsInSet)
            {
                var legByPlayersInSet = set.Select(x =>
                                                   x.LegByPlayers.Where(p => p.PlayerId == this.Player.Id.OrElse(this.Player.Name)))
                                        .SelectMany(x => x);

                if (legByPlayersInSet.Count(x => x.IsWon.OrElse(false)) == 3)
                {
                    setsCount++;
                }
            }

            return(setsCount);
        }
示例#3
0
        /// <summary>
        /// Gets the number of legs won in this set by this player.
        /// </summary>
        /// <returns>The number of legs won by this player.</returns>
        private int GetNumberWonLegsInSet(StandardMatch match)
        {
            var legsInLastSet     = match.SetsPlayed.Value.Last().Legs;
            var legsByPlayerInSet = legsInLastSet.SelectMany(x => x.LegByPlayers.Where(p => p.PlayerId == this.Player.Id.OrElse(this.Player.Name)));

            return(legsByPlayerInSet.Count(l => l.IsWon.OrElse(false)));
        }
示例#4
0
 /// <summary>
 /// Gets the latest basic match stats for the player. Will not get any stats regarding leg information, such as best leg etc.
 /// </summary>
 /// <param name="match">The match from which to retrieve the basic stats.</param>
 /// <returns>The latest match stats for the player.</returns>
 public PlayerMatchStats GetBasicStats(StandardMatch match)
 {
     this.LegsByPlayer = this.GetLegsByPlayer(this.GetLegs(match));
     return(new PlayerMatchStats
     {
         Average = this.GetAverage(),
         AverageFirstNine = this.GetAverageFirstNine(),
         HighestScore = this.GetHighestScore(),
         OneEighties = this.GetScoresBetween(180, 180),
         Plus100 = this.GetScoresBetween(100, 139),
         Plus140 = this.GetScoresBetween(140, 179),
         Plus80 = this.GetScoresBetween(80, 99),
     });
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of <see cref="MatchService"/>.
 /// </summary>
 /// <param name="match">The match for which this instance is created.</param>
 public MatchService(StandardMatch match)
 {
     this.StandardMatch = match;
     foreach (var player in match.Players)
     {
         if (player.PlayerType == PlayerType.Bot)
         {
             this.PlayerServices.Add(new BotPlayerService(player));
         }
         else if (player.PlayerType == PlayerType.Normal)
         {
             this.PlayerServices.Add(new NormalPlayerService(player));
         }
     }
 }
示例#6
0
        /// <summary>
        /// Gets the latest match stats for the player, except for a running leg.
        /// </summary>
        /// <param name="match">The match for which the stats have to be retrieved.</param>
        /// <remarks>Does not take running legs into account.</remarks>
        /// <returns>The latest match stats for the player.</returns>
        public PlayerMatchStats GetAllStats(StandardMatch match)
        {
            var legs = this.GetLegs(match);

            this.LegsByPlayer = this.GetLegsByPlayer(legs).ToList();

            return(new PlayerMatchStats
            {
                Average = this.GetAverage(),
                AverageBestLeg = this.GetAverageBestLeg(match),
                AverageFirstNine = this.GetAverageFirstNine(),
                BestLeg = this.GetBestLeg(),
                Breaks = this.GetBreaks(),
                HighestCheckout = this.GetHighestCheckout(),
                HighestScore = this.GetHighestScore(),
                Legs = this.GetNumberWonLegs(),
                Sets = this.GetSetsWon(match),
                OneEighties = this.GetScoresBetween(180, 180),
                Plus100 = this.GetScoresBetween(100, 139),
                Plus140 = this.GetScoresBetween(140, 179),
                Plus80 = this.GetScoresBetween(80, 99),
                WorstLeg = this.GetWorstLeg()
            });
        }
示例#7
0
        public void InitializeTest()
        {
            this.Players = new List <Player>()
            {
                new NormalPlayer("PlayerOne"),
                new NormalPlayer("PlayerTwo")
            };
            this.LegsMatch = new StandardMatch(StandardMatchType.Legs, Maybe <int> .Nothing, 6, 501, this.Players);
            this.SetsMatch = new StandardMatch(StandardMatchType.Sets, 3.ToMaybe(), 6, 501, this.Players);

            var leg1 = new Leg();

            leg1.LegByPlayers.Add(new LegByPlayer("PlayerTwo")
            {
                DartsThrown = { 5, 5, 5, 5 },
                HasStarted  = true,
                IsWon       = false.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 100, 140, 31
                }
            });
            leg1.LegByPlayers.Add(new LegByPlayer("PlayerTwo")
            {
                DartsThrown = { 5, 5, 5, 5 },
                HasStarted  = true,
                IsWon       = true.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 100, 140, 31
                }
            });
            var leg2 = new Leg();

            leg2.LegByPlayers.Add(new LegByPlayer("PlayerOne")
            {
                DartsThrown = { 5, 5, 5, 5, 1 },
                HasStarted  = false,
                IsWon       = false.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 100, 83, 42
                }
            });
            leg2.LegByPlayers.Add(new LegByPlayer("PlayerTwo")
            {
                DartsThrown = { 5, 5, 5, 5 },
                HasStarted  = false,
                IsWon       = true.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 100, 140, 31
                }
            });
            var leg3 = new Leg();

            leg3.LegByPlayers.Add(new LegByPlayer("PlayerOne")
            {
                DartsThrown = { 6, 6, 6, 6, 6, 6 },
                HasStarted  = true,
                IsWon       = false.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 8, 10, 31, 46, 30, 20
                }
            });
            leg3.LegByPlayers.Add(new LegByPlayer("PlayerTwo")
            {
                DartsThrown = { 5, 5, 5, 5 },
                HasStarted  = false,
                IsWon       = true.ToMaybe(),
                Scores      = new List <int> {
                    46, 83, 41, 60, 100, 140, 31
                }
            });
            this.Legs = new List <Leg> {
                leg1, leg1, leg3
            };
            this.LegsMatch.LegsPlayed = this.Legs.ToMaybe();
        }
示例#8
0
 /// <summary>
 /// Gets all the legs played during a match. Necessary since there are two types (i.e. sets and legs).
 /// </summary>
 /// <param name="match">The match from which to retrieve all the legs.</param>
 /// <returns>The legs played in the match</returns>
 private List <Leg> GetLegs(StandardMatch match)
 {
     return(match.StandardMatchType == StandardMatchType.Legs ?
            match.LegsPlayed.Value : match.SetsPlayed.Value.SelectMany(y => y.Legs).ToList());
 }
示例#9
0
 /// <summary>
 /// Get the remaining score for the specified player in the specified match.
 /// </summary>
 /// <returns>The remaining score for the provided player in the match</returns>
 public int GetRemainingScore(StandardMatch match)
 {
     this.LegsByPlayer = this.GetLegsByPlayer(this.GetLegs(match));
     return(match.Format - this.LegsByPlayer.Last().Scores.Sum());
 }
示例#10
0
 /// <summary>
 /// Gets the three dart average of a player over its best leg.
 /// </summary>
 /// <returns>The three dart average of the player over the best leg.</returns>
 private double GetAverageBestLeg(StandardMatch match)
 {
     return(this.GetBestLeg() == 0 ?
            0.00 :
            Math.Round(match.Format / (this.GetBestLeg() / 3.0), 2));
 }