public string BuildSqlStringFrom(IConvertedPokerRound convertedRound)
        {
            if (convertedRound == null || convertedRound.Count == 0)
            {
                return(null);
            }

            string sqlString = string.Empty;

            for (int i = 0; i < convertedRound.Count; i++)
            {
                try
                {
                    IConvertedPokerAction theAction = convertedRound[i];

                    if (theAction is IConvertedPokerActionWithId)
                    {
                        sqlString = sqlString + BuildSqlStringFrom((IConvertedPokerActionWithId)theAction);
                    }
                    else
                    {
                        sqlString = sqlString + BuildSqlStringFrom(theAction);
                    }

                    sqlString += ",";
                }
                catch (Exception excep)
                {
                    Log.DebugFormat("Unhandled {0}", excep);
                }
            }

            return(sqlString.TrimStart(',').TrimEnd(','));
        }
        /// <summary>
        /// Add a given Poker round to the Player
        /// </summary>
        /// <param name="convertedRound">
        /// The converted Round.
        /// </param>
        public IConvertedPokerPlayer Add(IConvertedPokerRound convertedRound)
        {
            try
            {
                if (convertedRound == null)
                {
                    throw new ArgumentNullException("convertedRound");
                }

                if (Rounds.Count < 4)
                {
                    Rounds.Add(convertedRound);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("convertedRound");
                }
            }
            catch (Exception excep)
            {
                Log.Error("Unexpected", excep);
            }

            return(this);
        }
        /// <summary>
        /// Prepares the analyzation, needs to be called before it's data becomes useful
        /// </summary>
        /// <param name="sequence"><see cref="Sequence"/></param>
        /// <param name="playerPosition"><see cref="HeroPosition"/></param>
        /// <param name="actionSequence">The ActionSequence whose last action's index will be idendified</param>
        public IReactionAnalyzationPreparer PrepareAnalyzationFor(IConvertedPokerRound sequence, int playerPosition, ActionSequences actionSequence)
        {
            InitializeProperties(sequence, playerPosition);

            PrepareAnalyzation(actionSequence);

            return(this);
        }
        public void ConvertedRoundFrom_EmptyString_ReturnsNull()
        {
            string csvString = string.Empty;

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);

            Assert.That(round, Is.Null);
        }
예제 #5
0
        public void PrepareAnalyzationFor_PreFlopUnraisedPotAndFirstMatchingHeroActionIsAtIndexOne_StartingActionIndexIsOne(
            [Values("[1]C,[2]F,[3]C", "[1]C,[2]C,[3]C", "[1]C,[2]R,[3]C")] string sequenceString,
            [Values(ActionSequences.HeroF, ActionSequences.HeroC, ActionSequences.HeroR)] ActionSequences actionSequence)
        {
            IConvertedPokerRound sequence = sequenceString.ToConvertedPokerRoundWithIds();

            _sut.PrepareAnalyzationFor(sequence, HeroPosition, actionSequence);

            _sut.StartingActionIndex.ShouldBeEqualTo(1);
        }
예제 #6
0
        public void AnalyzeUsingDataFrom_NoProperReactionInSequence_AnalyzationIsInvalid()
        {
            IConvertedPokerRound sequence = "[2]B0.3,[3]R2.0".ToConvertedPokerRoundWithIds();

            _analyzationPreparer.PrepareAnalyzationFor(sequence, HeroPosition, ActionSequences.HeroB);

            _sut.AnalyzeUsingDataFrom(_stub.Out <IAnalyzablePokerPlayer>(), _analyzationPreparer, true, _raiseSizes);

            _sut.IsValidResult.ShouldBeFalse();
        }
예제 #7
0
        public void PrepareAnalyzationFor_FlopHeroXOppBAndFirstMatchingHeroReactionIsAtIndexTwo_StartingActionIndexIsTwo(
            [Values("[2]X,[1]B,[2]F", "[2]X,[1]B,[2]C", "[2]X,[1]B,[2]R")] string sequenceString,
            [Values(ActionSequences.HeroXOppBHeroF, ActionSequences.HeroXOppBHeroC, ActionSequences.HeroXOppBHeroR)] ActionSequences actionSequence)
        {
            IConvertedPokerRound sequence = sequenceString.ToConvertedPokerRoundWithIds();

            _sut.PrepareAnalyzationFor(sequence, HeroPosition, actionSequence);

            _sut.StartingActionIndex.ShouldBeEqualTo(2);
        }
