public GameRepresentation(CommandFactory commandFactory, PlayerGameInfo playerGameInfo)
        {
            CommandFactory = commandFactory;
            PlayerGameInfo = playerGameInfo;
            PlayActionList = PlayerGameInfo?.ValidActionIdList
                             ?.Select(id => CommandFactory.ConstructAction(id))
                             .Where(a => a.GetActionType() == ActionType.PlayAction)
                             .Select(a => (PlayAction)a)
                             .ToList();
            BetActionList = PlayerGameInfo?.ValidActionIdList
                            ?.Select(id => CommandFactory.ConstructAction(id))
                            .Where(a => a.GetActionType() == ActionType.BetAction)
                            .Select(a => (BetAction)a)
                            .ToList();
            CardCommandDictionary = PlayActionList
                                    ?.ToDictionary(a => a.Card, a => CommandFactory.ConstructCommand(a.GetActionId()) as ICommand);
            BetActionCommandDictionary = BetActionList
                                         ?.ToDictionary(a => a, a => CommandFactory.ConstructCommand(a.GetActionId()) as ICommand);
            HandRepresentation = PlayerGameInfo?.PlayerHand != null
                ? new HandRepresentation(PlayerGameInfo?.PlayerHand, CardCommandDictionary)
                : null;
            BetActionsRepresentation = BetActionList != null
                ? new BetActionsRepresentation(BetActionList, BetActionCommandDictionary)
                : null;
            BoardRepresentation = GameStageInfo != null
                ? new BoardRepresentation(PlayerGameInfo.GameInfo, PlayerGameInfo.PlayerInfo, GameStageInfo)
                : null;

            // Remark: Since we receive relative player information we could also directly determine the player positions.
            //         But this way the ViewModel would also work with "real" player informations.
            var topPlayer   = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetOppositePlayer(PlayerGameInfo.PlayerInfo.PlayerId);
            var rightPlayer = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetNextPlayer(PlayerGameInfo.PlayerInfo.PlayerId);
            var leftPlayer  = PlayerGameInfo.GameInfo.PlayerGroupInfo.GetPreviousPlayer(PlayerGameInfo.PlayerInfo.PlayerId);

            var previousBetActionList = PlayerGameInfo?.GameStageInfo?.ExpectedActionType == ActionType.BetAction
                ? PlayerGameInfo?.GameStageInfo?.CurrentBetActionList
                : null;
            var betActionKeyValuePairList = (previousBetActionList != null && previousBetActionList.Any())
                ? previousBetActionList
                                            ?.Select((a, i) => new KeyValuePair <int, BetAction>(i, a))
                                            ?.ToList()
                : null;
            var topBetActionDictionary = betActionKeyValuePairList
                                         ?.Where(p => p.Value.PlayerInfo.PlayerId == topPlayer.PlayerId)
                                         ?.ToDictionary(p => p.Key, p => p.Value);
            var rightBetActionDictionary = betActionKeyValuePairList
                                           ?.Where(p => p.Value.PlayerInfo.PlayerId == rightPlayer.PlayerId)
                                           ?.ToDictionary(p => p.Key, p => p.Value);
            var leftBetActionDictionary = betActionKeyValuePairList
                                          ?.Where(p => p.Value.PlayerInfo.PlayerId == leftPlayer.PlayerId)
                                          ?.ToDictionary(p => p.Key, p => p.Value);

            // TODO
            var currentPlayerId = GameStageInfo?.CurrentPlayer?.PlayerId;

            TopPlayerRepresentation   = new PlayerRepresentation(topPlayer, topBetActionDictionary, null, 0, currentPlayerId == topPlayer.PlayerId);
            LeftPlayerRepresentation  = new PlayerRepresentation(rightPlayer, leftBetActionDictionary, null, 0, currentPlayerId == leftPlayer.PlayerId);
            RightPlayerRepresentation = new PlayerRepresentation(leftPlayer, rightBetActionDictionary, null, 0, currentPlayerId == rightPlayer.PlayerId);
        }
Exemple #2
0
        private IList <BetAction> GetFollowedBetActions(BetAction betAction)
        {
            var betActionIndex  = BetActionList.IndexOf(betAction);
            var followUpCount   = BetActionList.Count - (betActionIndex + 1);
            var followedActions = followUpCount > 0
                ? BetActionList.ToList().GetRange(betActionIndex + 1, followUpCount)
                : new List <BetAction>();

            return(followedActions);
        }
Exemple #3
0
        public override string ToString()
        {
            var str = string.Join(Environment.NewLine, BetActionList.Select(a => $"BetAction: {a}"));

            if (BetResult != null)
            {
                str += Environment.NewLine;
                str += $"BetResult: {BetResult}" + Environment.NewLine;
            }
            return(str);
        }
Exemple #4
0
 public void ProcessBetAction(BetAction betAction)
 {
     if (BetResult != null)
     {
         var msg = "Inconsistency: Once the Bet phase is over no BetAction can be processed!";
         Log.Error(msg);
         throw new InvalidOperationException(msg);
     }
     BetActionList.Add(betAction);
     BetResult = GetBetResult();
     if (BetResult == null && betAction.PlayerInfo == CurrentPlayer)
     {
         CurrentPlayer = PlayerGroup.GetNextPlayer(CurrentPlayer.PlayerId);
     }
 }
Exemple #5
0
 private BetAction GetLastNonPassBetAction()
 {
     return(BetActionList.LastOrDefault(b => b.Type != BetActionType.Pass));
 }
Exemple #6
0
 private BetAction GetLastBetBetAction()
 {
     return(BetActionList.LastOrDefault(b => b.Type == BetActionType.Bet));
 }