public TwoPlayersTexasHoldemGame(IPlayer firstPlayer, IPlayer secondPlayer, int initialMoney = 1000) { if (firstPlayer == null) { throw new ArgumentNullException(nameof(firstPlayer)); } if (secondPlayer == null) { throw new ArgumentNullException(nameof(secondPlayer)); } if (initialMoney <= 0 || initialMoney > 200000) { throw new ArgumentOutOfRangeException(nameof(initialMoney), "Initial money should be greater than 0 and less than 200000"); } // Ensure the players have unique names if (firstPlayer.Name == secondPlayer.Name) { throw new ArgumentException($"Both players have the same name: \"{firstPlayer.Name}\""); } this.firstPlayer = new InternalPlayer(firstPlayer); this.secondPlayer = new InternalPlayer(secondPlayer); this.allPlayers = new List <InternalPlayer> { this.firstPlayer, this.secondPlayer }; this.initialMoney = initialMoney; this.HandsPlayed = 0; }
private ICollection <Opponent> CreateOpponents(InternalPlayer hero) { var shifted = this.allPlayers.ToList(); shifted.Add(shifted.First()); shifted.RemoveAt(0); int heroActionPriority = shifted.TakeWhile(p => p.Name != hero.Name).Count(); var opponentActionPriority = -heroActionPriority; var opponents = new List <Opponent>(); foreach (var item in shifted) { if (item.Name == hero.Name) { opponentActionPriority++; continue; } opponents.Add(new Opponent( item.Name, item.Cards, opponentActionPriority++, item.PlayerMoney.Money, item.PlayerMoney.CurrentRoundBet, item.PlayerMoney.InHand)); } return(opponents); }
private PlayerAction DoPlayerAction(InternalPlayer player, PlayerAction action, int maxMoneyPerPlayer) { if (action.Type == PlayerActionType.Raise) { player.Call(maxMoneyPerPlayer); if (player.Money <= 0) { return(PlayerAction.CheckOrCall()); } foreach (var playerToUpdate in this.allPlayers) { playerToUpdate.ShouldPlayInRound = true; } // TODO: Min raise? if (player.Money > action.Money) { player.PlaceMoney(action.Money); } else { // All-in action.Money = player.Money; player.PlaceMoney(action.Money); } } else if (action.Type == PlayerActionType.CheckCall) { player.Call(maxMoneyPerPlayer); } else //// PlayerActionType.Fold { player.InHand = false; } return(action); }
private void Bet(InternalPlayer player, int amount) { player.Bet(amount); this.Pot += amount; }