Example #1
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);
            }
        }
Example #2
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);
                }
            }
        }
        internal static void Copy(ReplayerPlayerViewModel from, ReplayerPlayerViewModel to)
        {
            if (to == null || from == null)
            {
                return;
            }

            to.Reset(keepCards: true);

            to.ChipsContainer     = from.ChipsContainer;
            to.StatInfoCollection = from.StatInfoCollection;

            to.Name         = from.Name;
            to.IsActive     = from.IsActive;
            to.IsFinished   = from.IsFinished;
            to.IsDealer     = from.IsDealer;
            to.IsWin        = from.IsWin;
            to.EquityWin    = from.EquityWin;
            to.Bank         = from.Bank;
            to.OldBank      = from.OldBank;
            to.ActiveAmount = from.ActiveAmount;
            to.OldAmount    = from.OldAmount;

            to.ActionString = from.ActionString;

            to.CurrentStreet = from.CurrentStreet;
        }
Example #4
0
        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);
        }
Example #5
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;
        }
 internal static void CopyEquityWin(ReplayerPlayerViewModel from, ReplayerPlayerViewModel to)
 {
     to.EquityWin = from.EquityWin;
 }