예제 #1
0
        public static void GenerateStrategy()
        {
            List <Card> orderedCards = new List <Card>();

            for (int deck = 0; deck < Configuration.NUM_DECKS_IN_SHOE; deck++)
            {
                orderedCards.AddRange(new FrenchDeck().cards);
            }

            Queue <Card> shoe = Utilities.ShuffleShoe(orderedCards);

            IPlayerStrategy strategy = new RandomPlayerStrategy();

            for (int gameIndex = 0; gameIndex < Configuration.STRATEGY_GENERATOR_NUM_GAMES; gameIndex++)
            {
                BlackjackGame bjgame = new BlackjackGame();

                int bet = 10;

                BlackjackGameResult result = bjgame.PlayGame(shoe, bet, strategy);

                double currentShoePenetration = 1 - (shoe.Count / (double)orderedCards.Count);

                if (currentShoePenetration >= Configuration.RESHUFFLE_PENETRATION_PERCENT)
                {
                    Console.WriteLine("Shuffling shoe");
                    shoe = Utilities.ShuffleShoe(orderedCards);
                }
            }
        }
        internal void RecordResult(BlackjackGameResult result)
        {
            switch (result.Winner)
            {
            case BlackjackResultWinner.DealerWins:
                // No action needed
                break;

            case BlackjackResultWinner.PlayerWins:
                if (currentPlayerAction == PlayerAction.Hit)
                {
                    hitWasAGoodChoice++;
                }
                else
                {
                    standWasAGoodChoice++;
                }
                break;

            case BlackjackResultWinner.Push:
                // No action needed
                break;
            }

            // Do something else next time
            if (currentPlayerAction == PlayerAction.Hit)
            {
                currentPlayerAction = PlayerAction.Stand;
            }
            else
            {
                currentPlayerAction = PlayerAction.Hit;
            }
        }
예제 #3
0
        public async Task SendGameInfoWithWinner(HttpContext context, BlackjackGameResult result)
        {
            await _dbService(context).SaveBlackjackGameResult(result);

            foreach (var websocketWrapper in Websockets)
            {
                var wrapper = websocketWrapper.Value;
                await SendMessageJson(wrapper.WebSocket,
                                      _messageBuilder.BuildMessageWithWinner(wrapper.BlackjackUser, wrapper.Place, result));
            }
        }