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); }
IConvertedPokerPlayer CreatePlayerFromDatabase(IDataRecord dr) { IConvertedPokerPlayer convPlayer = _convertedPlayerMake.New; convPlayer.MBefore = Convert.ToInt32(dr[ActionTable.m.ToString()].ToString()); convPlayer.Position = Convert.ToInt32(dr[ActionTable.position.ToString()].ToString()); convPlayer.Holecards = dr[ActionTable.cards.ToString()].ToString(); convPlayer.PlayerId = long.Parse(dr[ActionTable.playerid.ToString()].ToString()); return(convPlayer); }
public void Get_SavedPlayer_RestoresMBefore() { _player.MBefore = 1; _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.MBefore.ShouldBeEqualTo(_player.MBefore); }
/// <summary> /// The init poker player. /// </summary> private void InitPokerPlayer() { _pokerPlayer = new ConvertedPokerPlayer("hero", 10, 5, 2, 9, "As Kd"); _pokerPlayer.Add(new ConvertedPokerRound()); _pokerPlayer[Streets.PreFlop].Add(new ConvertedPokerAction(ActionTypes.R, 3.4)); _pokerPlayer[Streets.PreFlop].Add(new ConvertedPokerAction(ActionTypes.R, 2.4)); _pokerPlayer[Streets.PreFlop].Add(new ConvertedPokerAction(ActionTypes.C, 0.3)); _pokerPlayer.Add(new ConvertedPokerRound()); _pokerPlayer[Streets.Flop].Add(new ConvertedPokerAction(ActionTypes.B, 0.4)); _handHistoryRow = new HandHistoryRow(_pokerPlayer); }
public void Get_SavedPlayer_RestoresStategicPosition() { _player.Position = 1; _player.SetStrategicPosition(_hand.TotalPlayers); _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.StrategicPosition.ShouldBeEqualTo(_player.StrategicPosition); }
public int CompareTo(IConvertedPokerPlayer other) { if (Position < other.Position) { return(-1); } if (Position > other.Position) { return(1); } return(0); }
public void Get_SavedPlayer_RestoresBetSizeIndexesArray() { _player.BetSizeIndexes[(int)Streets.Flop] = 1; _player.BetSizeIndexes[(int)Streets.Turn] = 2; _player.BetSizeIndexes[(int)Streets.River] = 3; _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.BetSizeIndexes.ShouldBeEqualTo(_player.BetSizeIndexes); }
public void Get_SavedPlayer_RestoresActionSequencesArray() { _player.ActionSequences[(int)Streets.PreFlop] = ActionSequences.HeroF; _player.ActionSequences[(int)Streets.Flop] = ActionSequences.HeroB; _player.ActionSequences[(int)Streets.Turn] = ActionSequences.HeroXOppBHeroF; _player.ActionSequences[(int)Streets.River] = ActionSequences.HeroB; _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.ActionSequences.ShouldBeEqualTo(_player.ActionSequences); }
public void _Init() { _session.Clear(); new SchemaExport(_configuration).Execute(false, true, false, _session.Connection, null); _hand = new ConvertedPokerHand("someSite", 1, DateTime.MinValue, 2, 1, 2); var playerIdentity = new PlayerIdentity(Name, Site); _session.Save(playerIdentity); _player = new ConvertedPokerPlayer { PlayerIdentity = playerIdentity }; }
public void Get_SavedPlayer_RestoresInPositionArray() { _player.InPosition[(int)Streets.PreFlop] = true; _player.InPosition[(int)Streets.Flop] = true; _player.InPosition[(int)Streets.Turn] = true; _player.InPosition[(int)Streets.River] = true; _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.InPosition.ShouldBeEqualTo(_player.InPosition); }
public void _Init() { _stub = new StubBuilder(); _heroName = "hero"; _convertedHand = new ConvertedPokerHand(); _heroPlayer = new ConvertedPokerPlayer( _heroName, _stub.Some <double>(), _stub.Some <double>(), _stub.Valid(For.Position, 1), _stub.Valid(For.TotalPlayers, 2), _stub.Valid(For.HoleCards, string.Empty)); _sawFlopCondition = new SawFlopCondition().AppliesTo(_heroName); }
/// <summary> /// Gives string representation for an Html Row containing this Players information /// </summary> public static string BuildFrom(IConvertedPokerPlayer convertedPlayer, bool markRow) { var strToHtml = new StringBuilder(); string strMarkRow = string.Empty; bool Indent; if (markRow) { strMarkRow = " bgcolor=\"#DCDCDC\""; } // Header strToHtml.AppendLine("\t\t\t<tr valign=\"top\" halign=\"left\"" + strMarkRow + ">"); // Position strToHtml.AppendLine( string.Format( "\t\t\t\t<td align=\"center\"><font size=\"2\">{0}</td>", convertedPlayer.StrategicPosition)); // Name strToHtml.AppendLine(string.Format("\t\t\t\t<td><font size=\"2\">{0}</td>", convertedPlayer.Name)); // Cards strToHtml.AppendLine( string.Format( "\t\t\t\t<td align=\"center\"><font size=\"2\">{0}</td>", HoleCardsToHtml(convertedPlayer.Holecards))); // BB strToHtml.AppendLine( string.Format("\t\t\t\t<td align=\"center\"><font size=\"2\">{0}</td>", convertedPlayer.MBefore)); // Bettingrounds foreach (IConvertedPokerRound round in convertedPlayer) { Indent = convertedPlayer.StrategicPosition <= StrategicPositions.BB && convertedPlayer.Rounds.IndexOf(round) == (int)Streets.PreFlop; strToHtml.AppendLine(BuildFrom(round, Indent)); } // Footer strToHtml.AppendLine("\t\t\t</tr>"); return(strToHtml.ToString()); }
public IPlayerOverlayViewModel UpdateStatusWith(IConvertedPokerPlayer pokerPlayer) { _mostRecentPokerPlayer = pokerPlayer; if (pokerPlayer == null) { PlayerStatus.IsPresent = false; return(this); } PlayerName = pokerPlayer.Name; PlayerStatus.HarringtonM.Value = pokerPlayer.MAfter; // An M value <= 0 indicates that he was eliminated during the last hand PlayerStatus.IsPresent = pokerPlayer.MAfter > 0; return(this); }
public void Get_SavedPlayer_RestoresRoundsArray() { var sampleRound = new ConvertedPokerRound() .Add(new ConvertedPokerAction(ActionTypes.B, 1.0)); _player .Add(sampleRound) .Add(sampleRound) .Add(sampleRound) .Add(sampleRound); _hand.AddPlayer(_player); _session.Save(_hand); FlushAndClearSession(); IConvertedPokerPlayer retrievedPlayer = _session.Get <ConvertedPokerPlayer>(_player.Id); retrievedPlayer.Rounds.ShouldBeEqualTo(_player.Rounds); }
bool UpdatePlayerTable(IConvertedPokerHand convHand, IConvertedPokerPlayer convPlayer) { string nonQuery = string.Format( "INSERT INTO {1} " + "( {2}, {3}, {4} )" + "VALUES" + "( null, {0}{3}, {0}{4} );", _dataProvider.ParameterPlaceHolder, Tables.playerhhd, PlayerTable.playerid, PlayerTable.site, PlayerTable.nickname); using (IDbCommand cmd = _dataProvider.GetCommand()) { cmd.CommandText = nonQuery; // Site IDataParameter param = cmd.CreateParameter(); param.ParameterName = string.Format("{0}{1}", _dataProvider.ParameterPlaceHolder, PlayerTable.site); param.Value = convHand.Site; param.DbType = DbType.StringFixedLength; cmd.Parameters.Add(param); // nickname param = cmd.CreateParameter(); param.ParameterName = string.Format("{0}{1}", _dataProvider.ParameterPlaceHolder, PlayerTable.nickname); param.Value = convPlayer.Name; param.DbType = DbType.StringFixedLength; cmd.Parameters.Add(param); int rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected > 0) { return(true); } else { return(false); } } }
public void ConvertPreflop_Player1IsSmallBlind__SetsOverallPreflopSequenceCorrectly() { RelativeRatioResult result = ConvertPreflopHeadsUpHand(); IConvertedPokerHand convHand = result.ConvertedHand; IConvertedPokerPlayer smallBlindPlayer = convHand[0]; IConvertedPokerPlayer bigBlindPlayer = convHand[1]; var action1 = new ConvertedPokerActionWithId( smallBlindPlayer[Streets.PreFlop][0], smallBlindPlayer.Position); var action2 = new ConvertedPokerActionWithId(bigBlindPlayer[Streets.PreFlop][0], bigBlindPlayer.Position); var action3 = new ConvertedPokerActionWithId( smallBlindPlayer[Streets.PreFlop][1], smallBlindPlayer.Position); var action4 = new ConvertedPokerActionWithId(bigBlindPlayer[Streets.PreFlop][1], bigBlindPlayer.Position); IConvertedPokerRound expectedPreflopSequence = new ConvertedPokerRound() .Add(action1) .Add(action2) .Add(action3) .Add(action4); Assert.That(expectedPreflopSequence, Is.EqualTo(convHand.Sequences[(int)Streets.PreFlop])); }
void ExtractPlayersFromDatabase(int handId, IConvertedPokerHand convertedHand) { string query = string.Format( "SELECT * FROM {0} WHERE {1} = {2};", Tables.actionhhd, ActionTable.handid, handId); using (IDataReader dr = _dataProvider.ExecuteQuery(query)) { // Iterate through all found players while (dr.Read()) { IConvertedPokerPlayer convPlayer = ExtractPlayer(dr); convertedHand.AddPlayer(convPlayer); } } ExtractNamesForAllPlayers(convertedHand); convertedHand.SetStrategicPositionsForAllPlayers(); }
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(); } } } } }
/// <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); }
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); } }
static void ExtractInPositionFields(IConvertedPokerPlayer convPlayer, IDataRecord dr) { convPlayer.InPosition[(int)Streets.Flop] = dr.GetInt32((int)ActionTable.inposflop); convPlayer.InPosition[(int)Streets.Turn] = dr.GetInt32((int)ActionTable.inposturn); convPlayer.InPosition[(int)Streets.River] = dr.GetInt32((int)ActionTable.inposriver); }
public HandHistoryRow(IConvertedPokerPlayer pokerPlayer) { _pokerPlayer = pokerPlayer; }
/// <summary> /// Remove a Poker Player /// Needed when converting hand /// </summary> /// <param name="thePlayer">Player to remove</param> /// <returns>true if player could be removed</returns> public bool RemovePlayer(IConvertedPokerPlayer thePlayer) { // throw new NotImplementedException(); return(true); }
/// <summary> /// Add Player when creating a hand from /// the database. /// </summary> /// <param name="convertedPlayer"> /// The converted Player. /// </param> public IConvertedPokerHand AddPlayer(IConvertedPokerPlayer convertedPlayer) { return(this); }
int GetPlayerID(IConvertedPokerHand convHand, IConvertedPokerPlayer convPlayer) { string query = string.Format( "SELECT {2} FROM {1} " + "WHERE {3} = {0}{3} " + "AND {4} = {0}{4};", _dataProvider.ParameterPlaceHolder, Tables.playerhhd, PlayerTable.playerid, PlayerTable.nickname, PlayerTable.site); try { int playerID = -1; using (IDbCommand cmd = _dataProvider.GetCommand()) { cmd.CommandText = query; // nickname IDataParameter param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, PlayerTable.nickname); param.Value = convPlayer.Name; param.DbType = DbType.StringFixedLength; cmd.Parameters.Add(param); // Site param = cmd.CreateParameter(); param.ParameterName = string.Format("{0}{1}", _dataProvider.ParameterPlaceHolder, PlayerTable.site); param.Value = convHand.Site; param.DbType = DbType.StringFixedLength; cmd.Parameters.Add(param); using (IDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { playerID = dr.GetInt32((int)PlayerTable.playerid); } } } if (playerID == -1) { bool successfullyEnteredPlayer = UpdatePlayerTable(convHand, convPlayer); if (successfullyEnteredPlayer) { playerID = GetIdentityOfLastEnteredPlayer(); } } return(playerID); } catch (Exception excep) { Log.Error("Unexpected", excep); Log.Debug("Query: " + query); Console.WriteLine(excep.ToString()); return(0); } }
void UpdateActionTable(int handID, int playerID, IConvertedPokerPlayer convPlayer) { string[] strAction; string[] strSequence = PrepareActionsAndSequences(convPlayer, out strAction); string nonQuery = string.Format( "INSERT INTO {1} " + "( {2}, {3}, {4}, {5}, {6}, " + "{7}, {8}, {9}, {10}, {11}," + "{12}, {13}, {14}, {15}, {16}," + " {17}, {18}, {19} )" + "VALUES " + "( {0}{2}, {0}{3}, {0}{4}, {0}{5}, {0}{6}, " + "{0}{7}, {0}{8}, {0}{9}, {0}{10}, {0}{11}," + "{0}{12}, {0}{13}, {0}{14}, {0}{15}, {0}{16}," + " {0}{17}, {0}{18}, {0}{19} );", _dataProvider.ParameterPlaceHolder, Tables.actionhhd, ActionTable.playerid, ActionTable.handid, ActionTable.m, ActionTable.cards, ActionTable.position, ActionTable.strategicposition, ActionTable.inposflop, ActionTable.inposturn, ActionTable.inposriver, ActionTable.raiseinfrontpreflopfrompos, ActionTable.action0, ActionTable.action1, ActionTable.action2, ActionTable.action3, ActionTable.sequence0, ActionTable.sequence1, ActionTable.sequence2, ActionTable.sequence3); try { using (IDbCommand cmd = _dataProvider.GetCommand()) { cmd.CommandText = nonQuery; // PlayerId IDataParameter param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.playerid); param.Value = playerID; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // handID param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.handid); param.Value = handID; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // m param = cmd.CreateParameter(); param.ParameterName = string.Format("{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.m); param.Value = convPlayer.MBefore; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // Cards param = cmd.CreateParameter(); param.ParameterName = string.Format("{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.cards); param.Value = convPlayer.Holecards; param.DbType = DbType.StringFixedLength; cmd.Parameters.Add(param); // Position param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.position); param.Value = convPlayer.Position; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // StrategicPosition param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.strategicposition); param.Value = (int)convPlayer.StrategicPosition; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // InPosition Flop param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.inposflop); param.Value = convPlayer.InPosition[(int)Streets.Flop]; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // InPosition Turn param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.inposturn); param.Value = convPlayer.InPosition[(int)Streets.Turn]; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // InPosition River param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.inposriver); param.Value = convPlayer.InPosition[(int)Streets.River]; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // Raiseinfrontpreflop param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.raiseinfrontpreflopfrompos); param.Value = convPlayer.PreflopRaiseInFrontPos; param.DbType = DbType.Int32; cmd.Parameters.Add(param); // action0 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.action0); param.Value = strAction[(int)Streets.PreFlop]; param.DbType = DbType.String; cmd.Parameters.Add(param); // action1 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.action1); param.Value = strAction[(int)Streets.Flop]; param.DbType = DbType.String; cmd.Parameters.Add(param); // action2 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.action2); param.Value = strAction[(int)Streets.Turn]; param.DbType = DbType.String; cmd.Parameters.Add(param); // action3 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.action3); param.Value = strAction[(int)Streets.River]; param.DbType = DbType.String; cmd.Parameters.Add(param); // sequence0 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.sequence0); param.Value = strSequence[(int)Streets.PreFlop]; param.DbType = DbType.String; cmd.Parameters.Add(param); // sequence1 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.sequence1); param.Value = strSequence[(int)Streets.Flop]; param.DbType = DbType.String; cmd.Parameters.Add(param); // sequence2 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.sequence2); param.Value = strSequence[(int)Streets.Turn]; param.DbType = DbType.String; cmd.Parameters.Add(param); // sequence3 param = cmd.CreateParameter(); param.ParameterName = string.Format( "{0}{1}", _dataProvider.ParameterPlaceHolder, ActionTable.sequence3); param.Value = strSequence[(int)Streets.River]; param.DbType = DbType.String; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } } catch (Exception excep) { Log.Error("Unexpected", excep); Log.Debug(nonQuery); } }
public void InvokeProcessRound(Streets street, IAquiredPokerRound aquiredPokerRound, IConvertedPokerPlayer convertedPlayer) { ProcessRound(street, aquiredPokerRound, convertedPlayer); }