private static MatchSimulationProcessState InitializeState(Match match, int goals, int ownGoals, bool local, List <FutbolPlayer> futbolPlayers) { var state = new MatchSimulationProcessState(); state.Match = match; state.Local = local; state.FinalState.OwnGoals = ownGoals; state.FinalState.FutbolPlayersProcessed = futbolPlayers.Count; state.ForwardsNumber = futbolPlayers.FindAll(fp => fp.Position == Position.Forward).Count; state.FinalState.ForwardGoals = (goals * random.Next(6, 10)) / 10; state.FinalState.ForwardsProccessed = state.ForwardsNumber; state.FinalState.OtherPositionGoals = goals - state.FinalState.ForwardGoals; state.FinalState.Changes = random.Next(0, Math.Min(SimulatorConstants.MaxChanges, futbolPlayers.Count - SimulatorConstants.PlayersOnTheField)); state.FinalState.MinutesPlayedBySubs = new int[state.FinalState.Changes]; state.FinalState.RedCards = random.Next(0, SimulatorConstants.MaxRedCards); return(state); }
private static MatchFutbolPlayerPerformance SimulateMatchFutbolPlayerPerformance(MatchSimulationProcessState state, FutbolPlayer futbolPlayer) { var playerPerformance = new MatchFutbolPlayerPerformance { ID = Guid.NewGuid().ToString(), MatchID = state.Match.ID, FutbolPlayerID = futbolPlayer.ID, Round = state.Match.Round, TournamentId = state.Match.TournamentId }; playerPerformance.Goals = AssignGoals(state, futbolPlayer); if (futbolPlayer.Position == Position.Forward) { state.CurrentState.ForwardGoals += playerPerformance.Goals; } else { state.CurrentState.OtherPositionGoals += playerPerformance.Goals; } if (futbolPlayer.Position == Position.Goalkeeper) { playerPerformance.Saves = GetIntBeetween(0, SimulatorConstants.MaxSaves); } playerPerformance.YellowCards = GetIntBeetween(0, state.CurrentState.RedCards == state.FinalState.RedCards ? 1 : 2); if (playerPerformance.YellowCards == 2) { playerPerformance.RedCards = 1; } else { playerPerformance.RedCards = state.CurrentState.RedCards == state.FinalState.RedCards ? 0 : GetIntBeetween(0, 1); } state.CurrentState.RedCards += playerPerformance.RedCards; playerPerformance.Faults = GetIntBeetween(0, SimulatorConstants.MaxFaults); if (playerPerformance.RedCards == 1 || HasToMakeAChange(state)) { playerPerformance.PlayedMinutes = GetIntBeetween(0, SimulatorConstants.MatchMinutes - 1); if (playerPerformance.RedCards == 0) { state.CurrentState.MinutesPlayedBySubs[^ state.CurrentState.Changes] = SimulatorConstants.MatchMinutes - playerPerformance.PlayedMinutes;