예제 #8
0
        public void AnalyzeUsingDataFrom_HeroXOppBHeroR_OppReraisesFourTimes_OpponentRaiseSizeIsStandardizedToFive()
        {
            IConvertedPokerRound sequence = "[2]X,[1]B,[2]R3.0,[1]R4.0,[2]R3.0".ToConvertedPokerRoundWithIds();

            _analyzationPreparer.PrepareAnalyzationFor(sequence, HeroPosition, ActionSequences.HeroXOppBHeroR);

            _sut.AnalyzeUsingDataFrom(_stub.Out <IAnalyzablePokerPlayer>(), _analyzationPreparer, true, _raiseSizes);

            _sut.ConsideredRaiseSize.ShouldBeEqualTo(5);
        }
예제 #9
0
        public void AnalyzeUsingDataFrom_OnlyOneOpponentRaisedAndNoMoreActionsAfterHerosReaction_IsStandardSituationIsTrue()
        {
            IConvertedPokerRound sequence = "[2]X,[1]B,[2]R3.0,[1]R3.0,[2]R3.0".ToConvertedPokerRoundWithIds();

            _analyzationPreparer.PrepareAnalyzationFor(sequence, HeroPosition, ActionSequences.HeroXOppBHeroR);

            _sut.AnalyzeUsingDataFrom(_stub.Out <IAnalyzablePokerPlayer>(), _analyzationPreparer, true, _raiseSizes);

            _sut.IsStandardSituation.ShouldBeTrue();
        }
예제 #10
0
 public RelativeRatioResult(IConvertedPokerHand convertedHand, IConvertedPokerRound player1FirstRound, IConvertedPokerRound player2FirstRound, double relativeRatio1, double relativeRatio2, double relativeRatio3, double relativeRatio4)
 {
     ConvertedHand     = convertedHand;
     Player1FirstRound = player1FirstRound;
     Player2FirstRound = player2FirstRound;
     RelativeRatio4    = relativeRatio4;
     RelativeRatio3    = relativeRatio3;
     RelativeRatio2    = relativeRatio2;
     RelativeRatio1    = relativeRatio1;
 }
        public void ConvertedRoundFrom_OneActiveAction_ReturnsRoundWithThatAction(
            [Values(ActionTypes.B, ActionTypes.C, ActionTypes.R, ActionTypes.W)] ActionTypes actionType)
        {
            const double         ratio         = 0.5;
            string               csvString     = actionType.ToString() + ratio;
            IConvertedPokerRound expectedRound = new ConvertedPokerRound()
                                                 .Add(new ConvertedPokerAction(actionType, ratio));

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);

            Assert.That(round, Is.EqualTo(expectedRound));
        }
        public void ConvertedRoundFrom_PokerActionWithId_ReturnsRoundWithPokerActionWithIdType()
        {
            const ActionTypes actionType1 = ActionTypes.B;
            const double      ratio1      = 0.5;

            string csvString =
                "[0]" + actionType1 + ratio1;

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);

            Assert.That(round[0], Is.AssignableTo(typeof(IConvertedPokerActionWithId)));
        }
예제 #13
0
        public void AnalyzeUsingDataFrom_ReactionContainedInSequence_FindsReactionAndSetsIsValidToTrue(
            [Values("[2]B0.3,[3]R2.0,[2]F", "[2]B0.3,[3]R2.0,[2]C", "[2]B0.3,[3]R2.0,[2]R2.0")] string sequenceString,
            [Values(ActionTypes.F, ActionTypes.C, ActionTypes.R)] ActionTypes expectedReaction)
        {
            IConvertedPokerRound sequence = sequenceString.ToConvertedPokerRoundWithIds();

            _analyzationPreparer.PrepareAnalyzationFor(sequence, HeroPosition, ActionSequences.HeroB);

            _sut.AnalyzeUsingDataFrom(_stub.Out <IAnalyzablePokerPlayer>(), _analyzationPreparer, true, _raiseSizes);

            _sut.HeroReactionType.ShouldBeEqualTo(expectedReaction);
            _sut.IsValidResult.ShouldBeTrue();
        }
