Ejemplo n.º 1
0
        public GoalAttempt RecordGoalAttempt(RecordGoalAttemptRequest request)
        {
            Round round = _context.Rounds.FirstOrDefault(r => r.RoundId == request.GoalAttempt.RoundId);

            round.SecondsRemaining = request.SecondsRemaining;
            RfCountToRouteAndGame currentRfCountToRouteAndGame = _context.RfToRouteAndGameList.FirstOrDefault(rf => rf.RouteId == request.GoalAttempt.RouteId && rf.GameId == round.GameId);

            currentRfCountToRouteAndGame.Value += 1;

            if (!round.Practice)
            {
                List <RfCountToRouteAndGame> otherRfCountToRouteAndGameList = _context.RfToRouteAndGameList.Where(rf => rf.GameId == round.GameId && rf.RouteId != request.GoalAttempt.RouteId).ToList();
                double sum = otherRfCountToRouteAndGameList.Sum(rf => rf.Value) + currentRfCountToRouteAndGame.Value;

                double newRf = currentRfCountToRouteAndGame.Value / sum;
                if (newRf <= 0.0825)
                {
                    //Score a goal!
                    request.GoalAttempt.ScoredGoal      = true;
                    currentRfCountToRouteAndGame.Value *= 0.95;
                    otherRfCountToRouteAndGameList.ForEach(rf => rf.Value *= 0.95);
                }
                else
                {
                    //Did not score a goal
                    request.GoalAttempt.ScoredGoal = false;
                }
            }
            else
            {
                request.GoalAttempt.ScoredGoal = new Random().Next(100) < 50;
            }

            _context.GoalAttempts.Add(request.GoalAttempt);
            _context.SaveChanges();
            return(request.GoalAttempt);
        }
Ejemplo n.º 2
0
 public GoalAttempt RecordGoalAttempt(RecordGoalAttemptRequest request)
 {
     return(_service.RecordGoalAttempt(request));
 }