public void RecalculatePoints(IDataContext dataContext, IPointsCalculator pointsCalculator, List<PlayedGameToRecalculate> playedGamesToRecalculate)
        {
            int counter = 0;
            foreach (var playedGame in playedGamesToRecalculate)
            {
                var playerRanks = playedGame.PlayerGameResults.Select(x => new PlayerRank
                {
                    PlayerId = x.PlayerId,
                    GameRank = x.GameRank
                }).ToList();

                var newPoints = pointsCalculator.CalculatePoints(playerRanks, playedGame.BoardGameGeekGameDefinition);

                var applicationUserForThisGamingGroup = new ApplicationUser()
                {
                    CurrentGamingGroupId = playedGame.GamingGroupId
                };

                foreach (var playerGameResult in playedGame.PlayerGameResults)
                {
                    var scorecard = newPoints[playerGameResult.PlayerId];
                    playerGameResult.NemeStatsPointsAwarded = scorecard.BasePoints;
                    playerGameResult.GameDurationBonusPoints = scorecard.GameDurationBonusPoints;
                    playerGameResult.GameWeightBonusPoints = scorecard.GameWeightBonusPoints;
                    dataContext.Save(playerGameResult, applicationUserForThisGamingGroup);
                }

                Debug.WriteLine("{0} games updated... last PlayedGame.Id is {1}", ++counter, playedGame.PlayedGameId);
            }
        }
        public void RecalculatePoints(IDataContext dataContext, IPointsCalculator pointsCalculator, List <PlayedGameToRecalculate> playedGamesToRecalculate)
        {
            int counter = 0;

            foreach (var playedGame in playedGamesToRecalculate)
            {
                var playerRanks = playedGame.PlayerGameResults.Select(x => new PlayerRank
                {
                    PlayerId = x.PlayerId,
                    GameRank = x.GameRank
                }).ToList();

                var newPoints = pointsCalculator.CalculatePoints(playerRanks, playedGame.BoardGameGeekGameDefinition);

                var applicationUserForThisGamingGroup = new ApplicationUser()
                {
                    CurrentGamingGroupId = playedGame.GamingGroupId
                };

                foreach (var playerGameResult in playedGame.PlayerGameResults)
                {
                    var scorecard = newPoints[playerGameResult.PlayerId];
                    playerGameResult.NemeStatsPointsAwarded  = scorecard.BasePoints;
                    playerGameResult.GameDurationBonusPoints = scorecard.GameDurationBonusPoints;
                    playerGameResult.GameWeightBonusPoints   = scorecard.GameWeightBonusPoints;
                    dataContext.Save(playerGameResult, applicationUserForThisGamingGroup);
                }

                Debug.WriteLine("{0} games updated... last PlayedGame.Id is {1}", ++counter, playedGame.PlayedGameId);
            }
        }
        public void Initialize(GameSettings gameSettings,
                               InputController inputController,
                               LocalStorage.LocalStorage localStorage,
                               SoundController soundController,
                               ISequenceChecker sequenceChecker,
                               IPointsCalculator pointsCalculator)
        {
            _gameSettings    = gameSettings;
            _inputController = inputController;
            _localStorage    = localStorage;
            _soundController = soundController;
            _sequenceChecker = sequenceChecker;

            _pointsCalculator       = pointsCalculator;
            _gemSelectionController = new GemSelectionController(_inputController);
            _gridController         = gameObject.AddComponent <GridController>();
            _gridController.Initialize(_gameGrid, _gameSettings, sequenceChecker);

            _gemSelectionController.OnSelectionComplete.AddListener(
                (first, second) => StartCoroutine(ChangeGemsPosition(first, second)));
            _gemSelectionController.OnSelectionInvalid.AddListener(InvalidMove);
            _gridController.OnSequence.AddListener(CalculatePoints);

            ContextProvider.Context.OnPause.AddListener(Pause);
        }
Exemplo n.º 4
0
        public static bool DetermineIfUserCanWin(Round round, RoundPlayer player, IPointsCalculator pointCalculator)
        {
            HandWorth handWorth = pointCalculator.Calculate(round, player.GamePlayer.Player.UserName);

            if (handWorth == null)
            {
                return(false);
            }
            return(handWorth.Points >= round.Game.MinPoint);
        }
