示例#1
0
        /// <summary>
        /// Calculates the matches for the shot
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IShotResult> Calculate(int targetDistance)
        {
            var shotList = new ShotResultList(10);

            foreach (var club in this.clubs)
            {
                var clubShots = GetShotsForClub(club, targetDistance);

                shotList.AddCandidateShotRange(clubShots);
            }

            return shotList.Shots;
        }
示例#2
0
        private IEnumerable<IShotResult> GetShotsForClub(IClub club, int targetDistance)
        {
            var clubShotList = new ShotResultList(10);

            var shotTypes = Enum.GetValues(typeof(ShotType)).Cast<ShotType>();
            foreach (var shotType in shotTypes)
            {
                var windAdjuster = this.windAdjusterFactory.GetWindAdjuster(shotType);

                var stepCount = club.GetStepCountForShotType(shotType);

                for (var i = 0; i < stepCount; i++)
                {
                    var methods = new Func<ShotType, int, int>[] {club.GetDistance, club.GetHalfDistance };

                    for (var index = 0; index < methods.Length; index++)
                    {
                        var method = methods[index];
                        var distance = method(shotType, i);

                        var step = index == 1 ? i + 0.5d : i;
                        if (distance > 0)
                        {
                            var windAdjustedDistance = windAdjuster.GetWindAdjustedDistance(distance);
                            var distanceToTarget = Math.Abs(windAdjustedDistance - targetDistance);
                            var result = new ShotResult()
                            {
                                ClubName = club.Name,
                                Step = step,
                                ShotType = shotType,
                                Distance = distance,
                                WindDistance = windAdjustedDistance,
                                DistanceToTarget = distanceToTarget,
                                IsWithinRange = distanceToTarget <= MaximumDistance
                            };
                            clubShotList.AddCandidateShot(result);
                        }
                    }
                }
            }

            return clubShotList.Shots;
        }