public IEvent SpawnEvent(Card card, Guid squadId, int minute, Models.Match match) { var oppositionsDefenceRating = RatingHelper.CurrentRating(PositionalArea.DEF, match.GetOppositionSquad(squadId), match.Events); var shootersRating = RatingHelper.CurrentRating(card.Id, match.GetSquad(squadId)); var shotOnTargetChance = (int)Math.Round(oppositionsDefenceRating + shootersRating * Constants.SHOOTER_AGAINST_DEFENDERS_MODIFIER); var randomNumber = _randomnessProvider.Next(0, shotOnTargetChance); if (randomNumber <= shootersRating * Constants.SHOOTER_AGAINST_DEFENDERS_MODIFIER) { var gkRating = RatingHelper.CurrentRating(PositionalArea.GK, match.GetOppositionSquad(squadId), match.Events); var goalChanceAccum = (int)Math.Round(gkRating + shootersRating * Constants.SHOOTER_AGAINST_GK_MODIFIER); var goalRandomNumber = _randomnessProvider.Next(0, goalChanceAccum); if (goalRandomNumber <= shootersRating * Constants.SHOOTER_AGAINST_GK_MODIFIER) { return(new Goal(minute, card.Id, squadId)); } return(new ShotOnTarget(minute, card.Id, squadId)); } return(new ShotOffTarget(minute, card.Id, squadId)); }
public IEvent SpawnEvent(Card card, Guid squadId, Models.Match.Match match) { var oppositionsDefenceRating = _ratingService.CurrentRating(PositionalArea.DEF, match, match.GetOppositionSquad(squadId)); var shootersRating = _ratingService.CurrentRating(card.Id, match, match.GetSquad(squadId)); var shotOnTargetChance = (int)Math.Round(oppositionsDefenceRating + shootersRating * Constants.ShooterAgainstDefendersModifier); var randomNumber = _randomnessProvider.Next(0, shotOnTargetChance); if (randomNumber <= shootersRating * Constants.ShooterAgainstDefendersModifier) { var gkRating = _ratingService.CurrentRating(PositionalArea.GK, match, match.GetOppositionSquad(squadId)); var goalChanceAccum = (int)Math.Round(gkRating + shootersRating * Constants.ShooterAgainstGkModifier); var goalRandomNumber = _randomnessProvider.Next(0, goalChanceAccum); if (goalRandomNumber <= shootersRating * Constants.ShooterAgainstGkModifier) { return(new Goal(card.Id, squadId)); } return(new ShotOnTarget(card.Id, squadId)); } return(new ShotOffTarget(card.Id, squadId)); }
public Card RollCard(Squad team, IAction action, MatchMinute[] minutes) { PositionalArea positionalArea = ChanceHelper.PercentBase100Chance(action.PositionalChance, x => x.Value).Key; var sentOffCardIds = minutes.SelectMany(x => x.Events).Where(x => x is RedCard).Select(x => x.CardId); var cards = team.Lineup[positionalArea.ToString()].Where(x => x != null && !sentOffCardIds.Contains(x.Id)).ToList(); int r = _randomnessProvider.Next(cards.Count); return(cards.ElementAtOrDefault(r)); //returns null TODO fix rolling position with 0 cards due to sending off }
public IEvent SpawnEvent(Card card, Guid squadId, Models.Match.Match match) { int randomNumber = _randomnessProvider.Next(1, 40); if (randomNumber == 1) { return(new RedCard(card.Id, squadId)); } if (randomNumber >= 2 && randomNumber < 5) { var yellowCards = match.Minutes.SelectMany(x => x.Events).Where(x => x is YellowCard).Select(x => x.CardId); if (yellowCards.Contains(card.Id)) { return(new RedCard(card.Id, squadId)); //TODO return yellow and red event } return(new YellowCard(card.Id, squadId)); } if (randomNumber >= 5) { return(new Events.Foul(card.Id, squadId)); } return(null); }
private float CalculateFitnessDrain() { return(0.01f * _randomnessProvider.Next(100)); //TODO drain based on position }