public static PlayerDecisionResponse GetDefaultDecision(string playerName) { PlayerDecisionResponse pd = new PlayerDecisionResponse(); pd.PlayerName = playerName; pd.RaiseAmount = 0; pd.Type = DecisionType.Fold; return pd; }
public PlayerDecisionResponse GetPlayerDecision(Player player, double minimumBet, DecisionType[] availableOptions) { PlayerDecisionResponse pd = new PlayerDecisionResponse(); pd.Type = DecisionType.TimeOutAndFold; PlayerDecisionRequest pdr = new PlayerDecisionRequest(); pdr.RequestId = Guid.NewGuid().ToString(); pdr.MinimumBet = minimumBet; pdr.AvailableOptions = availableOptions; AddToOutgoingMessageQueue(GameMessageType.Client_ReceivePlayerDecisionRequest, pdr, player.ToList()); int waitingFor = 0; while (waitingFor < Table.MAX_DECISION_TIME) { if (m_dicStorage.ContainsKey(pdr.RequestId)) { pd = (PlayerDecisionResponse)m_dicStorage[pdr.RequestId]; break; } //-- Perhaps the player has disconnected from the table if (Table.IsPlayerSittingAtTable(player.Name) == false) { pd.Type = DecisionType.DisconnectAndFold; break; } m_tcGameFlow.WaitHereFor(100); waitingFor += 100; } return pd; }
private bool IsValidDecision(Player player, PlayerDecisionResponse decision, double callAmount) { //-- This method could probably use some simplification etc.. See the GetValidOptions() method. if (decision == null) throw new NullReferenceException("The decision argument cannot be null."); if (callAmount > 0) { switch (decision.Type) { case DecisionType.DisconnectAndFold: case DecisionType.TimeOutAndFold: case DecisionType.InvalidAndFold: case DecisionType.Fold: { return true; } case DecisionType.Call: { if (callAmount >= player.Chips) return false; else return true; } case DecisionType.AllIn: return true; case DecisionType.Raise: { if (TurnCounter[player.Name] == 0) { if (decision.RaiseAmount <= callAmount) return false; else if (decision.RaiseAmount >= player.Chips) return false; else return true; } else { //-- You cannot raise when its you second turn in the round return false; } } case DecisionType.Check: return false; default: throw new InvalidOperationException("An unknown DecisionType was encountered."); } } else { switch (decision.Type) { case DecisionType.DisconnectAndFold: case DecisionType.TimeOutAndFold: case DecisionType.InvalidAndFold: case DecisionType.Fold: case DecisionType.Check: case DecisionType.AllIn: return true; case DecisionType.Raise: { if (TurnCounter[player.Name] == 0) { if (decision.RaiseAmount <= callAmount) return false; else if (decision.RaiseAmount >= player.Chips) return false; else return true; } else { //-- You cannot raise when its you second turn in the round return false; } } case DecisionType.Call: return false; default: throw new InvalidOperationException("An unknown DecisionType was encountered."); } } }
protected PlayerDecisionNotification GetPlayerDecisionNotification(PlayerDecisionResponse decision) { return new PlayerDecisionNotification() { PlayerName = decision.PlayerName, RaiseAmount = decision.RaiseAmount, Type = decision.Type, LatestPotValue = Table.PotManager.GetTotal() }; }
private void HandlePlayerDecision(Player player, PlayerDecisionResponse decision) { switch (decision.Type) { case DecisionType.DisconnectAndFold: case DecisionType.TimeOutAndFold: case DecisionType.InvalidAndFold: case DecisionType.Fold: player.State = PlayerState.Folded; break; case DecisionType.Check: player.State = PlayerState.Playing; break; case DecisionType.Call: { double callAmount = GetAmountPlayerRequiresToCall(player); Table.PotManager.AddToPot(player, player.HandOverChips(callAmount)); player.State = PlayerState.Playing; break; } case DecisionType.Raise: { Table.PotManager.AddToPot(player, player.HandOverChips(decision.RaiseAmount)); player.State = PlayerState.Playing; break; } case DecisionType.AllIn: { Table.PotManager.AddToPot(player, player.AllIn()); player.State = PlayerState.AllIn; break; } default: throw new InvalidOperationException("An unknown DecisionType was encountered."); } }