예제 #14
0
        /// <summary>
        /// Gives string representation for an Html Cell containing this betting round
        /// <param name="indent">If true, this is Preflop and player is SB or BB, so we need to indent</param>
        /// </summary>
        /// <returns>Html Cell string</returns>
        public static string BuildFrom(IConvertedPokerRound convertedRound, bool indent)
        {
            string strIndent = indent ? " &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp " : string.Empty;

            string roundString = string.Empty;

            foreach (IConvertedPokerAction iConvertedAction in convertedRound)
            {
                roundString = roundString + BuildFrom(iConvertedAction) + " &nbsp ";
            }

            return(string.Format("\t\t\t\t<td><font size=\"2\">{0}{1}</td>", strIndent, roundString));
        }
        public void ConvertedRoundFrom_OneInactiveAction_ReturnsRoundWithThatAction(
            [Values(ActionTypes.A, ActionTypes.F, ActionTypes.X)] ActionTypes actionType)
        {
            _stub.Value(For.Ratio).Is(1.0);

            string csvString = actionType.ToString();
            IConvertedPokerRound expectedRound = new ConvertedPokerRound()
                                                 .Add(new ConvertedPokerAction(actionType, _stub.Out <double>(For.Ratio)));

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);

            Assert.That(round, Is.EqualTo(expectedRound));
        }
예제 #16
0
        public void AnalyzeUsingDataFrom_OnlyOneOpponentRaisedAndMoreActionsAfterHerosReaction_IsStandardSituationIsTrue(
            [Values("[2]B,[1]R3.0,[2]F,[4]R2.0", "[1]B,[2]R,[1]R3.0,[2]F,[4]R2.0", "[2]X,[1]B,[2]R,[1]R3.0,[2]F,[4]R2.0"
                    )] string sequenceString,
            [Values(ActionSequences.HeroB, ActionSequences.OppBHeroR, ActionSequences.HeroXOppBHeroR)] ActionSequences
            actionSequence)
        {
            IConvertedPokerRound sequence = sequenceString.ToConvertedPokerRoundWithIds();

            _analyzationPreparer.PrepareAnalyzationFor(sequence, HeroPosition, actionSequence);

            _sut.AnalyzeUsingDataFrom(_stub.Out <IAnalyzablePokerPlayer>(), _analyzationPreparer, true, _raiseSizes);

            _sut.IsStandardSituation.ShouldBeTrue();
        }
        public void ConvertedRoundFrom_PokerActionWithId_ReturnsRoundWithPokerActionWithGivenId()
        {
            const ActionTypes actionType1 = ActionTypes.B;
            const double      ratio1      = 0.5;
            const int         playerId    = 2;

            var expectedAction = new ConvertedPokerActionWithId(
                new ConvertedPokerAction(actionType1, ratio1), playerId);

            string csvString =
                "[" + playerId + "]" + actionType1 + ratio1;

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);
            var firstAction            = round[0] as IConvertedPokerActionWithId;

            Assert.That(firstAction, Is.EqualTo(expectedAction));
        }
