public static void RunSimulations(SeasonSimulationOptions simulationOptions, IUnityContainer container, ILogger logger) { var stopwatch = new Stopwatch(); stopwatch.Start(); if (!string.IsNullOrWhiteSpace(simulationOptions.StrategyName)) { RegisterStrategyByName(container, simulationOptions.StrategyName); } if(simulationOptions.ListUsage) { ListUsage(); } else if (simulationOptions.CalculateTeamStrengthOnly) { CalculateTeamStrengths(container, logger); } else if (simulationOptions.CalculateHomeAdvantageRatioOnly) { CalculateHomeAdvantageRatio(container, logger); } else if (simulationOptions.CalculatePlayerFormOnly) { CalculatePlayerForm(container, logger); } else { RunSeasonSimulation(container, logger, simulationOptions); } stopwatch.Stop(); logger.Log(Tag.Progress, string.Format("Simulation time: {0}", stopwatch.Elapsed.ToFormatted())); }
public SeasonSimulationResult PerformSimulation(IStrategy strategy, SeasonSimulationOptions options) { if (strategy == null) throw new ArgumentNullException("strategy"); var allPlayers = GetPlayersForFirstGameweek(); var maxGameweek = CalculateMaxGameweek(options.MaximumGameweek); _logger.Log(Tag.Simulation, string.Concat("Max gameweek is ", maxGameweek)); var startingTeam = options.UseSavedInitialTeam ? SelectInitialTeamByIds(allPlayers, options.InitialTeamPlayerIds) : strategy.PickStartingTeam(allPlayers); _logger.Log(Tag.Simulation, "Starting team picked"); LogHelper.LogTeam(startingTeam, _logger); if (options.ChooseInitialTeamOnly) { return new SeasonSimulationResult(); } var seasonState = _decisionActioner.ValidateAndApplyStartingTeam(startingTeam, allPlayers); _logger.Log(Tag.Simulation, "Applied starting team"); return SimulateSeason(seasonState, strategy, maxGameweek); }
private static SeasonSimulationOptions CreateSimulationOptions(Arguments arguments) { var options = new SeasonSimulationOptions { CalculateTeamStrengthOnly = GetBoolArgument(arguments, ConsoleOptions.CalculateTeamStrengthsOnly), ChooseInitialTeamOnly = GetBoolArgument(arguments, ConsoleOptions.ChooseInitialTeamOnly), CalculatePlayerFormOnly = GetBoolArgument(arguments, ConsoleOptions.CalculatePlayerFormOnly), ListUsage = GetBoolArgument(arguments, ConsoleOptions.ListUsage), CalculateHomeAdvantageRatioOnly = GetBoolArgument(arguments, ConsoleOptions.CalculateHomeAdvantageOnly), UseSavedInitialTeam = GetBoolArgument(arguments, ConsoleOptions.UseSavedInitialTeam), StrategyName = GetStringArgument(arguments, ConsoleOptions.StrategyName) }; var maxGameweekString = arguments[ConsoleOptions.MaxGameweek]; if (!string.IsNullOrWhiteSpace(maxGameweekString)) { options.MaximumGameweek = int.Parse(maxGameweekString); } return options; }
public void SetUp() { _allPlayers = TeamCreationHelper.CreatePlayersWithPastFixtures(1); _playerServiceMock = new Mock<IMultiplePlayersService>(); _playerServiceMock.Setup(x => x.GetAllPlayers()).Returns(_allPlayers); _startingTeam = TeamCreationHelper.CreateTestTeam(); var startingSeasonState = new SeasonState { CurrentTeam = _startingTeam }; _strategyMock = new Mock<IStrategy>(); _strategyMock.Setup(x => x.MakeTransfers(It.IsAny<SeasonState>())).Returns((SeasonState seasonState) => new TransferActions()); _strategyMock.Setup(x => x.PickStartingTeam(It.IsAny<IList<Player>>())).Returns(_startingTeam); _strategyMock.Setup(x => x.PickGameweekTeam(It.IsAny<SeasonState>())).Returns(_startingTeam); _timeAdjustorMock = new Mock<ITimeAdjustor>(); _timeAdjustorMock.Setup(x => x.AdjustPlayersToGameweek(It.IsAny<IList<Player>>(), It.IsAny<int>())).Returns( (IList<Player> players, int gameweek) => players); _timeAdjustorMock.Setup(x => x.AdjustTeamToGameweek(It.IsAny<Team>(), It.IsAny<IList<Player>>(), It.IsAny<int>())).Returns( (Team team, IList<Player> players, int gameweek) => team); _gameweekSimulatorMock = new Mock<IGameweekSimulator>(); _gameweekSimulatorMock.Setup( x => x.CalculatePlayerPerformances(It.IsAny<Team>(), It.IsAny<int>(), It.IsAny<IList<Player>>())). Returns(new List<PlayerGameweekPerformance>()); _decisionActionerMock = new Mock<IDecisionActioner>(); _simulationOptions = new SeasonSimulationOptions(); _decisionActionerMock.Setup( x => x.ValidateAndApplyTransfers(It.IsAny<SeasonState>(), It.IsAny<TransferActions>())).Returns((SeasonState s, TransferActions a) => new TransferActionsResult{UpdatedSeasonState = s}); _decisionActionerMock.Setup(x => x.ValidateAndApplyStartingTeam(It.IsAny<Team>(), It.IsAny<IList<Player>>())).Returns(startingSeasonState); _decisionActionerMock.Setup(x => x.ValidateAndApplyGameweekTeamSelection(It.IsAny<SeasonState>(), It.IsAny<Team>())).Returns(startingSeasonState); _seasonSimulator = new SeasonSimulator(_playerServiceMock.Object, _timeAdjustorMock.Object, _gameweekSimulatorMock.Object, _decisionActionerMock.Object, new Mock<ILogger>().Object); }
private static void RunSeasonSimulation(IUnityContainer container, ILogger logger, SeasonSimulationOptions simulationOptions) { logger.Log(Tag.Progress, "Starting season simulation"); var strategy = container.Resolve<IStrategy>(); var simulator = container.Resolve<ISeasonSimulator>(); var result = simulator.PerformSimulation(strategy, simulationOptions); logger.Log(Tag.Progress, "Ending season simulation"); if (!simulationOptions.ChooseInitialTeamOnly) { logger.Log(Tag.Progress, string.Format("Total points: {0}", result.TotalPointsScored)); } }