Exemplo n.º 5
0
 public OrderService(IOrderFactory orderFactory,
                     ICustomerOrdersRepository customerOrdersRepository, IUnitOfWork unitOfWork,
                     IPointsCalculator pointsCalculator, IDiscountCalculator discountCalculator)
 {
     this.orderFactory             = orderFactory;
     this.customerOrdersRepository = customerOrdersRepository;
     this.unitOfWork         = unitOfWork;
     this.pointsCalculator   = pointsCalculator;
     this.discountCalculator = discountCalculator;
 }
 public CoordinateGameplay(ILogger <CoordinateGameplay> logger, IPlayWar gamePlay,
                           IPointsCalculator pointsCalculator, ITrackIndividualGameState individualGameStateTracker,
                           IDateTime dateTime, ICompileStats statsCompiler)
 {
     _logger                     = logger;
     _gamePlay                   = gamePlay;
     _pointsCalculator           = pointsCalculator;
     _individualGameStateTracker = individualGameStateTracker;
     _dateTime                   = dateTime;
     _statsCompiler              = statsCompiler;
 }
Exemplo n.º 7
0
        public static void CheckSelfAction(Round round, RoundPlayer roundPlayer, IPointsCalculator pointsCalculator)
        {
            if (DetermineIfUserCanWin(round, roundPlayer, pointsCalculator))
            {
                roundPlayer.RoundPlayerActions.Add(new RoundPlayerAction {
                    ActionType = ActionType.SelfWin
                });
            }

            CheckPossibleSelfKong(round, roundPlayer);
        }
Exemplo n.º 8
0
        public GameFixture()
        {
            MainPlayerUserName = "******";
            OtherPlayerName    = "south";
            GameId             = 1;
            RoundId            = 1;

            CreateBaseData();
            PointCalculator  = new HomeGameCalculator(new ExtraPointBuilder(), new HandTypeBuilder());
            MainPlayerRound  = TestDataContext.Rounds.First().RoundPlayers.First(u => u.GamePlayer.Player.UserName == MainPlayerUserName);
            OtherPlayerRound = TestDataContext.Rounds.First().RoundPlayers.First(u => u.GamePlayer.Player.UserName == OtherPlayerName);
        }
        public void PlaceOrder(Order order, IPointsCalculator pointsCalculator, IDiscountCalculator discountCalculator = null)
        {
            NewOrder = order;

            if (order == null)
            {
                return;
            }

            order.SetCustomerId(CustomerId);

            order.ApplyDiscount(discountCalculator, ExistingPoints);
            NewPoints = order.GetPoints(pointsCalculator);
        }
Exemplo n.º 10
0
        public void RecalculateAllPoints(IDataContext dataContext, IPointsCalculator pointsCalculator, int startPlayedGameId, int endPlayedGameId = int.MaxValue)
        {
            var allPlayedGames = (from PlayedGame playedGame in dataContext.GetQueryable <PlayedGame>()
                                  where playedGame.Id >= startPlayedGameId && playedGame.Id < endPlayedGameId
                                  select new PlayedGameToRecalculate
            {
                PlayedGameId = playedGame.Id,
                GamingGroupId = playedGame.GamingGroupId,
                PlayerGameResults = playedGame.PlayerGameResults,
                BoardGameGeekGameDefinition = playedGame.GameDefinition.BoardGameGeekGameDefinition
            }).OrderBy(x => x.PlayedGameId).ToList();

            RecalculatePoints(dataContext, pointsCalculator, allPlayedGames);
        }
