private void UpdatePlayersToState(ReplayerTableState state) { var prevStates = TableStateList.Take(TableStateList.IndexOf(state)); foreach (var player in PlayersCollection) { var playerAction = prevStates.LastOrDefault(x => x.ActivePlayer?.Name == player.Name); if (playerAction == null) { playerAction = TableStateList.FirstOrDefault(x => x.ActivePlayer.Name == player.Name); if (playerAction != null) { player.Bank = playerAction.ActivePlayer.OldBank; player.ActiveAmount = playerAction.ActivePlayer.OldAmount; player.IsActive = playerAction.ActivePlayer.IsActive; player.UpdateChips(); } continue; } ReplayerPlayerViewModel.Copy(playerAction.ActivePlayer, player); } }
private void ToEnd(object obj) { StopTimer(null); ResetPlayersPot(PlayersCollection); PlayersCollection.Where(x => !x.IsFinished && TableStateList.Any(t => t.ActivePlayer.Name == x.Name && t.ActivePlayer.IsFinished)).ForEach(x => x.IsFinished = true); StateIndex = TableStateList.Count - 1; ReplayerTableState replayerTableStateBeforeSummary = TableStateList.FirstOrDefault(x => x.CurrentStreet == Street.Summary); UpdatePlayersEquityWin(replayerTableStateBeforeSummary); //added in order to update equity state for winning actions when we go to the end of TableStateList }
private ReplayerPlayerViewModel GetActivePlayerForState(ReplayerTableState state) { if (state.ActivePlayer == null) { return(null); } var activePlayer = PlayersCollection.FirstOrDefault(x => x.Name == state.ActivePlayer.Name); if (activePlayer != null) { ReplayerPlayerViewModel.Copy(state.ActivePlayer, activePlayer); } return(activePlayer); }
private void LoadState(int stateIndex) { if (stateIndex < 0 || stateIndex >= TableStateList.Count) { return; } bool isBackward = stateIndex < StateIndex; bool isRefreshPlayersRequired = Math.Abs(stateIndex - StateIndex) > 1; ReplayerTableState state = TableStateList[stateIndex]; UpdatePlayersEquityWin(state); CurrentStreet = state.CurrentStreet; CurrentPotValue = state.CurrentPotValue; UpdateTotalPot(state.TotalPotValue); if (!IsShowHoleCards) { ProcessPlayersCards(); } ResetLastActivePlayer(isBackward); if (isRefreshPlayersRequired) { UpdatePlayersToState(state); } if (state.IsStreetChangedAction) { ResetPlayersPot(PlayersCollection); return; } var activePlayer = GetActivePlayerForState(state); if (activePlayer != null) { if (activePlayer.IsWin) { ResetPlayersPot(PlayersCollection.AsQueryable().Where(x => x != activePlayer)); } activePlayer.UpdateChips(); } }
private ReplayerPlayerViewModel GetActivePlayerLastState(HandAction action) { ReplayerPlayerViewModel activePlayer; string activePlayerName = action.PlayerName; ReplayerTableState activePlayerLastState = TableStateList.LastOrDefault(x => x.ActivePlayer != null && x.ActivePlayer.Name == activePlayerName); if (activePlayerLastState == null) { activePlayer = PlayersCollection.LastOrDefault(x => x.Name == activePlayerName); } else { activePlayer = activePlayerLastState.ActivePlayer; } if (activePlayer == null) { throw new ArgumentNullException(nameof(activePlayer), $"Cannot find player with name: {activePlayerName}"); } return(activePlayer); }
private void UpdatePlayersEquityWin(ReplayerTableState state) { if (state == null) { return; } //preparing for formula Card on the Board in dependence of street in current state switch (state.CurrentAction.Street) { case Street.Preflop: CurrentBoard = new Card[] { }; CurrentBoardCards = string.Empty; break; case Street.Flop: CurrentBoard = CurrentGame.CommunityCards.Take(3).ToArray(); CurrentBoardCards = new string(CurrentGame.CommunityCardsString.Take(6).ToArray()); break; case Street.Turn: CurrentBoard = CurrentGame.CommunityCards.Take(4).ToArray(); CurrentBoardCards = new string(CurrentGame.CommunityCardsString.Take(8).ToArray()); break; case Street.River: CurrentBoard = CurrentGame.CommunityCards.ToArray(); CurrentBoardCards = CurrentGame.CommunityCardsString; break; case Street.Showdown: CurrentBoard = CurrentGame.CommunityCards.ToArray(); CurrentBoardCards = CurrentGame.CommunityCardsString; break; case Street.Summary: CurrentBoard = CurrentGame.CommunityCards.ToArray(); CurrentBoardCards = CurrentGame.CommunityCardsString; break; } // finding all players having hole cards ActivePlayerHasHoleCard = CurrentGame.Players.Where(pl => pl.hasHoleCards).ToList(); // searching for dead cards and removing this player from list of ActivePlayerHasHoleCard ActivePlayerHasHoleCardFolded = new List <Player>(); AllDeadCards.Clear(); foreach (ReplayerTableState replayerTableState in TableStateList) { Player playerInTableState = CurrentGame.Players.FirstOrDefault(x => x.PlayerName == replayerTableState.CurrentAction.PlayerName); if (playerInTableState != null && TableStateList.IndexOf(replayerTableState) <= TableStateList.IndexOf(state) && replayerTableState.CurrentAction.IsFold && playerInTableState.hasHoleCards) { ActivePlayerHasHoleCardFolded.Add(playerInTableState); ActivePlayerHasHoleCard.Remove(playerInTableState); AllDeadCards.Add(playerInTableState.HoleCards); AllDeadCardsString += playerInTableState.Cards; } } var equitySolver = ServiceLocator.Current.GetInstance <IEquitySolver>(); var gameType = new GeneralGameTypeEnum().ParseGameType(CurrentGame.GameDescription.GameType); var isShortDeck = CurrentGame.GameDescription.TableTypeDescriptors.Contains(HandHistories.Objects.GameDescription.TableTypeDescription.ShortDeck); var equitySolverParams = new EquitySolverParams { PlayersCards = ActivePlayerHasHoleCard.Select(x => x.HoleCards).ToArray(), BoardCards = CurrentBoard, Dead = isShortDeck ? AllDeadCards .Distinct(new LambdaComparer <HoleCards>((x, y) => x.ToString().Equals(y.ToString()))) .SelectMany(x => x) .Concat(CardGroup.GetDeadCardsForHoldem6Plus()) .ToArray() : AllDeadCards .Distinct(new LambdaComparer <HoleCards>((x, y) => x.ToString().Equals(y.ToString()))) .SelectMany(x => x) .ToArray(), GameType = gameType }; var equities = equitySolver.CalculateEquity(equitySolverParams) .Select(x => Math.Round((decimal)x.Equity * 100, 2)) .ToArray(); // updating states in replayer view if (equities != null) { RefreshBoard(equities, state.CurrentStreet); } //case of last state. Needed for All-in before River for some cases if (TableStateList.IndexOf(state) + 1 == TableStateList.Count && equities != null) { // updating states in replayer view RefreshBoard(equities, Street.Preflop); } }
private void Update() { TableStateList.Clear(); SetPlayersDefaults(); TotalPotChipsContainer = new ReplayerChipsContainer(); CommunityCards = new List <ReplayerCardViewModel>(); if (CurrentGame == null) { return; } SetCommunityCards(CurrentGame.CommunityCards); decimal anteAmount = Math.Abs(CurrentGame.HandActions.Where(x => x.HandActionType == HandActionType.ANTE).Sum(x => x.Amount)); decimal currentPotValue = anteAmount; decimal totalPotValue = anteAmount; foreach (var action in CurrentGame.HandActions.Where(x => x.HandActionType != HandActionType.ANTE)) { if (IsSkipAction(action)) { continue; } ReplayerTableState state = new ReplayerTableState(); ReplayerTableState lastAction = TableStateList.LastOrDefault(); if (lastAction != null && lastAction.CurrentStreet != action.Street && action.Street >= Street.Flop && action.Street <= Street.River) { // if we are inside this "if" we create an extra state between two actions totalPotValue = currentPotValue; state.TotalPotValue = totalPotValue; state.CurrentPotValue = currentPotValue; state.IsStreetChangedAction = true; state.ActivePlayer = new ReplayerPlayerViewModel(); state.CurrentStreet = action.Street; TableStateList.Add(state); // added new state between actions like flop/river state.CurrentAction = action; state = new ReplayerTableState(); } state.CurrentAction = action; state.ActionAmount = action.Amount; state.CurrentStreet = action.Street; ReplayerPlayerViewModel activePlayer = GetActivePlayerLastState(action); state.ActivePlayer = new ReplayerPlayerViewModel(); ReplayerPlayerViewModel.Copy(activePlayer, state.ActivePlayer); state.UpdatePlayerState(action); if (state.ActivePlayer.IsWin) { if (!TableStateList.Any(x => x.ActivePlayer != null && x.ActivePlayer.IsWin)) { totalPotValue = currentPotValue; } totalPotValue -= state.ActionAmount; } else { currentPotValue = currentPotValue - state.ActionAmount; } state.TotalPotValue = totalPotValue; state.CurrentPotValue = currentPotValue; TableStateList.Add(state); } StateIndex = 0; SliderMax = TableStateList.Count - 1; }