/// <summary> /// Remove Posting and set BettingRound to null if no actions were left /// Antes and Blinds will be added to pot during removal /// </summary> /// <param name="aquiredHand">PokerHand</param> /// <returns>The pot at the beginning of the hand - containing blinds and antes</returns> protected virtual double RemovePostingActionsAndCalculatePotAfterPosting(ref IAquiredPokerHand aquiredHand) { double sumOfAllPostingAmounts = 0; var playersToRemove = new List <IAquiredPokerPlayer>(); foreach (IAquiredPokerPlayer aquiredPlayer in aquiredHand) { // Does player have a round? if (aquiredPlayer.Count > (int)Streets.PreFlop) { IAquiredPokerRound preflopRound = aquiredPlayer[Streets.PreFlop]; if (NoActionsLeftAfterRemovingPostingActionsFromRound(ref preflopRound, ref sumOfAllPostingAmounts)) { // Must have been a sitout, otherwise he's have at least a preflop fold left playersToRemove.Add(aquiredPlayer); } } else { // if player has no round, remove him b/c there is nothing he contributed to the hand // not even a fold (so he was probably sitting out) playersToRemove.Add(aquiredPlayer); } } foreach (IAquiredPokerPlayer aquiredPlayer in playersToRemove) { aquiredHand.RemovePlayer(aquiredPlayer); } return(sumOfAllPostingAmounts); }
static Mock <IPokerHandParser> ParserThatRecognizesAndSeparatesHandsAndParseSetsAquiredHandTo(ulong gameId) { const string extractedHistory = "someHistory"; const int extractedGameId = 1; var extractedHistories = new Dictionary <ulong, string> { { extractedGameId, extractedHistory } }; Mock <IPokerHandParser> stubParser = ParserThatRecognizesHandsAndWhenExtractingHandsReturns(extractedHistories, SomeHandHistoriesString); var stub = new StubBuilder(); IAquiredPokerHand stubAquiredHand = stub.Setup <IAquiredPokerHand>() .Get(p => p.GameId) .Returns(gameId).Out; stubParser .Setup(p => p.AquiredPokerHand) .Returns(stubAquiredHand); stubParser .Setup(p => p.IsValid) .Returns(true); stubParser .Setup(p => p.ParseHand(It.IsAny <string>())) .Returns(stubParser.Object); return(stubParser); }
public void _Init() { const int someGameId = 1; DateTime someDateTime = DateTime.MinValue; const int someTotalPlayers = 6; _aquiredHand = new AquiredPokerHand( "SomeSite", someGameId, someDateTime, BigBlind, SmallBlind, someTotalPlayers); }
public IPokerRoundsConverter InitializeWith( IAquiredPokerHand aquiredHand, IConvertedPokerHand convertedHand, double pot, double toCall) { ToCall = toCall; Pot = pot; _convertedHand = convertedHand; _aquiredHand = aquiredHand; return(this); }
/// <summary> /// The copy additional properties from. /// </summary> /// <param name="aquiredHand"> /// The aquired hand. /// </param> void CopyAdditionalPropertiesFrom(IAquiredPokerHand aquiredHand) { AllNames = aquiredHand.AllNames; Board = aquiredHand.Board; TableName = aquiredHand.TableName; TotalSeats = aquiredHand.TotalSeats; TournamentId = aquiredHand.TournamentId; Ante = aquiredHand.Ante; HeroName = aquiredHand.HeroName; GameType = aquiredHand.GameType; HandHistory = aquiredHand.HandHistory; }
/// <summary> /// The initialize with. /// </summary> /// <param name="aquiredHand"> /// The aquired hand. /// </param> /// <returns> /// </returns> public IConvertedPokerHand InitializeWith(IAquiredPokerHand aquiredHand) { InitializeWith( aquiredHand.Site, aquiredHand.GameId, aquiredHand.TimeStamp, aquiredHand.BB, aquiredHand.SB, aquiredHand.TotalPlayers); CopyAdditionalPropertiesFrom(aquiredHand); return(this); }
public void _Init() { _stub = new StubBuilder(); _aquiredHand = new AquiredPokerHand().InitializeWith( _stub.Valid(For.Site, "site"), _stub.Out <ulong>(For.GameId), _stub.Out <DateTime>(For.TimeStamp), _stub.Valid(For.SB, 1.0), _stub.Valid(For.BB, 2.0), _stub.Valid(For.TotalPlayers, 2)); _convertedHand = new ConvertedPokerHand(_aquiredHand); _convertedPlayerMake = new Constructor <IConvertedPokerPlayer>(() => new ConvertedPokerPlayer()); }
IConvertedPokerHand ConvertHandAndAddToParsedHands(IAquiredPokerHand aquiredPokerHand) { IConvertedPokerHand convertedPokerHand = _pokerHandConverterMake.New.ConvertAquiredHand(aquiredPokerHand); if (convertedPokerHand != null) { lock (_parsedHands) { if (!_parsedHands.ContainsKey(convertedPokerHand.GameId)) { _parsedHands.Add(convertedPokerHand.GameId, convertedPokerHand); } } return(convertedPokerHand); } throw new NullReferenceException("convertedPokerHand when converting: \n" + aquiredPokerHand); }
/// <summary> /// The add players from. /// </summary> /// <param name="aquiredHand"> /// The aquired hand. /// </param> /// <param name="startingPot"> /// The starting pot. /// </param> /// <param name="convertedPlayerMake"> /// The converted player make. /// </param> /// <returns> /// </returns> public IConvertedPokerHand AddPlayersFrom( IAquiredPokerHand aquiredHand, double startingPot, IConstructor <IConvertedPokerPlayer> convertedPlayerMake) { foreach (IAquiredPokerPlayer aquiredPlayer in aquiredHand) { double mBefore = startingPot > 0 ? aquiredPlayer.StackBefore / startingPot : 0; double mAfter = startingPot > 0 ? aquiredPlayer.StackAfter / startingPot : 0; IConvertedPokerPlayer convertedPlayer = convertedPlayerMake.New.InitializeWith( aquiredPlayer.Name, mBefore, mAfter, aquiredPlayer.Position, aquiredHand.TotalPlayers, aquiredPlayer.Holecards); convertedPlayer.SeatNumber = aquiredPlayer.SeatNumber; AddPlayer(convertedPlayer); } return(this); }
/// <summary> /// Converts the given Hand with absolute ratios into a Hand with relative ratios /// It assumes all Players of the Hand were sorted previously /// </summary> /// <param name="sortedAquiredHand">Hand to be converted</param> /// <returns>Converted Hand</returns> public IConvertedPokerHand ConvertAquiredHand(IAquiredPokerHand sortedAquiredHand) { if (sortedAquiredHand == null) { Log.Debug("AquiredHand was null, returning null"); return(null); } if (sortedAquiredHand.TotalPlayers < 2 || sortedAquiredHand.TotalPlayers > 10) { Log.DebugFormat("AquiredHand had {0} players.\n<{1}>", sortedAquiredHand.TotalPlayers, sortedAquiredHand); return(null); } // At this point Players are already sorted according to their Positions // Now parse through the hand and create the relative actions // Start w/ SB except for Preflop try { // First we just need to call the big blind double toCall = sortedAquiredHand.BB; double theoreticalStartingPot = sortedAquiredHand.BB + sortedAquiredHand.SB + (sortedAquiredHand.Ante * sortedAquiredHand.TotalPlayers); // This could be different from the theoretical starting pot if a player // posted out of line (like from middle position) -> the actual pot at the beginning // of the hand will be bigger than the theoretical pot double pot = RemovePostingActionsAndCalculatePotAfterPosting(ref sortedAquiredHand); // PokerOffice sometimes didn't store posting Actions // This will ignore Ante though if (pot <= 0) { pot = theoreticalStartingPot; } IConvertedPokerHand convertedHand = _convertedHandMake.New .InitializeWith(sortedAquiredHand) .AddPlayersFrom(sortedAquiredHand, theoreticalStartingPot, _convertedPlayerMake); convertedHand = _pokerRoundsConverter .InitializeWith(sortedAquiredHand, convertedHand, pot, toCall) .ConvertPreflop() .ConvertFlopTurnAndRiver(); convertedHand .RemoveInactivePlayers() .SetNumOfPlayersInEachRound() .AdjustOrderOfPlayersIfItIsHeadsUp() .SetWhoHasPositionInEachRound(); foreach (var player in convertedHand) { player.SetActionSequencesAndBetSizeKeysFromSequenceStrings(); } return(convertedHand); } catch (Exception excep) { Log.Error("Unhandled", excep); return(null); } }
public IConvertedPokerHand InitializeWith(IAquiredPokerHand aquiredHand) { // throw new NotImplementedException(); return(this); }
public IConvertedPokerHand AddPlayersFrom( IAquiredPokerHand aquiredHand, double startingPot, IConstructor <IConvertedPokerPlayer> convertedPlayerMake) { // throw new NotImplementedException(); return(this); }
public PokerHandParserSut Set_AquiredPokerHand(IAquiredPokerHand aquiredPokerHand) { AquiredPokerHand = aquiredPokerHand; return(this); }
public double CallRemovePostingActionsAndCalculatePotAfterPosting(ref IAquiredPokerHand aquiredHand) { return(RemovePostingActionsAndCalculatePotAfterPosting(ref aquiredHand)); }
/// <summary> /// Initializes a new instance of the <see cref="ConvertedPokerHand"/> class. /// </summary> /// <param name="aquiredHand"> /// The aquired hand. /// </param> public ConvertedPokerHand(IAquiredPokerHand aquiredHand) { InitializeWith(aquiredHand); }