Exemplo n.º 1
0
    private void UpdateVisual()
    {
        var openedLevels = Profile.GetSeasonProgress(CurrentSeason);

        if (season == null)
        {
            seasonState = SeasonState.Null;
        }
        else
        {
            seasonProgress = openedLevels / (float)season.levelCount;
            if (openedLevels < season.levelCount)
            {
                seasonState = SeasonState.Progressing;
            }
            else if (Profile.GetSeasonRewarded(CurrentSeason) < 1)
            {
                seasonState = SeasonState.CanClaimReward;
            }
            else
            {
                seasonState = SeasonState.Completed;
            }

            GlobalFactory.Theme.Select(season.id);
            themeImage.sprite = GlobalFactory.Theme.Selected.previewBackground;
        }

        title.SetFormatedText(CurrentSeason + 1);
        chestButton.gameObject.SetActive(seasonState == SeasonState.Progressing || seasonState == SeasonState.CanClaimReward);
        claimReward.SetActive(seasonState == SeasonState.CanClaimReward);
        comingSoon.SetActive(seasonState == SeasonState.Null);

        progressImage.fillAmount = 0.1f + 0.8f * seasonProgress;
        progressHighlight.SetActive(seasonProgress > 0.7f);

        if (seasonProgress > 0.8f)
        {
            chestAnimation.Play();
        }
        else
        {
            chestAnimation.Stop();
            chestAnimation.transform.AsRectTransform().localRotation = Quaternion.identity;
        }

        CheckTutorial();


        if (GlobalConfig.DebugMode)
        {
            nextButton.SetInteractable(season != null);
            prevButton.SetInteractable(CurrentSeason > 0);
        }
        else
        {
            nextButton.SetInteractable(season != null && Profile.GetSeasonRewarded(season.id) > 0);
            prevButton.SetInteractable(CurrentSeason > 0);
        }
    }
Exemplo n.º 2
0
 public void Apply(SeasonCreatedEvent @event)
 {
     base.Id          = new Identity(@event.SeasonId);
     this.divisions   = new List <Division>();
     this.Number      = 1;
     this.StartDate   = @event.StartDate;
     this.SeasonState = SeasonState.Proposed;
 }