예제 #18
0
        public virtual IPokerRoundsConverter ConvertPreflop()
        {
            // At this point all posting has been removed
            SequenceForCurrentRound = _convertedRound.New;
            ActionCount             = 0;

            // Do as long as we still find an action of ANY Player
            do
            {
                FoundAction   = false;
                SequenceSoFar = string.Empty;

                int fromPlayer;
                int toPlayer;

                if (HeadsUp)
                {
                    fromPlayer = 0;
                    toPlayer   = 1;

                    ProcessPlayersForRound(Streets.PreFlop, fromPlayer, toPlayer);
                }
                else if (ThreeOrMore)
                {
                    // Preflop Blinds are last

                    // Everyone but blinds
                    fromPlayer = 2;
                    toPlayer   = _aquiredHand.Players.Count - 1;

                    ProcessPlayersForRound(Streets.PreFlop, fromPlayer, toPlayer);

                    // Blinds
                    fromPlayer = 0;
                    toPlayer   = 1;

                    ProcessPlayersForRound(Streets.PreFlop, fromPlayer, toPlayer);
                }

                ActionCount++;
            }while (FoundAction);

            _convertedHand.Sequences[(int)Streets.PreFlop] = SequenceForCurrentRound;

            return(this);
        }
        public void ConvertedRoundFrom_TwoActiveActions_ReturnsRoundWithBothActions()
        {
            const ActionTypes actionType1 = ActionTypes.B;
            const double      ratio1      = 0.5;
            const ActionTypes actionType2 = ActionTypes.C;
            const double      ratio2      = 0.2;

            string csvString =
                actionType1.ToString() + ratio1 + "," +
                actionType2 + ratio2;

            IConvertedPokerRound expectedRound = new ConvertedPokerRound()
                                                 .Add(new ConvertedPokerAction(actionType1, ratio1))
                                                 .Add(new ConvertedPokerAction(actionType2, ratio2));

            IConvertedPokerRound round = _converter.ConvertedRoundFrom(csvString);

            Assert.That(round, Is.EqualTo(expectedRound));
        }