Exemplo n.º 11
0
        public void RecalculateAllPoints(IDataContext dataContext, IPointsCalculator pointsCalculator, int startPlayedGameId, int endPlayedGameId = int.MaxValue)
        {
            var allPlayedGames = (from PlayedGame playedGame in dataContext.GetQueryable<PlayedGame>()
                                  where playedGame.Id >= startPlayedGameId && playedGame.Id < endPlayedGameId
                                  select new PlayedGameToRecalculate
                                  {
                                      PlayedGameId = playedGame.Id,
                                      GamingGroupId = playedGame.GamingGroupId,
                                      PlayerGameResults = playedGame.PlayerGameResults,
                                      BoardGameGeekGameDefinition = playedGame.GameDefinition.BoardGameGeekGameDefinition
                                  }).OrderBy(x => x.PlayedGameId).ToList();

            RecalculatePoints(dataContext, pointsCalculator, allPlayedGames);
        }
Exemplo n.º 12
0
 public PlayedGameSaver(
     IDataContext applicationDataContext,
     ISecuredEntityValidator securedEntityValidator,
     IPointsCalculator pointsCalculator,
     IApplicationLinker applicationLinker,
     IBusinessLogicEventSender businessLogicEventSender, IWinnerTypeCalculator winnerTypeCalculator)
 {
     _dataContext              = applicationDataContext;
     _securedEntityValidator   = securedEntityValidator;
     _pointsCalculator         = pointsCalculator;
     _applicationLinker        = applicationLinker;
     _businessLogicEventSender = businessLogicEventSender;
     _winnerTypeCalculator     = winnerTypeCalculator;
 }
Exemplo n.º 13
0
        public void RecalculateAllPointsForGamesWithNoPlayTime(IDataContext dataContext, IPointsCalculator pointsCalculator)
        {
            var allPlayedGames = (from PlayedGame playedGame in dataContext.GetQueryable<PlayedGame>()
                                  where (playedGame.GameDefinition.BoardGameGeekGameDefinition == null 
                                  || (playedGame.GameDefinition.BoardGameGeekGameDefinition.MinPlayTime == null
                                        && playedGame.GameDefinition.BoardGameGeekGameDefinition.MaxPlayTime == null))
                                  select new PlayedGameToRecalculate
                                  {
                                      PlayedGameId = playedGame.Id,
                                      GamingGroupId = playedGame.GamingGroupId,
                                      PlayerGameResults = playedGame.PlayerGameResults,
                                      BoardGameGeekGameDefinition = null
                                  }).OrderBy(x => x.PlayedGameId).ToList();

            RecalculatePoints(dataContext, pointsCalculator, allPlayedGames);
        }
Exemplo n.º 14
0
 public PlayedGameSaver(
     IDataContext applicationDataContext,
     INemeStatsEventTracker playedGameTracker,
     INemesisRecalculator nemesisRecalculator,
     IChampionRecalculator championRecalculator,
     ISecuredEntityValidator securedEntityValidator,
     IPointsCalculator pointsCalculator,
     IBusinessLogicEventBus eventBus, 
     ILinkedPlayedGameValidator linkedPlayedGameValidator, IApplicationLinker applicationLinker) : base(eventBus)
 {
     _dataContext = applicationDataContext;
     _playedGameTracker = playedGameTracker;
     _nemesisRecalculator = nemesisRecalculator;
     _championRecalculator = championRecalculator;
     _securedEntityValidator = securedEntityValidator;
     _pointsCalculator = pointsCalculator;
     _linkedPlayedGameValidator = linkedPlayedGameValidator;
     _applicationLinker = applicationLinker;
 }
Exemplo n.º 15
0
 public PlayedGameSaver(
     IDataContext applicationDataContext,
     INemeStatsEventTracker playedGameTracker,
     INemesisRecalculator nemesisRecalculator,
     IChampionRecalculator championRecalculator,
     ISecuredEntityValidator securedEntityValidator,
     IPointsCalculator pointsCalculator,
     IApplicationLinker applicationLinker,
     IBusinessLogicEventSender businessLogicEventSender)
 {
     _dataContext              = applicationDataContext;
     _playedGameTracker        = playedGameTracker;
     _nemesisRecalculator      = nemesisRecalculator;
     _championRecalculator     = championRecalculator;
     _securedEntityValidator   = securedEntityValidator;
     _pointsCalculator         = pointsCalculator;
     _applicationLinker        = applicationLinker;
     _businessLogicEventSender = businessLogicEventSender;
 }
