示例#1
0
        public async Task <bool> GetCardsForBots(Guid gameId)
        {
            IEnumerable <Player> allPlayersExist = await _playerRepository.GetAll();

            List <Move> moves = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();

            var playersInCurrentGame = new List <Player>();

            foreach (var move in moves.Where(p => p.MoveNumber == firstMoveNumber))
            {
                playersInCurrentGame.Add(allPlayersExist.SingleOrDefault(p => p.Id == move.PlayerId));
            }

            List <PlayerViewModel> playersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);

            foreach (var item in playersViews)
            {
                if (item.Points >= pointsToStop)
                {
                    continue;
                }
                await GetOneMoreCardForOneBotMove(gameId, playersInCurrentGame, moves, playersViews);

                moves        = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();
                playersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);
            }
            await GetCardForDealer(playersInCurrentGame, gameId, moves);

            bool isGameOver = true;

            return(isGameOver);
        }
示例#2
0
        private async Task GetOneMoreCardForOneBotMove(Guid gameId, List <Player> playersInCurrentGame, List <Move> moves, List <PlayerViewModel> playersViews)
        {
            foreach (var item in playersViews.Where(p => p.PlayerRole == PlayerRole.Bot))
            {
                if (item.Points >= pointsToStop)
                {
                    continue;
                }
                Player player = playersInCurrentGame.SingleOrDefault(m => m.Id == item.Id);
                await MoveForOnePlayer(player, moves, gameId);

                moves        = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();
                playersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);
            }
        }
示例#3
0
        private async Task GetCardForDealer(List <Player> playersInCurrentGame, Guid gameId, List <Move> moves)
        {
            List <PlayerViewModel> playersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);
            int counterForDealerPoints          = playersViews.SingleOrDefault(p => p.PlayerRole == PlayerRole.Dealer).Points;

            foreach (var item in playersViews)
            {
                if (counterForDealerPoints >= pointsToStop)
                {
                    continue;
                }
                await MoveForOnePlayer(playersInCurrentGame.SingleOrDefault(p => p.PlayerRole == PlayerRole.Dealer), moves, gameId);

                moves                  = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();
                playersViews           = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);
                counterForDealerPoints = playersViews.SingleOrDefault(p => p.PlayerRole == PlayerRole.Dealer).Points;
            }
            await FinishGame(playersViews, gameId);
        }
示例#4
0
        public async Task <bool> GetOneMoreCardForPlayer(Guid gameId)
        {
            Game currentGame = await GetGame(gameId);

            List <Move>          moves           = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();
            IEnumerable <Player> allPlayersExist = await _playerRepository.GetAll();

            bool isGameOver           = false;
            var  playersInCurrentGame = new List <Player>();


            foreach (var move in moves.Where(p => p.MoveNumber == firstMoveNumber))
            {
                playersInCurrentGame.Add(allPlayersExist.SingleOrDefault(p => p.Id == move.PlayerId));
            }

            List <PlayerViewModel> playersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);

            foreach (var item in playersViews)
            {
                if (item.Points < pointsToVictory && item.PlayerRole != PlayerRole.Player)
                {
                    continue;
                }
                Player player = playersInCurrentGame.SingleOrDefault(m => m.Id == item.Id);
                await MoveForOnePlayer(player, moves, gameId);

                moves = (await _moveRepository.GetAllMovesForOneGame(gameId)).ToList();
            }

            List <PlayerViewModel> newPlayersViews = CalculatePointsHelper.CalculatePlayersPoints(moves, playersInCurrentGame);

            if (newPlayersViews.FirstOrDefault(p => p.PlayerRole == PlayerRole.Player)?.Points >= pointsToVictory)
            {
                var result = await GetCardsForBots(gameId);

                isGameOver = result;
            }
            return(isGameOver);
        }