Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
        }