示例#1
0
        private void ToStreet(object obj)
        {
            if (obj == null)
            {
                return;
            }

            StopTimer(null);

            if (Enum.TryParse(obj.ToString(), out Street outStreet))
            {
                var streetState = TableStateList.FirstOrDefault(x => x.CurrentStreet == outStreet);

                if (streetState != null)
                {
                    if (outStreet <= Street.Preflop)
                    {
                        PlayersCollection.Where(x => x.IsFinished && TableStateList.Any(t => t.ActivePlayer.Name == x.Name)).ForEach(x => x.IsFinished = false);
                    }

                    StateIndex = TableStateList.IndexOf(streetState);

                    UpdatePlayersEquityWin(TableStateList.FirstOrDefault(x => x.CurrentStreet == outStreet)); //update equity win property of all players
                }
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        private void ToStart(object obj)
        {
            StopTimer(null);

            PlayersCollection.Where(x => x.IsFinished && TableStateList.Any(t => t.ActivePlayer.Name == x.Name)).ForEach(x => x.IsFinished = false);
            StateIndex = 0;
        }
示例#4
0
        private void RefreshBoard(decimal[] equities, Street street)
        {
            foreach (ReplayerTableState replayerTableState in TableStateList.Where(st => st.CurrentStreet == street))
            {
                try
                {
                    _playerInState = PlayersCollection.FirstOrDefault(u => u.Name == replayerTableState.CurrentAction.PlayerName);
                    if (_playerInState != null &&
                        ActivePlayerHasHoleCard.FirstOrDefault(x => x.PlayerName == replayerTableState.CurrentAction.PlayerName) != null &&
                        replayerTableState.CurrentAction != null &&
                        ActivePlayerHasHoleCard.Count > 1)
                    {
                        replayerTableState.ActivePlayer.EquityWin = equities[ActivePlayerHasHoleCard.IndexOf(ActivePlayerHasHoleCard.FirstOrDefault(x => x.PlayerName == replayerTableState.CurrentAction.PlayerName))];
                    }
                    else
                    {
                        replayerTableState.ActivePlayer.EquityWin = -1;
                    }


                    ReplayerPlayerViewModel.CopyEquityWin(replayerTableState.ActivePlayer, _playerInState);
                }
                catch (Exception ex)
                {
                    LogProvider.Log.Error(typeof(Converter), $"Player with name '{replayerTableState.CurrentAction.PlayerName}' has not been found in PlayerCollection in method RefreshBoard in ReplayerViewModel class", ex);
                }
            }
        }
示例#5
0
        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
        }
示例#6
0
        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);
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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;
        }