/*public static int GetKicker( List<ResultEntry> entries ) * { * int startIndex = 0; * * switch ( entries[0].Rank ) * { * case HandRank.None: startIndex = 1; break; * case HandRank.OnePair: startIndex = 2; break; * case HandRank.ThreeOfAKind: startIndex = 3; break; * case HandRank.FourOfAKind: * case HandRank.TwoPairs: return 4; * } * * for ( int i = startIndex; i < 4; ++i ) * { * foreach ( ResultEntry entry in entries ) * if ( entry.BestCards[i].Rank != entries[0].BestCards[i].Rank ) * startIndex = i; * } * * return startIndex; * }*/ /// <summary> /// Returns whether the left Result entry is better than the right /// </summary> public static RankResult IsBetterThan(ResultEntry left, ResultEntry right) { if (left.Rank > right.Rank) { return(RankResult.Better); } if (left.Rank < right.Rank) { return(RankResult.Worse); } //Ranks are the same if (left.Rank != HandRank.RoyalFlush) { for (int i = 0; i < left.BestCards.Count; ++i) { if (left.BestCards[i].Rank > right.BestCards[i].Rank) { return(RankResult.Better); } if (left.BestCards[i].Rank < right.BestCards[i].Rank) { return(RankResult.Worse); } } } return(RankResult.Same); }
/// <summary> /// Returns whether the left Result entry is better than the right /// </summary> public static RankResult IsBetterThan(ResultEntry left, ResultEntry right) { if (left.Rank > right.Rank) { return RankResult.Better; } if (left.Rank < right.Rank) { return RankResult.Worse; } //Ranks are the same if (left.Rank != HandRank.RoyalFlush) { for (int i = 0; i < left.BestCards.Count; ++i) { if (left.BestCards[i].Rank > right.BestCards[i].Rank) { return RankResult.Better; } if (left.BestCards[i].Rank < right.BestCards[i].Rank) { return RankResult.Worse; } } } return RankResult.Same; }
public static string RankString(ResultEntry entry) { switch (entry.Rank) { case HandRank.None: return String.Format("high card {0}", entry.BestCards[0].RankString); case HandRank.OnePair: return String.Format("a pair of {0}s", entry.BestCards[0].RankString); case HandRank.TwoPairs: return String.Format("two pairs: {0}s and {1}s", entry.BestCards[0].RankString, entry.BestCards[2].RankString); case HandRank.ThreeOfAKind: return String.Format("three {0}s", entry.BestCards[0].RankString); case HandRank.Straight: return String.Format( "a straight: high {0} to low {1}", entry.BestCards[0].RankString, entry.BestCards[4].RankString); case HandRank.Flush: return String.Format("a flush: high card {0}", entry.BestCards[0].RankString); case HandRank.FullHouse: return String.Format( "a full house: 3 {0}s and 2 {1}s", entry.BestCards[0].RankString, entry.BestCards[3].RankString); case HandRank.FourOfAKind: return String.Format("four {0}s", entry.BestCards[0].RankString); case HandRank.StraightFlush: return String.Format("a straight flush: {0} to {1}", entry.BestCards[0].Name, entry.BestCards[4].Name); case HandRank.RoyalFlush: return "a royal flush"; } return String.Empty; }
public JackpotInfo(List<PokerPlayer> winners, ResultEntry hand, DateTime date, Type currency) { Winners = winners; Hand = hand; Date = date; TypeOfCurrency = currency; }
public int CompareTo(object obj) { if (obj is ResultEntry) { ResultEntry entry = (ResultEntry)obj; RankResult result = HandRanker.IsBetterThan(this, entry); if (result == RankResult.Better) { return(-1); } if (result == RankResult.Worse) { return(1); } } return(0); }
public static string RankString(ResultEntry entry) { switch (entry.Rank) { case HandRank.None: return(String.Format("high card {0}", entry.BestCards[0].RankString)); case HandRank.OnePair: return(String.Format("a pair of {0}s", entry.BestCards[0].RankString)); case HandRank.TwoPairs: return(String.Format("two pairs: {0}s and {1}s", entry.BestCards[0].RankString, entry.BestCards[2].RankString)); case HandRank.ThreeOfAKind: return(String.Format("three {0}s", entry.BestCards[0].RankString)); case HandRank.Straight: return(String.Format( "a straight: high {0} to low {1}", entry.BestCards[0].RankString, entry.BestCards[4].RankString)); case HandRank.Flush: return(String.Format("a flush: high card {0}", entry.BestCards[0].RankString)); case HandRank.FullHouse: return(String.Format( "a full house: 3 {0}s and 2 {1}s", entry.BestCards[0].RankString, entry.BestCards[3].RankString)); case HandRank.FourOfAKind: return(String.Format("four {0}s", entry.BestCards[0].RankString)); case HandRank.StraightFlush: return(String.Format("a straight flush: {0} to {1}", entry.BestCards[0].Name, entry.BestCards[4].Name)); case HandRank.RoyalFlush: return("a royal flush"); } return(String.Empty); }
public PokerPlayer AssignNextTurn() { PokerPlayer nextTurn = Players.Next(); if (nextTurn == null) { return(null); } if (nextTurn.RequestLeave) { Players.Push(nextTurn); nextTurn.BetStart = DateTime.UtcNow; nextTurn.Action = PlayerAction.Fold; return(nextTurn); } if (nextTurn.IsAllIn) { Players.Push(nextTurn); nextTurn.BetStart = DateTime.UtcNow; nextTurn.Action = PlayerAction.AllIn; return(nextTurn); } if (nextTurn.LonePlayer) { Players.Push(nextTurn); nextTurn.BetStart = DateTime.UtcNow; nextTurn.Action = PlayerAction.Check; return(nextTurn); } bool canCall = false; PokerPlayer currentTurn = Players.Peek(); if (currentTurn != null && currentTurn.Action != PlayerAction.Check && currentTurn.Action != PlayerAction.Fold) { canCall = true; } if (currentTurn == null && State == PokerGameState.PreFlop) { canCall = true; } Players.Push(nextTurn); nextTurn.BetStart = DateTime.UtcNow; var entry = new ResultEntry(nextTurn); List <Card> bestCards; entry.Rank = nextTurn.GetBestHand(CommunityCards, out bestCards); entry.BestCards = bestCards; nextTurn.SendMessage(0x22, String.Format("You have {0}.", HandRanker.RankString(entry))); nextTurn.CloseGump(typeof(PokerBetGump)); nextTurn.SendGump(new PokerBetGump(this, nextTurn, canCall)); NeedsGumpUpdate = true; return(nextTurn); }
public List<PokerPlayer> GetWinners( bool silent ) { List<ResultEntry> results = new List<ResultEntry>(); for ( int i = 0; i < m_Players.Round.Count; ++i ) { ResultEntry entry = new ResultEntry( m_Players.Round[i] ); List<Card> bestCards = new List<Card>(); entry.Rank = HandRanker.GetBestHand( entry.Player.GetAllCards( m_CommunityCards ), out bestCards ); entry.BestCards = bestCards; results.Add( entry ); /*if ( !silent ) { //Check if kickers needed PokerMessage( entry.Player.Mobile, String.Format( "I have {0}.", HandRanker.RankString( entry ) ) ); }*/ } results.Sort(); if ( results.Count < 1 ) return null; List<PokerPlayer> winners = new List<PokerPlayer>(); for ( int i = 0; i < results.Count; ++i ) if ( HandRanker.IsBetterThan( results[i], results[0] ) == RankResult.Same ) winners.Add( results[i].Player ); //IF NOT SILENT if ( !silent ) { //Only hands that have made it past the showdown may be considered for the jackpot for ( int i = 0; i < results.Count; ++i ) { if ( winners.Contains( results[i].Player ) ) { if ( PokerDealer.JackpotWinners != null ) { if ( HandRanker.IsBetterThan( results[i], PokerDealer.JackpotWinners.Hand ) == RankResult.Better ) { PokerDealer.JackpotWinners = null; PokerDealer.JackpotWinners = new PokerDealer.JackpotInfo( winners, results[i], DateTime.Now ); break; } } else { PokerDealer.JackpotWinners = new PokerDealer.JackpotInfo( winners, results[i], DateTime.Now ); break; } } } results.Reverse(); foreach ( ResultEntry entry in results ) { //if ( !winners.Contains( entry.Player ) ) PokerMessage( entry.Player.Mobile, String.Format( "I have {0}.", HandRanker.RankString( entry ) ) ); /*else { if ( !HandRanker.UsesKicker( entry.Rank ) ) PokerMessage( entry.Player, String.Format( "I have {0}.", HandRanker.RankString( entry ) ) ); else //Hand rank uses a kicker { switch ( entry.Rank ) { } } }*/ } } return winners; }
public PokerPlayer AssignNextTurn() { PokerPlayer nextTurn = m_Players.Next(); if ( nextTurn == null ) return null; if ( nextTurn.RequestLeave ) { m_Players.Push( nextTurn ); nextTurn.BetStart = DateTime.Now; nextTurn.Action = PlayerAction.Fold; return nextTurn; } if ( nextTurn.IsAllIn ) { m_Players.Push( nextTurn ); nextTurn.BetStart = DateTime.Now; nextTurn.Action = PlayerAction.AllIn; return nextTurn; } if ( nextTurn.LonePlayer ) { m_Players.Push( nextTurn ); nextTurn.BetStart = DateTime.Now; nextTurn.Action = PlayerAction.Check; return nextTurn; } bool canCall = false; PokerPlayer currentTurn = m_Players.Peek(); if ( currentTurn != null && currentTurn.Action != PlayerAction.Check && currentTurn.Action != PlayerAction.Fold ) canCall = true; if ( currentTurn == null && m_State == PokerGameState.PreFlop ) canCall = true; m_Players.Push( nextTurn ); nextTurn.BetStart = DateTime.Now; ResultEntry entry = new ResultEntry( nextTurn ); List<Card> bestCards; entry.Rank = nextTurn.GetBestHand( m_CommunityCards, out bestCards ); entry.BestCards = bestCards; nextTurn.SendMessage( 0x22, String.Format( "You have {0}.", HandRanker.RankString( entry ) ) ); nextTurn.CloseGump( typeof( PokerBetGump ) ); nextTurn.SendGump( new PokerBetGump( this, nextTurn, canCall ) ); m_NeedsGumpUpdate = true; return nextTurn; }
public JackpotInfo(List <PokerPlayer> winners, ResultEntry hand, DateTime date) { m_Winners = winners; m_Hand = hand; m_Date = date; }
public JackpotInfo(List<PokerPlayer> winners, ResultEntry hand, DateTime date) { m_Winners = winners; m_Hand = hand; m_Date = date; }
public List <PokerPlayer> GetWinners(bool silent) { List <ResultEntry> results = new List <ResultEntry>(); for (int i = 0; i < m_Players.Round.Count; ++i) { ResultEntry entry = new ResultEntry(m_Players.Round[i]); List <Card> bestCards = new List <Card>(); entry.Rank = HandRanker.GetBestHand(entry.Player.GetAllCards(m_CommunityCards), out bestCards); entry.BestCards = bestCards; results.Add(entry); /*if ( !silent ) * { * //Check if kickers needed * PokerMessage( entry.Player.Mobile, string.Format( "I have {0}.", HandRanker.RankString( entry ) ) ); * }*/ } results.Sort(); if (results.Count < 1) { return(null); } List <PokerPlayer> winners = new List <PokerPlayer>(); for (int i = 0; i < results.Count; ++i) { if (HandRanker.IsBetterThan(results[i], results[0]) == RankResult.Same) { winners.Add(results[i].Player); } } //IF NOT SILENT if (!silent) { //Only hands that have made it past the showdown may be considered for the jackpot for (int i = 0; i < results.Count; ++i) { if (winners.Contains(results[i].Player)) { if (PokerDealer.JackpotWinners != null) { if (HandRanker.IsBetterThan(results[i], PokerDealer.JackpotWinners.Hand) == RankResult.Better) { PokerDealer.JackpotWinners = null; PokerDealer.JackpotWinners = new PokerDealer.JackpotInfo(winners, results[i], DateTime.Now); break; } } else { PokerDealer.JackpotWinners = new PokerDealer.JackpotInfo(winners, results[i], DateTime.Now); break; } } } results.Reverse(); foreach (ResultEntry entry in results) { //if ( !winners.Contains( entry.Player ) ) PokerMessage(entry.Player.Mobile, string.Format("I have {0}.", HandRanker.RankString(entry))); /*else * { * if ( !HandRanker.UsesKicker( entry.Rank ) ) * PokerMessage( entry.Player, string.Format( "I have {0}.", HandRanker.RankString( entry ) ) ); * else //Hand rank uses a kicker * { * switch ( entry.Rank ) * { * } * } * }*/ } } return(winners); }