Exemplo n.º 3
0
 void IInitializable.Initialize()
 {
     SeasonState
     .Where(SeasonMaster.Exists)
     .Select(SeasonMaster.FindText)
     .Subscribe(SignalBus.Fire);
     SeasonState
     .Where(SeasonMaster.Exists)
     .Select(SeasonMaster.FindColor)
     .Subscribe(SignalBus.Fire);
 }
        public TransferActions SelectTransfers(SeasonState seasonState)
        {
            _geneticTransferSelector.SetSeedGenes(seasonState);

            var allTransferActions = _geneticTransferSelector.Run();

            var topTransferActions = allTransferActions.Take(1).ToList();

            LogHelper.LogTopTransferActions(topTransferActions, _logger);

            return topTransferActions.First();
        }
 public void SetUp()
 {
     _transferActions = new List<FitTransferActions>
                   {
                       new FitTransferActions(),
                       new FitTransferActions()
                   };
     _seasonState = new SeasonState();
     _geneticAlgorithmMock = new Mock<IGeneticAlgorithm<FitTransferActions, SeasonState>>();
     _geneticAlgorithmMock.Setup(x => x.Run()).Returns(_transferActions);
     _selectorStrategy = new TransferSelectorStrategy(_geneticAlgorithmMock.Object, new Mock<ILogger>().Object);
 }
        public Team PickGameweekTeam(SeasonState seasonState)
        {
            var predictedPlayerScores =
                seasonState.CurrentTeam.Players.Select(
                    p => new PredictedPlayerScore{Player = p, PredictedScore =
                    _playerScorePredictor.PredictPlayerGameweekPoints(p, seasonState.Gameweek, seasonState.AllPlayers)}).ToList();

            var teamSelection = _teamGameweekSelector.SelectStartingTeamForGameweek(predictedPlayerScores);

            LogHelper.LogTeamSelection(teamSelection, seasonState.Gameweek, predictedPlayerScores, _logger, true);

            return teamSelection.Team;
        }
        public void SetUp()
        {
            _gameweek = 1;
            _team = TeamCreationHelper.CreateTestTeam();
            _allPlayers = new List<Player>();
            _seasonState = new SeasonState {CurrentTeam = _team, AllPlayers = _allPlayers, Gameweek = _gameweek};

            _intitialTeamSelectorMock = new Mock<IInitialTeamSelectorStrategy>();
            _playerScorePredictorMock = new Mock<IPlayerScorePredictor>();
            _teamGameweekSelectorMock = new Mock<ITeamGameweekSelector>();
            _transferSelectorStrategyMock = new Mock<ITransferSelectorStrategy>();

            _complexStrategy = new ComplexStrategy(new Mock<ILogger>().Object, _intitialTeamSelectorMock.Object, _playerScorePredictorMock.Object, _teamGameweekSelectorMock.Object, _transferSelectorStrategyMock.Object);
        }
        public void SetUp()
        {
            _originalSeasonState = new SeasonState
                                   {
                                       AllPlayers = TeamCreationHelper.CreatePlayerList(5, 5, 5, 5),
                                       CurrentTeam = TeamCreationHelper.CreateTestTeam(),
                                       FreeTransfers = 5,
                                       Gameweek = 2,
                                       Money = 200,
                                       StandardWildCardPlayed = true,
                                       TransferWindowWildcardPlayed = true
                                   };

            _clonedSeasonState = _originalSeasonState.ShallowClone();
        }
        public SeasonState ValidateAndApplyGameweekTeamSelection(SeasonState seasonState, Team selectedTeam)
        {
            if(seasonState == null)throw new ArgumentNullException("seasonState");
            if(selectedTeam == null)throw new ArgumentNullException("selectedTeam");

            if (selectedTeam.Validity != TeamValidationStatus.Valid)
            {
                throw new InvalidTeamException(selectedTeam.Validity);
            }

            //team now valid so update
            seasonState.CurrentTeam = selectedTeam;

            return seasonState;
        }
        public TransferActionsResult ValidateAndApplyTransfers(SeasonState seasonState, TransferActions transferActions)
        {
            if (seasonState == null) throw new ArgumentNullException("seasonState");
            if (transferActions == null) throw new ArgumentNullException("transferActions");

            var transferValidity = _transferValidator.ValidateTransfers(seasonState, transferActions);
            if(transferValidity != TransferValidity.Valid)
            {
                throw new InvalidTransferException(transferValidity);
            }

            _transferActioner.VerboseLoggingEnabled = true;
            var result = _transferActioner.ApplyTransfers(seasonState, transferActions);

            return result;
        }
        public TransferValidity ValidateTransfers(SeasonState seasonState, TransferActions transferActions)
        {
            if (seasonState.Gameweek == 1 && transferActions.Transfers.Any())
            {
                return TransferValidity.NoTransfersAllowedInFirstGameweek;
            }

            foreach (var transfer in transferActions.Transfers)
            {
                var transferValidity = CheckTransferValidity(transfer, seasonState.CurrentTeam);
                if (transferValidity != TransferValidity.Valid)
                {
                    return transferValidity;
                }
            }

            if (transferActions.Transfers.DistinctBy(t => t.PlayerIn.Id).Count() != transferActions.Transfers.Count)
            {
                return TransferValidity.PlayerTransferredInMultipleTimes;
            }

            if (transferActions.Transfers.DistinctBy(t => t.PlayerOut.Id).Count() != transferActions.Transfers.Count)
            {
                return TransferValidity.PlayerTransferredOutMultipleTimes;
            }

            var wildcardValidity = CheckWildcardValidity(seasonState, transferActions);
            if(wildcardValidity != TransferValidity.Valid)
            {
                return wildcardValidity;
            }

            if(!TeamCanAffordTransfers(seasonState, transferActions))
            {
                return TransferValidity.NotEnoughMoney;
            }

            var teamVailidity = CheckResultingTeamValidity(seasonState, transferActions);
            if(teamVailidity != TeamValidationStatus.Valid)
            {
                return TransferValidity.LeavesTeamInInvalidState;
            }

            return TransferValidity.Valid;
        }
        public TransferActionsResult ApplyTransfers(SeasonState seasonState, TransferActions transferActions)
        {
            var actionResults = new TransferActionsResult();

            if (VerboseLoggingEnabled)
            {
                _logger.Log(Tag.Transfers, string.Format("Applying gameweek {0} transfers", seasonState.Gameweek), true);
            }

            //set transferred in player cost
            foreach (var transfer in transferActions.Transfers)
            {
                seasonState.CurrentTeam = ProcessTransfer(transfer, seasonState.CurrentTeam);
            }

            seasonState.CurrentTeam.EnsureValidCaptains();

            actionResults.TotalTransfersMade = transferActions.Transfers.Count;

            actionResults.PenalisedTransfersMade = Math.Max(transferActions.Transfers.Count - seasonState.FreeTransfers, 0);
            seasonState.Money = CommonTransferFunctions.CalculateUpdatedTeamMoney(transferActions.Transfers, seasonState.Money);

            if (VerboseLoggingEnabled)
            {
                _logger.Log(Tag.Transfers, string.Format("Total transfers made: {0}", actionResults.TotalTransfersMade));
                _logger.Log(Tag.Transfers, string.Format("Penalised transfers made: {0}", actionResults.PenalisedTransfersMade));
                _logger.Log(Tag.Transfers, string.Format("Updated money: {0}", seasonState.Money.ToMoney()));
            }

            UpdateFreeTransfers(transferActions, seasonState);

            actionResults.UpdatedSeasonState = seasonState;

            actionResults = ApplyWildcards(seasonState, transferActions, actionResults);

            return actionResults;
        }
        private static void UpdateFreeTransfers(TransferActions actions, SeasonState seasonState)
        {
            //transfers carry over if you're playing wildcard
            if (!actions.PlayTransferWindowWildcard && !actions.PlayStandardWildcard)
            {
                //deduct the transfers made
                seasonState.FreeTransfers -= actions.Transfers.Count;

                //you can never have negative free transfers
                seasonState.FreeTransfers = Math.Max(seasonState.FreeTransfers, 0);

                //add on one transfer for new game week
                seasonState.FreeTransfers++;

                //add one another free transfer if you didn't make any this week
                if (actions.Transfers.Count == 0)
                {
                    seasonState.FreeTransfers++;
                }

                //you can only ever have a max of two free transfers
                seasonState.FreeTransfers = Math.Min(seasonState.FreeTransfers, 2);
            }
        }
        private TeamValidationStatus CheckResultingTeamValidity(SeasonState seasonState, TransferActions transferActions)
        {
            var clonedSeasonState = seasonState.ShallowClone();

            _transferActioner.VerboseLoggingEnabled = false;
            var result = _transferActioner.ApplyTransfers(clonedSeasonState, transferActions);
            return result.UpdatedSeasonState.CurrentTeam.Validity;
        }
        private SeasonState UpdateSeasonStateToGameweek(SeasonState seasonState, int gameweek)
        {
            seasonState.Gameweek = gameweek;

            var allUpToDatePlayers = _playerService.GetAllPlayers();

            seasonState.CurrentTeam = _timeAdjustor.AdjustTeamToGameweek(seasonState.CurrentTeam, allUpToDatePlayers,
                                                                                seasonState.Gameweek);
            seasonState.AllPlayers = _timeAdjustor.AdjustPlayersToGameweek(allUpToDatePlayers, seasonState.Gameweek);

            return seasonState;
        }
 public Team PickGameweekTeam(SeasonState seasonState)
 {
     return seasonState.CurrentTeam;
 }
