Example #1
0
        public static PlayState PlayState(IGame game, Guid requestingPlayerId)
        {
            var turnType      = game.TurnType;
            var currentDeck   = new GameStateDescriber(game).CurrentHand;
            var currentTrick  = currentDeck?.PickPhaseComplete == true ? new GameStateDescriber(game).CurrentTrick : null;
            var currentPlayer =
                turnType == TurnType.PlayTrick
                ? currentTrick?.PlayersWithoutTurn?.FirstOrDefault()
                : null;
            var tricks           = game.IHands.LastOrDefault(d => d.PickPhaseComplete)?.ITricks ?? new List <ITrick>();
            var humanPlayer      = currentPlayer as IHumanPlayer;
            var requestingPlayer = game.Players.OfType <IHumanPlayer>().SingleOrDefault(p => p.Id == requestingPlayerId);

            return(new PlayState
            {
                TurnType = turnType.ToString(),
                HumanTurn = humanPlayer != null,
                CurrentTurn = currentPlayer?.Name,
                RequestingPlayerTurn = humanPlayer?.Id == requestingPlayerId,
                CardsPlayed = tricks.Select(t => t.OrderedMoves
                                            .Select(om => new Tuple <string, CardSummary>(om.Key.Name, CardUtil.GetCardSummary(om.Value)))
                                            .ToList()
                                            )?.ToList(),
                PlayerCards = requestingPlayer?.Cards?.Select(c => CardUtil.GetCardSummary(c, currentTrick?.IsLegalAddition(c, requestingPlayer)))?.ToList()
            });
        }
Example #2
0
        public static BuryState BuryState(IGame game, Guid requestingPlayerId)
        {
            var turnType      = game.TurnType;
            var currentDeck   = new GameStateDescriber(game).CurrentHand;
            var currentPlayer =
                turnType == TurnType.Bury
                ? currentDeck?.Picker
                : null;
            var humanPlayer      = currentPlayer as IHumanPlayer;
            var requestingPlayer = game.Players.OfType <IHumanPlayer>().SingleOrDefault(p => p.Id == requestingPlayerId);

            return(new BuryState
            {
                TurnType = turnType.ToString(),
                RequestingPlayerTurn = humanPlayer?.Id == requestingPlayerId,
                Blinds = turnType == TurnType.Bury ? currentDeck?.Blinds?.Select(b => CardUtil.GetCardSummary(b))?.ToList() : null,
                PlayerCards = requestingPlayer?.Cards?.Select(c => CardUtil.GetCardSummary(c))?.ToList(),
                PartnerMethod = game.PartnerMethodEnum.ToString(),
                LegalCalledAces = humanPlayer?.LegalCalledAces(currentDeck).Select(c => CardUtil.GetCardSummary(c)).ToList()
            });
        }