예제 #20
0
        public virtual IConvertedPokerHand ConvertFlopTurnAndRiver()
        {
            for (Streets street = Streets.Flop; street <= Streets.River; street++)
            {
                ActionCount   = 0;
                SequenceSoFar = string.Empty;

                SequenceForCurrentRound = _convertedRound.New;

                // Do as long as we still find an action of ANY Player
                do
                {
                    FoundAction = false;
                    int fromPlayer;
                    int toPlayer;

                    if (HeadsUp)
                    {
                        // BigBlind acts before button (small Blind)
                        fromPlayer = 1;
                        toPlayer   = 0;
                        ProcessPlayersForRound(street, fromPlayer, toPlayer);
                    }
                    else if (ThreeOrMore)
                    {
                        fromPlayer = 0;
                        toPlayer   = _aquiredHand.Players.Count - 1;
                        ProcessPlayersForRound(street, fromPlayer, toPlayer);
                    }

                    ActionCount++;
                }while (FoundAction);

                _convertedHand.Sequences[(int)street] = SequenceForCurrentRound;
            }

            return(_convertedHand);
        }
        void ExtractRoundsAndSequences(IConvertedPokerPlayer convPlayer, IDataRecord dr)
        {
            IConvertedPokerRound convRound =
                _pokerHandStringConverter.ConvertedRoundFrom(dr[ActionTable.action0.ToString()].ToString());

            if (convRound != null && convRound.Count > 0)
            {
                convPlayer.Add(convRound);
                convPlayer.Sequence[0] = dr[ActionTable.sequence0.ToString()].ToString();

                // Flop
                convRound = _pokerHandStringConverter.ConvertedRoundFrom(dr[ActionTable.action1.ToString()].ToString());
                if (convRound != null && convRound.Count > 0)
                {
                    convPlayer.Add(convRound);
                    convPlayer.Sequence[1] = dr[ActionTable.sequence1.ToString()].ToString();

                    // Turn
                    convRound =
                        _pokerHandStringConverter.ConvertedRoundFrom(dr[ActionTable.action2.ToString()].ToString());
                    if (convRound != null && convRound.Count > 0)
                    {
                        convPlayer.Add(convRound);
                        convPlayer.Sequence[2] = dr[ActionTable.sequence2.ToString()].ToString();

                        // River
                        convRound =
                            _pokerHandStringConverter.ConvertedRoundFrom(dr[ActionTable.action3.ToString()].ToString());
                        if (convRound != null && convRound.Count > 0)
                        {
                            convPlayer.Add(convRound);
                            convPlayer.Sequence[3] = dr[ActionTable.sequence3.ToString()].ToString();
                        }
                    }
                }
            }
        }
        RelativeRatioResult ConvertPreflopThreePlayersHand()
        {
            _stub
            .Value(For.HoleCards).Is(string.Empty);

            const double smallBlind         = 1.0;
            const double bigBlind           = 2.0;
            const double pot                = smallBlind + bigBlind;
            const double toCall             = bigBlind;
            const int    totalPlayers       = 3;
            const int    smallBlindPosition = 0;
            const int    bigBlindPosition   = 1;
            const int    buttonPosition     = 2;

            var          action1        = new AquiredPokerAction(ActionTypes.C, toCall);
            const double relativeRatio1 = toCall / pot;
            const double pot1           = pot + toCall;

            var          action2        = new AquiredPokerAction(ActionTypes.C, smallBlind);
            const double relativeRatio2 = smallBlind / pot1;
            const double pot2           = pot1 + smallBlind;

            var          action3        = new AquiredPokerAction(ActionTypes.R, bigBlind * 3);
            const double relativeRatio3 = 3;
            const double pot3           = pot2 + (bigBlind * 3);

            var          action4        = new AquiredPokerAction(ActionTypes.R, toCall * 3 * 2);
            const double relativeRatio4 = 2;
            const double pot4           = pot3 + (toCall * 3 * 2);

            var          action5        = new AquiredPokerAction(ActionTypes.C, toCall * 3 * 2);
            const double relativeRatio5 = (toCall * 3 * 2) / pot4;

            var action6 = new AquiredPokerAction(ActionTypes.F, 1.0);

            // Small Blind
            IAquiredPokerPlayer player1 = new AquiredPokerPlayer(
                _stub.Some <long>(), smallBlindPosition, _stub.Out <string>(For.HoleCards))
                                          .AddRound(
                new AquiredPokerRound()
                .Add(action2)
                .Add(action5));

            player1.Name     = "player1";
            player1.Position = smallBlindPosition;

            // Big Blind
            IAquiredPokerPlayer player2 = new AquiredPokerPlayer(
                _stub.Some <long>(), bigBlindPosition, _stub.Out <string>(For.HoleCards))
                                          .AddRound(
                new AquiredPokerRound()
                .Add(action3)
                .Add(action6));

            player2.Name     = "player2";
            player2.Position = bigBlindPosition;

            // Button
            IAquiredPokerPlayer player3 = new AquiredPokerPlayer(
                _stub.Some <long>(), buttonPosition, _stub.Out <string>(For.HoleCards))
                                          .AddRound(
                new AquiredPokerRound()
                .Add(action1)
                .Add(action4));

            player3.Name     = "player3";
            player3.Position = buttonPosition;

            IAquiredPokerHand aquiredHand =
                new AquiredPokerHand(
                    _stub.Valid(For.Site, "site"),
                    _stub.Out <ulong>(For.GameId),
                    _stub.Out <DateTime>(For.TimeStamp),
                    smallBlind,
                    bigBlind,
                    totalPlayers)
                .AddPlayer(player1)
                .AddPlayer(player2)
                .AddPlayer(player3);

            IConvertedPokerHand convertedHand =
                new ConvertedPokerHand(aquiredHand)
                .InitializeWith(aquiredHand)
                .AddPlayersFrom(aquiredHand, pot, _convertedPlayerMake);

            _converter
            .InitializeWith(aquiredHand, convertedHand, pot, toCall)
            .ConvertPreflop();

            IConvertedPokerRound player1FirstRound = convertedHand[smallBlindPosition][Streets.PreFlop];
            IConvertedPokerRound player2FirstRound = convertedHand[bigBlindPosition][Streets.PreFlop];
            IConvertedPokerRound player3FirstRound = convertedHand[buttonPosition][Streets.PreFlop];

            return(new RelativeRatioResult(
                       convertedHand,
                       player1FirstRound,
                       player2FirstRound,
                       player3FirstRound,
                       relativeRatio1,
                       relativeRatio2,
                       relativeRatio3,
                       relativeRatio4,
                       relativeRatio5));
        }
 protected void InitializeProperties(IConvertedPokerRound sequence, int playerPosition)
 {
     Sequence     = sequence;
     HeroPosition = playerPosition;
 }