Exemplo n.º 17
0
 public void Apply(SeasonStartedEvent @event)
 {
     this.SeasonState = SeasonState.Started;
 }
Exemplo n.º 18
0
 private void SeasonTimeOnEndCounter(object sender, EventArgs eventArgs)
 {
     State = SeasonState.ReleaseWaiting;
     RelaseWait.Start();
 }
Exemplo n.º 19
0
 private void PreStartOnEndCounter(object sender, EventArgs eventArgs)
 {
     State = SeasonState.Started;
     CurrentSeason.Start();
 }
 public TransferActions MakeTransfers(SeasonState seasonState)
 {
     return _transferSelectorStrategy.SelectTransfers(seasonState);
 }
        public void SetUp()
        {
            _geneticParametersMock = new Mock<IGeneticParameters>();
            _geneticParametersMock.SetupGet(x => x.PopulationSize).Returns(5);
            // run test as single threaded so we can predict outcome and test logic
            _geneticParametersMock.SetupGet(x => x.MaxDegreeOfParallelism).Returns(1);

            _teamScorePredictorMock = new Mock<ITeamScorePredictor>();

            _team = TeamCreationHelper.CreateTestTeam();

            _seasonState = new SeasonState
                           {
                               CurrentTeam = _team,
                               AllPlayers = TeamCreationHelper.CreatePlayerList(10, 10, 10, 10)
                           };

            _transferActionerMock = new Mock<ITransferActioner>();
            _transferActionerMock.Setup(x => x.ApplyTransfers(It.IsAny<SeasonState>(), It.IsAny<TransferActions>())).
               Returns(new TransferActionsResult { UpdatedSeasonState = _seasonState });

            _randomMock = new Mock<IRandom>();

            _transferValidatorMock = new Mock<ITransferValidator>();

            _predictorParametersMock = new Mock<IPredictorParameters>();

            _playerPoolReducerMock = new Mock<IPlayerPoolReducer>();
            _playerPoolReducerMock.Setup(x => x.ReducePlayerPool(_seasonState.AllPlayers)).Returns(
                _seasonState.AllPlayers);

            _transferSelector = new GeneticTransferSelector(_geneticParametersMock.Object,
                _randomMock.Object,
                new Mock<ILogger>().Object,
                _transferValidatorMock.Object,
                _teamScorePredictorMock.Object,
                _predictorParametersMock.Object,
                _transferActionerMock.Object,
                _playerPoolReducerMock.Object);

            _transferSelector.SetSeedGenes(_seasonState);
        }
        private TransferActionsResult ApplyWildcards(SeasonState seasonState, TransferActions actions, TransferActionsResult result)
        {
            if (actions.PlayStandardWildcard)
            {
                if (VerboseLoggingEnabled)
                {
                    _logger.Log(Tag.Transfers, "Standard wildcard played", true);
                }
                seasonState.StandardWildCardPlayed = true;
                result.PenalisedTransfersMade = 0;
            }
            else if (actions.PlayTransferWindowWildcard)
            {
                if (VerboseLoggingEnabled)
                {
                    _logger.Log(Tag.Transfers, "Transfer window wildcard played", true);
                }
                seasonState.TransferWindowWildcardPlayed = true;
                result.PenalisedTransfersMade = 0;
            }

            return result;
        }
        private TransferValidity CheckWildcardValidity(SeasonState seasonState, TransferActions transferActions)
        {
            if (transferActions.PlayStandardWildcard && seasonState.StandardWildCardPlayed)
            {
               return TransferValidity.WildcardPlayedTwice;
            }

            if (transferActions.PlayTransferWindowWildcard)
            {
                if (seasonState.TransferWindowWildcardPlayed)
                {
                    return TransferValidity.WildcardPlayedTwice;
                }

                var insideTransferWindowWildcardPeriod = IsInsideTransferWindow(seasonState.Gameweek);
                if (!insideTransferWindowWildcardPeriod)
                {
                    return TransferValidity.WildcardPlayedOutsideWindow;
                }
            }

            return TransferValidity.Valid;
        }
 private bool TeamCanAffordTransfers(SeasonState seasonState, TransferActions transferActions)
 {
     var newMoneyValue = CommonTransferFunctions.CalculateUpdatedTeamMoney(transferActions.Transfers,
                                                                           seasonState.Money);
     return newMoneyValue >= 0;
 }
        private StrategyDecisionsResult ProcessStrategyDecisions(SeasonState seasonState, IStrategy strategy)
        {
            var updatedSeasonState = seasonState;

            var transferActions = new TransferActions();
            var transferResults = new TransferActionsResult();

            //no transfers in first gameweek
            if (seasonState.Gameweek > 1)
            {
                transferActions = strategy.MakeTransfers(updatedSeasonState);
                transferResults = _decisionActioner.ValidateAndApplyTransfers(updatedSeasonState, transferActions);
                updatedSeasonState = transferResults.UpdatedSeasonState;
            }

            var selectedTeamForGameweek = strategy.PickGameweekTeam(updatedSeasonState);
            updatedSeasonState = _decisionActioner.ValidateAndApplyGameweekTeamSelection(updatedSeasonState, selectedTeamForGameweek);

            return new StrategyDecisionsResult
                   {
                       TransfersMade = transferActions,
                       TransferResults = transferResults,
                       UpdatedSeasonState = updatedSeasonState
                   };
        }
