/// <summary> /// Gives a html representation of the action /// </summary> /// <returns>String representation of the action type and ratio</returns> public static string BuildFrom(IConvertedPokerAction convertedAction) { string htmlString; switch (convertedAction.What) { case ActionTypes.P: case ActionTypes.B: case ActionTypes.C: case ActionTypes.W: case ActionTypes.R: htmlString = string.Format("{0} {1:F1}", convertedAction.What, convertedAction.Ratio); break; case ActionTypes.A: case ActionTypes.X: case ActionTypes.F: case ActionTypes.E: htmlString = string.Format("{0}     ", convertedAction.What); break; default: htmlString = string.Format("{0} {1:F1}", convertedAction.What, convertedAction.Ratio); break; } return(htmlString); }
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(',')); }
protected virtual void ProcessRound(Streets street, IAquiredPokerRound aquiredPokerRound, IConvertedPokerPlayer convertedPlayer) { try { FoundAction = true; // Ignore returned chips (they didn't add or substract from the pot // and this action was not "done" by the player if (aquiredPokerRound[ActionCount].What != ActionTypes.U) { IConvertedPokerAction convertedAction = _actionConverter.Convert( aquiredPokerRound[ActionCount], ref Pot, ref ToCall, _aquiredHand.TotalPot); SequenceForCurrentRound.Add( _convertedActionWithId.New.InitializeWith(convertedAction, convertedPlayer.Position)); SetActionSequenceAndAddActionTo(convertedPlayer, convertedAction, street); } } catch (Exception excep) { Log.Error("Unhandled", excep); } }
void SetActionSequenceAndAddActionTo(IConvertedPokerPlayer convertedPlayer, IConvertedPokerAction convertedAction, Streets street) { convertedPlayer.SetActionSequenceString(ref SequenceSoFar, convertedAction, street); if (convertedPlayer.Rounds != null && convertedPlayer.Rounds.Count < (int)street + 1) { convertedPlayer.Add(); } convertedPlayer[street].Add(convertedAction); }
/// <summary> /// The add action. /// </summary> /// <param name="action"> /// The the action. /// </param> /// <exception cref="ArgumentNullException"> /// </exception> public IConvertedPokerRound Add(IConvertedPokerAction action) { if (action != null) { Actions.Add(action); } else { throw new ArgumentNullException("action"); } return(this); }
ProcessRound_PreflopAquPlayerWithOneRoundConPlayerWithNoRound_AddsPreflopRoundAndActionToConvertedPokerPlayer () { IAquiredPokerRound aquiredRound = new AquiredPokerRound() .Add(new AquiredPokerAction(_stub.Valid(For.ActionType, ActionTypes.C), _stub.Some <double>())); IConvertedPokerPlayer convertedPlayer = new ConvertedPokerPlayer(); _converter.InvokeProcessRound(Streets.PreFlop, aquiredRound, convertedPlayer); IConvertedPokerAction firstPreflopAction = convertedPlayer[Streets.PreFlop][0]; Assert.That(firstPreflopAction, Is.EqualTo(aquiredRound[0])); }
public void Convert_ValidActionType_ReturnsConvertedActionWithSameActionType( [Values(ActionTypes.A, ActionTypes.B, ActionTypes.C, ActionTypes.F, ActionTypes.R, ActionTypes.W, ActionTypes.X)] ActionTypes actionType) { double somePot = 3.0; double someToCall = 1.5; const double someTotalPot = 4.0; const double someRatio = 1.0; var aquiredAction = new AquiredPokerAction(actionType, someRatio); ActionTypes expectedActionType = actionType; IConvertedPokerAction convertedAction = _converter.Convert( aquiredAction, ref somePot, ref someToCall, someTotalPot); Assert.That(convertedAction.What, Is.EqualTo(expectedActionType)); }
static IConvertedPokerActionWithId ConvertedActionWithIdFrom(string sqlAction) { Match m = Regex.Match(sqlAction, PatSqlActionWithId); if (!(m.Groups["playerID"].Success && m.Groups["whatAndRatio"].Success)) { throw new FormatException("Given sqlAction cannot be matched: " + sqlAction); } string whatAndRatio = m.Groups["whatAndRatio"].Value; int playerId = int.Parse(m.Groups["playerID"].Value); IConvertedPokerAction convertedAction = ConvertedActionFrom(whatAndRatio); return(new ConvertedPokerActionWithId(convertedAction, playerId)); }
public void Convert_Win_SetsConvertedRatioToAquiredRatioDividedByTotalPot() { const ActionTypes actionType = ActionTypes.W; const double aquiredRatio = 2.0; const double totalPot = 4.0; const double expectedRatio = aquiredRatio / totalPot; double somePot = 1.0; double someToCall = 1.5; var aquiredAction = new AquiredPokerAction(actionType, aquiredRatio); IConvertedPokerAction convertedAction = _converter.Convert( aquiredAction, ref somePot, ref someToCall, totalPot); Assert.That(convertedAction.Ratio, Is.EqualTo(expectedRatio)); }
ProcessRound_PreflopAquPlayerWithOneRoundConPlayerWithOneRound_AddsPreflopActionToConvertedPokerPlayerFirstRound () { const ActionTypes someActionType = ActionTypes.C; const double someRatio = 1.0; IAquiredPokerRound aquiredRound = new AquiredPokerRound() .Add(new AquiredPokerAction(someActionType, someRatio)); IConvertedPokerPlayer convertedPlayer = new ConvertedPokerPlayer().Add(); _converter.InvokeProcessRound(Streets.PreFlop, aquiredRound, convertedPlayer); IConvertedPokerAction firstPreflopAction = convertedPlayer[Streets.PreFlop][0]; const int first = 0; Assert.That(firstPreflopAction, Is.EqualTo(aquiredRound[first])); }
/// <summary> /// Gives a string representation of the action to be entered into the database /// </summary> static string BuildSqlStringFrom(IConvertedPokerAction convertedAction) { switch (convertedAction.What) { case ActionTypes.A: case ActionTypes.X: case ActionTypes.F: return(string.Format("{0}", convertedAction.What)); case ActionTypes.E: case ActionTypes.N: case ActionTypes.P: case ActionTypes.U: Log.DebugFormat("Encountered this illegal action {0}, returning empty string.", convertedAction.What); return(string.Empty); default: return(string.Format("{0}{1:F1}", convertedAction.What, convertedAction.Ratio)); } }
ProcessRound_PreflopAquPlayerWithTwoRoundsConPlayerWithOneRoundActionCountOne_AddsSecondPreflopActionAsFirstActionOfConvertedPokerPlayersFirstRound () { const ActionTypes firstActionType = ActionTypes.C; const ActionTypes secondActionType = ActionTypes.F; const double someRatio = 1.0; IAquiredPokerRound aquiredRound = new AquiredPokerRound() .Add(new AquiredPokerAction(firstActionType, someRatio)) .Add(new AquiredPokerAction(secondActionType, someRatio)); IConvertedPokerPlayer convertedPlayer = new ConvertedPokerPlayer().Add(); _converter.ActionCountProp = 1; _converter.InvokeProcessRound(Streets.PreFlop, aquiredRound, convertedPlayer); IConvertedPokerAction addedPreflopAction = convertedPlayer[Streets.PreFlop][0]; const int second = 1; Assert.That(addedPreflopAction, Is.EqualTo(aquiredRound[second])); }
/// <summary> /// Determines a Sequence string, representing, what the player did in a round /// </summary> /// <param name="currentSequence"> /// Actions affecting us that happened so far /// </param> /// <param name="myNextAction"> /// What am I about to do /// </param> /// <param name="street"> /// Preflop,Flop, Turn, etc. /// </param> /// <para> /// Sequences are of the following format: /// Relevant actions are listed in order. ActionTypes abreviations are used, except for bet, in that case /// the normalized Bet size is listed. /// if we assume a bet of 0.5 which is normalized to 5 (multiplied by 10), we end up with the following /// representations for the following ActionSequences /// HeroB - "5" /// HeroXOppBHeroF - "X5F" /// HeroXOppBHeroC - "X5C" /// HeroXOppBHeroR - "X5R" /// OppBHeroF - "5F" /// OppBHeroC - "5C" /// OppBHeroR - "5R" /// Preflop - "F" or "C", or "R" /// It will also produce Sequences such as "X5RC" (he checked, opp bet 0.5, another opp raised and he called) /// These don't fit in any of the above standard situations and cannot be included in the standard /// statistics analysis. /// They will automatically be ignored when querying for statistics because they won't match any of the /// standard Sequence strings. /// </para> public void SetActionSequenceString( ref string currentSequence, IConvertedPokerAction myNextAction, Streets street) { // Add what we did and what happened so far to determine our ActionSequence // Once we added a sequence part w/ a number (which represents a bet), we will stop adding to the sequence // because we don't want to get so deep into the sequence. For instance we want to know, if he raised a bet but not // how he reacted to a reraise to that raise. // These further reactions will be analysed, once the user requests it // Preflop we only are interested in the first action if (street == Streets.PreFlop) { // Only consider first action/reaction if (string.IsNullOrEmpty(SequenceStrings[(int)street])) { // CurrentSequence will be empty for unraised pot and contain R for each raise/reraise in a raised pot SequenceStrings[(int)street] = currentSequence + myNextAction.What; // It is now a raised pot for all players to come if (myNextAction.What == ActionTypes.R) { currentSequence = currentSequence + myNextAction.What; } } return; } if (SequenceStrings[(int)street] == null) { SequenceStrings[(int)street] = string.Empty; } // PostFlop, once we have a bet or reaction to bet (represented by number) we don't need to know more const string patContainsNumber = "[0-9]"; if (Regex.IsMatch(SequenceStrings[(int)street], patContainsNumber)) { return; } switch (myNextAction.What) { case ActionTypes.F: case ActionTypes.C: case ActionTypes.X: SequenceStrings[(int)street] = SequenceStrings[(int)street] + currentSequence + myNextAction.What; break; case ActionTypes.B: var normalizedRatio = (int) (10.0 * Normalizer.NormalizeToKeyValues(ApplicationProperties.BetSizeKeys, myNextAction.Ratio)); SequenceStrings[(int)street] = SequenceStrings[(int)street] + currentSequence + normalizedRatio; currentSequence = currentSequence + normalizedRatio; break; case ActionTypes.R: SequenceStrings[(int)street] = SequenceStrings[(int)street] + currentSequence + myNextAction.What; currentSequence = currentSequence + myNextAction.What; break; } }
/// <summary> /// Initializes a new instance of the <see cref="ConvertedPokerActionWithId"/> class. /// </summary> /// <param name="convertedAction"> /// The converted action. /// </param> /// <param name="id"> /// The id. /// </param> public ConvertedPokerActionWithId(IConvertedPokerAction convertedAction, int id) { InitializeWith(convertedAction, id); }
public IConvertedPokerActionWithId InitializeWith(IConvertedPokerAction convertedAction, int id) { return(InitializeWith(convertedAction.What, convertedAction.Ratio, id)); }