Exemplo n.º 16
0
        public static void SetNextPlayer(Round round, IPointsCalculator pointCalculator)
        {
            var playerThatHasTurn = round.RoundPlayers.FirstOrDefault(p => p.IsMyTurn == true);

            playerThatHasTurn.IsMyTurn  = false;
            playerThatHasTurn.MustThrow = false;

            var nextPlayer = GetNextPlayer(round.RoundPlayers, playerThatHasTurn.Wind);

            nextPlayer.IsMyTurn  = true;
            nextPlayer.MustThrow = true;

            //in case there is other player that has my turn set to true
            var otherPlayers = round.RoundPlayers.Where(u => u.IsMyTurn == true &&
                                                        u.GamePlayer.Player.UserName != nextPlayer.GamePlayer.Player.UserName &&
                                                        u.GamePlayer.Player.UserName != playerThatHasTurn.GamePlayer.Player.UserName);

            foreach (var otherPlayerTurn in otherPlayers)
            {
                otherPlayerTurn.IsMyTurn = false;
            }

            //automatically pick tile for next player
            //unless remaining tile is 1, give user give up action
            var unopenTiles = round.RoundTiles.Where(t => string.IsNullOrEmpty(t.Owner));

            if (unopenTiles.Count() == 1)
            {
                nextPlayer.RoundPlayerActions.Add(new RoundPlayerAction {
                    ActionType = ActionType.GiveUp
                });
                nextPlayer.MustThrow = false;
            }
            else
            {
                var newTiles = RoundTileHelper.PickTile(round, nextPlayer.GamePlayer.Player.UserName);
                if (newTiles == null)
                {
                    round.IsEnding = true;
                }
                CheckSelfAction(round, nextPlayer, pointCalculator);
            }
        }
Exemplo n.º 17
0
        public void RecalculateAllPointsForGamesWithNoPlayTime(IDataContext dataContext, IPointsCalculator pointsCalculator)
        {
            var allPlayedGames = (from PlayedGame playedGame in dataContext.GetQueryable <PlayedGame>()
                                  where (playedGame.GameDefinition.BoardGameGeekGameDefinition == null ||
                                         (playedGame.GameDefinition.BoardGameGeekGameDefinition.MinPlayTime == null &&
                                          playedGame.GameDefinition.BoardGameGeekGameDefinition.MaxPlayTime == null))
                                  select new PlayedGameToRecalculate
            {
                PlayedGameId = playedGame.Id,
                GamingGroupId = playedGame.GamingGroupId,
                PlayerGameResults = playedGame.PlayerGameResults,
                BoardGameGeekGameDefinition = null
            }).OrderBy(x => x.PlayedGameId).ToList();

            RecalculatePoints(dataContext, pointsCalculator, allPlayedGames);
        }
Exemplo n.º 18
0
 public void CalculatePoints(IPointsCalculator calculator)
 {
     FantasyPoints = calculator.CalculateFantasyPoints(this);
 }
Exemplo n.º 19
0
 public TeamsController(ITeamsService teamsService, IPointsCalculator pointsCalculator)
 {
     this.teamsService     = teamsService;
     this.pointsCalculator = pointsCalculator;
 }
Exemplo n.º 20
0
 public CustomerPoints GetPoints(IPointsCalculator pointsCalculator)
 {
     return(new CustomerPoints(pointsCalculator?.Calculate(this) ?? 0, CustomerId, Id));
 }
Exemplo n.º 21
0
 public Handler(MahjongBuddyDbContext context, IMapper mapper, IPointsCalculator pointCalculator)
 {
     _context         = context;
     _mapper          = mapper;
     _pointCalculator = pointCalculator;
 }
 public HomeGameCalculatorTest(GameFixture f)
 {
     _f  = f;
     _pc = new HomeGameCalculator(new ExtraPointBuilder(), new HandTypeBuilder());
 }
Exemplo n.º 23
0
 public MatchesController(IMatchesService matchesService, ITeamsService teamsService, IPointsCalculator pointsCalculator)
 {
     this.matchesService   = matchesService;
     this.teamsService     = teamsService;
     this.pointsCalculator = pointsCalculator;
 }