Exemplo n.º 26
0
        public override void Start()
        {
            this.Left = PreStart.Left + CurrentSeason.Left + RelaseWait.Left;

            State = SeasonState.PreStartWaiting;
            PreStart.Start();
        }
        public void SetUp()
        {
            _seasonState = new SeasonState
            {
                Gameweek = 2,
                FreeTransfers = 1,
                CurrentTeam = TeamCreationHelper.CreateTestTeam(4, 3, 3, Position.Defender,
                                                                                        Position.Midfielder,
                                                                                        Position.Midfielder)

            };
            _transferActions = new TransferActions();

            _transferValidatorMock = new Mock<ITransferValidator>();
            _transferActionerMock = new Mock<ITransferActioner>();

            _decisionActioner = new DecisionActioner(_transferActionerMock.Object, _transferValidatorMock.Object);

            _allPlayers = new List<Player>();
        }
Exemplo n.º 28
0
 private void RelaseWaitOnEndCounter(object sender, EventArgs eventArgs)
 {
     State = SeasonState.Ended;
 }
 private IList<PlayerGameweekPerformance> CalculatePlayerGameweekPerformances(SeasonState seasonState)
 {
     var allPlayers = _playerService.GetAllPlayers();
     return _gameweekSimulator.CalculatePlayerPerformances(seasonState.CurrentTeam, seasonState.Gameweek, allPlayers);
 }
        private SeasonSimulationResult SimulateSeason(SeasonState startingSeasonState, IStrategy strategy, int maxGameweek)
        {
            var seasonState = startingSeasonState;

            var result = new SeasonSimulationResult();
            for (int gameweek = 1; gameweek <= maxGameweek; gameweek++)
            {
                _logger.Log(Tag.Simulation, string.Concat("Simulating gameweek ", gameweek), true);
                _logger.Log(Tag.Simulation, string.Concat("Current points total: ", result.TotalPointsScored), true);
                _logger.Log(Tag.Simulation, string.Concat("Available money: ", seasonState.Money.ToMoney()), true);
                _logger.Log(Tag.Simulation, string.Concat("Free transfers: ", seasonState.FreeTransfers), true);

                seasonState = UpdateSeasonStateToGameweek(seasonState, gameweek);

                var strategyDecisionResult = ProcessStrategyDecisions(seasonState, strategy);

                seasonState = strategyDecisionResult.UpdatedSeasonState;

                var playerPerformances = CalculatePlayerGameweekPerformances(seasonState);

                var gameweekPerformance = new TeamGameweekPerformance
                                          {
                                              PlayerPerformances = playerPerformances,
                                              TransferActions = strategyDecisionResult.TransfersMade,
                                              TransferResults = strategyDecisionResult.TransferResults,
                                              Gameweek = gameweek
                                          };

                result.GameweekResults.Add(gameweekPerformance);

                _logger.Log(Tag.Result,
                            string.Concat("Total player points scored in gameweek ", gameweek, ": ",
                                            gameweekPerformance.TotalPlayerPointsScored), true);
                _logger.Log(Tag.Result,
                           string.Concat("Transfer penalty points in gameweek ", gameweek, ": ",
                                           gameweekPerformance.TransferResults.TransferPointsPenalty), true);

                _logger.Log(Tag.Result,
                           string.Concat("Total points for gameweek ", gameweek, ": ",
                                           gameweekPerformance.TotalPointsScored), true);
            }

            OutputResult(result);

            return result;
        }
        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);
        }
        public void SetUp()
        {
            _seasonState = new SeasonState
                               {
                                   CurrentTeam = TeamCreationHelper.CreateTestTeam(),
                                   AllPlayers = TeamCreationHelper.CreatePlayerList(10,10,10,10, startingId: 100),
                                   Gameweek = 2
                               };
            _transferActions = new TransferActions();

            _transferActionerMock = new Mock<ITransferActioner>();
            _transferActionerMock.Setup(x => x.ApplyTransfers(It.IsAny<SeasonState>(), It.IsAny<TransferActions>())).
                Returns((SeasonState s, TransferActions t) => new TransferActionsResult{UpdatedSeasonState = s});

            _configSettingsMock = new Mock<IConfigurationSettings>();
            _transferValidator = new TransferValidator(_configSettingsMock.Object, _transferActionerMock.Object);
        }
 public TransferActions MakeTransfers(SeasonState seasonState)
 {
     //do nothing
     return new TransferActions ();
 }