Example #1
0
        public async Task <ResponseGetBotExtraCardGameView> GetBotExtraCard(RequestGetBotExtraCardGameView requestGetBotExtraCardGameView)
        {
            Hand hand = await _handRepository.GetWithCards(requestGetBotExtraCardGameView.HandId);

            if (hand == null)
            {
                var stringBuilder = new StringBuilder();

                stringBuilder.AppendLine(string.Format("GameId: {0}", requestGetBotExtraCardGameView.GameId));
                stringBuilder.AppendLine(string.Format("HandId: {0}", requestGetBotExtraCardGameView.HandId));
                stringBuilder.AppendLine(string.Format("Message: {0}", SolutionConstants.BUSINESS_LOGIC_GET_ITEM_EXCEPTION_MESSAGE));

                string message = stringBuilder.ToString();

                throw new BusinessLogicGetItemException(message);
            }

            RequestGetExtraCardGameView requestExtraCardView = _mapper.Map <RequestGetBotExtraCardGameView, RequestGetExtraCardGameView>(requestGetBotExtraCardGameView);

            int chance = await CountChanceToGetNeededExtraCardForBot(requestGetBotExtraCardGameView.GameId);

            var extraCards = new List <ResponseGetBotExtraCardGameViewItem>();

            for (int i = hand.Summary; i < GameConstants.BLACKJACK;)
            {
                i = _gameUtility.CalculateCardsSumm(hand.HandCards.Select(item => item.Card).ToList());

                if (i <= GameConstants.REQUIRED_SUMM_CARDS_BOT)
                {
                    ResponseGetExtraCardGameView extraCardView = await GetExtraCard(requestExtraCardView);

                    ResponseGetBotExtraCardGameViewItem extraCardViewItem = _mapper.Map <ResponseGetExtraCardGameView, ResponseGetBotExtraCardGameViewItem>(extraCardView);

                    extraCards.Add(extraCardViewItem);

                    chance = await CountChanceToGetNeededExtraCardForBot(requestGetBotExtraCardGameView.GameId);

                    hand = await _handRepository.GetWithCards(hand.Id);

                    continue;
                }

                if (i <= GameConstants.DESIRED_SUMM_CARDS_BOT_AND_DEALLER && chance < 0)
                {
                    ResponseGetExtraCardGameView extraCardView = await GetExtraCard(requestExtraCardView);

                    ResponseGetBotExtraCardGameViewItem extraCardViewItem = _mapper.Map <ResponseGetExtraCardGameView, ResponseGetBotExtraCardGameViewItem>(extraCardView);

                    extraCards.Add(extraCardViewItem);

                    chance = await CountChanceToGetNeededExtraCardForBot(requestGetBotExtraCardGameView.GameId);

                    hand = await _handRepository.GetWithCards(hand.Id);

                    continue;
                }

                if (i <= GameConstants.DESIRED_SUMM_CARDS_BOT_AND_DEALLER && chance >= 0)
                {
                    var random = new Random();

                    int randValue = random.Next(GameConstants.DECISION_TO_TAKE_CARD, GameConstants.DECISION_NOT_TO_TAKE_CARD);

                    if (randValue.Equals(GameConstants.DECISION_TO_TAKE_CARD))
                    {
                        ResponseGetExtraCardGameView extraCardView = await GetExtraCard(requestExtraCardView);

                        ResponseGetBotExtraCardGameViewItem extraCardViewItem = _mapper.Map <ResponseGetExtraCardGameView, ResponseGetBotExtraCardGameViewItem>(extraCardView);

                        extraCards.Add(extraCardViewItem);

                        chance = await CountChanceToGetNeededExtraCardForBot(requestGetBotExtraCardGameView.GameId);

                        hand = await _handRepository.GetWithCards(hand.Id);

                        continue;
                    }

                    if (randValue.Equals(GameConstants.DECISION_NOT_TO_TAKE_CARD))
                    {
                        break;
                    }
                }

                break;
            }

            var responseView = new ResponseGetBotExtraCardGameView();

            responseView.ExtraCards = extraCards;

            return(responseView);
        }
Example #2
0
        public async Task <ResponseGetBotExtraCardGameView> GetBotExtraCard([FromBody] RequestGetBotExtraCardGameView getBotExtraCardView)
        {
            ResponseGetBotExtraCardGameView responseGetBotExtraCardView = await _gameLogicService.GetBotExtraCard(getBotExtraCardView);

            return(responseGetBotExtraCardView);
        }