コード例 #1
0
    public void Calculate_ExactChance_ExpectSuccess(
        int deckSize,
        int handSize,
        int copiesInDeck,
        int copiesInHand,
        string expected
        )
    {
        var service = new HandProbability(deckSize, handSize, copiesInDeck, copiesInHand);
        var actual  = service.GetExact();

        Assert.Equal(decimal.Parse(expected), actual);
    }
コード例 #2
0
ファイル: RangeCalculatorService.cs プロジェクト: ddksaku/rzr
        protected HandProbability[][] CollateHandRangeCombinations(HandRange[] ranges)
        {
            HandProbability[][] ret = new HandProbability[ranges.Length][];

            for (int i = 0; i < ranges.Length; i++)
            {
                List<HandProbability> rangeProb = new List<HandProbability>();
                for (uint handDef = 0; handDef < 169; handDef++)
                {
                    int probability = ranges[i].Probability[(int)handDef];
                    if (ranges[i].Probability[(int)handDef] == 0) continue;

                    uint card1 = handDef % 13;
                    uint card2 = handDef / 13;

                    if (card1 < card2) // Suited
                    {
                        for (int index1 = 0; index1 < 4; index1++)
                        {
                            ulong longCard1 = 1UL << (int)(card1 + (index1 * 13));
                            ulong longCard2 = 1UL << (int)(card2 + (index1 * 13));
                            ulong pocket = longCard1 | longCard2;
                            rangeProb.Add(new HandProbability() { Hand = pocket, Probability = probability });
                        }
                    }
                    else if (card1 == card2) // Pair
                    {
                        for (int index1 = 0; index1 < 4; index1++)
                        {
                            ulong longCard1 = 1UL << (int)(card1 + (index1 * 13));
                            for (int index2 = index1 + 1; index2 < 4; index2++)
                            {
                                ulong longCard2 = 1UL << (int)(card2 + (index2 * 13));
                                ulong pocket = longCard1 | longCard2;
                                rangeProb.Add(new HandProbability() { Hand = pocket, Probability = probability });
                            }
                        }
                    }
                    else if (card1 > card2) // Unsuited
                    {
                        for (int index1 = 0; index1 < 4; index1++)
                        {
                            ulong longCard1 = 1UL << (int)(card1 + (index1 * 13));
                            for (int index2 = 0; index2 < 4; index2++)
                            {
                                if (index1 == index2) continue;

                                ulong longCard2 = 1UL << (int)(card2 + (index2 * 13));
                                ulong pocket = longCard1 | longCard2;
                                rangeProb.Add(new HandProbability() { Hand = pocket, Probability = probability });
                            }
                        }
                    }
                }
                ret[i] = rangeProb.ToArray();
            }

            return ret;
        }
コード例 #3
0
ファイル: RangeCalculatorService.cs プロジェクト: ddksaku/rzr
        protected ulong[] GetHands(ulong[] pockets, HandRange[] ranges, HandProbability[][] combos, ulong board)
        {
            ulong[] ret = new ulong[pockets.Length + ranges.Length];
            ulong deck = Deck.DeckLong ^ board;

            for (int j = 0; j < pockets.Length; j++)
                ret[j] = pockets[j];

            for (int j = 0; j < combos.Length; j++)
            {
                if (combos[j].Length == 0) continue;

                //---------------------------------------------------------------------------------
                // Select a hand at random
                //---------------------------------------------------------------------------------
                int index = _rand.Next(combos[j].Length);
                int prob = _rand.Next(100);

                HandProbability combo = combos[j][index];
                //---------------------------------------------------------------------------------
                // Select another hand if any of the cards required have already been dealt, or if
                // the probability of the player using the hand fails the random probability test
                //---------------------------------------------------------------------------------
                while ((deck & combo.Hand) != combo.Hand || prob > combo.Probability)
                {
                    index = _rand.Next(combos[j].Length);
                    prob = _rand.Next(100);
                    combo = combos[j][index];
                }

                deck = deck ^ combo.Hand;
                ret[pockets.Length + j] = combo.Hand;
            }
            return ret;
        }
コード例 #4
0
ファイル: RangeCalculatorService.cs プロジェクト: ddksaku/rzr
        protected HandMask[][] GetConditionResults(ulong[] pockets, HandRange[] ranges, HandProbability[][] combos,
            bool[] show, ulong fullBoard, ulong[] boardPart, int[] numCardsSelected)
        {
            ulong[] hands = GetHands(pockets, ranges, combos, fullBoard);
            HandMask[][] handMasks = new HandMask[][] {
                new HandMask[hands.Length],
                new HandMask[hands.Length],
                new HandMask[hands.Length],
            };
            ulong dead = 0;

            foreach (ulong hand in hands)
                dead |= hand;

            ulong board = boardPart[0] | GetRandomCards(dead, 3 - numCardsSelected[0]);
            if (show[0])
                handMasks[0] = SetResults(3, hands, board);

            board |= boardPart[1] | GetRandomCards(dead | board, 1 - numCardsSelected[1]);
            if (show[1])
                handMasks[1] = SetResults(4, hands, board);

            board |= boardPart[2] | GetRandomCards(dead | board, 1 - numCardsSelected[2]);
            if (show[2])
                handMasks[2] = SetResults(5, hands, board);

            return handMasks;
        }
コード例 #5
0
    public async Task ProbabilityCommand(
        [Summary(description: "deck size")] int deckSize,
        [Summary(description: "copies in deck")]
        int inDeck,
        [Summary(description: "hand size")]
        int handSize,
        [Summary(description: "copies you want in hand")]
        int inHand
        )
    {
        if (inDeck > deckSize)
        {
            await RespondAsync($"There are more cards in deck `({inDeck})` than the deck size `({deckSize})`!");

            return;
        }

        if (handSize > deckSize)
        {
            await RespondAsync($"The hand is larger `({handSize})` than the deck size `({deckSize})`!");

            return;
        }

        if (inHand > deckSize)
        {
            await RespondAsync($"There are more copies of the card in hand `({inHand})` than the deck size `({deckSize})`!");

            return;
        }

        if (inHand > inDeck)
        {
            await RespondAsync($"There are more copies of the card in hand `({inHand})` than the copies in deck `({inDeck})`!");

            return;
        }

        if (inHand > handSize)
        {
            await RespondAsync($"There are more cards in hand `({inHand})` than the hand size `({handSize})`!");

            return;
        }

        try
        {
            var probability = new HandProbability(deckSize, handSize, inDeck, inHand);
            var display     = $"{deckSize} cards in deck\n" +
                              $"{inDeck} copies in deck\n" +
                              $"{handSize} cards in hand\n" +
                              $"{inHand} copies in hand\n" +
                              $"Exactly {inHand} in hand: {probability.GetExact()}%\n" +
                              $"Less than {inHand} in hand: {probability.GetLess()}%\n" +
                              $"Less or equal to {inHand} in hand: {probability.GetLessOrEqual()}%\n" +
                              $"More than {inHand} in hand: {probability.GetMore()}%\n" +
                              $"More or equal to {inHand} in hand: {probability.GetMoreOrEqual()}%";

            if (inHand == 1)
            {
                await RespondAsync($"```{display}```");

                return;
            }

            decimal onetoInHand = 0;

            for (var i = inHand; i >= 1; i--)
            {
                onetoInHand += Probability(deckSize, inDeck, handSize, i);
            }

            display += $"\n1-{inHand} copies in hand: {onetoInHand}%";

            await RespondAsync($"```{display}```");
        }
        catch
        {
            await RespondAsync("There was an error. Please check your values and try again!\nEx. `y!prob 40 7 5 2`");
        }
    }