コード例 #1
0
ファイル: GameState.cs プロジェクト: rsyNinja/Sheepshead
        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()
            });
        }
コード例 #2
0
 /// <summary>
 /// Use this method to bury cards in a Called-Ace game.
 /// </summary>
 public void BuryCards(IHand hand, IHumanPlayer picker, List <SheepCard> cardsToBury, bool goItAlone, SheepCard partnerCard)
 {
     if (picker.Cards.Contains(partnerCard))
     {
         throw new ArgumentException("Picker has the parner card");
     }
     if (!picker.Cards.Any(c => CardUtil.GetSuit(c) == CardUtil.GetSuit(partnerCard)))
     {
         throw new ArgumentException($"Picker does not have a card in the {CardUtil.GetSuit(partnerCard).ToString()} suit");
     }
     if (!_validCalledAceCards.Contains(partnerCard))
     {
         throw new ArgumentException($"{CardUtil.GetAbbreviation(partnerCard)} is not a valid partner card.");
     }
     hand.SetPartnerCard(partnerCard);
     BuryCards(hand, picker, cardsToBury, goItAlone);
 }
コード例 #3
0
ファイル: GameState.cs プロジェクト: rsyNinja/Sheepshead
        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()
            });
        }
コード例 #4
0
ファイル: GameState.cs プロジェクト: rsyNinja/Sheepshead
        public static TrickResults GetTrickWinners(IHand hand)
        {
            var tricks  = hand.ITricks ?? new List <ITrick>();
            var winners = tricks.Where(t => t.PlayersWithoutTurn.Count == 0).Select(t => t?.Winner()?.Player?.Name).ToList();

            return(new TrickResults()
            {
                Picker = hand.Picker?.Name,
                Partner = hand.Partner?.Name,
                PartnerCard = hand.PartnerCardEnum == null ? null : CardUtil.GetAbbreviation(hand.PartnerCardEnum.Value),
                TrickWinners = winners,
                LeastersHand = hand?.Leasters ?? false,
                Tricks = hand
                         ?.ITricks
                         ?.Where(t => t.IsComplete())
                         ?.Select(trick =>
                                  trick.OrderedMoves
                                  .Select(move => new KeyValuePair <string, CardSummary>(move.Key.Name, CardUtil.GetCardSummary(move.Value)))
                                  .ToList()
                                  )
                         ?.ToList()
            });
        }
コード例 #5
0
        private static Dictionary <IPlayer, int> AssignNonLeasterPoints(IHand hand, out int defensePoints, out bool challengersWonOneTrick, out bool defenseWonOneTrick)
        {
            var handPoints = new Dictionary <IPlayer, int>
            {
                { hand.Picker, hand.Buried.Sum(c => CardUtil.GetPoints(c)) }
            };

            defensePoints          = 0;
            challengersWonOneTrick = false;
            defenseWonOneTrick     = false;
            foreach (var trick in hand.ITricks)
            {
                var winnerData = trick.Winner();
                if (winnerData?.Player == hand.Picker || winnerData?.Player == hand.Partner)
                {
                    challengersWonOneTrick = true;
                }
                else
                {
                    defensePoints     += winnerData.Points;
                    defenseWonOneTrick = true;
                }
                if (winnerData?.Player != null)
                {
                    if (handPoints.ContainsKey(winnerData.Player))
                    {
                        handPoints[winnerData.Player] += winnerData.Points;
                    }
                    else
                    {
                        handPoints.Add(winnerData.Player, winnerData.Points);
                    }
                }
            }
            return(handPoints);
        }
コード例 #6
0
ファイル: GameState.cs プロジェクト: rsyNinja/Sheepshead
        public static PickState PickState(IGame game, Guid requestingPlayerId)
        {
            var turnType      = game.TurnType;
            var currentHand   = game.IHands.LastOrDefault();
            var currentPlayer =
                turnType == TurnType.Pick
                ? currentHand?.PlayersWithoutPickTurn?.FirstOrDefault()
                : null;
            var humanPlayer      = currentPlayer as IHumanPlayer;
            var requestingPlayer = game.Players.OfType <IHumanPlayer>().SingleOrDefault(p => p.Id == requestingPlayerId);
            var pickChoices      =
                currentHand?.PlayersRefusingPick.Select(p => new Tuple <string, bool>(p.Name, false))
                .Union(new List <Tuple <string, bool> > {
                new Tuple <string, bool>(currentHand?.Picker?.Name, true)
            })
                .Where(p => p.Item1 != null)
                .ToList()
                ?? new List <Tuple <string, bool> >();

            if (currentHand == null)
            {
                return new PickState
                       {
                           TurnType             = turnType.ToString(),
                           RequestingPlayerTurn = false,
                           PickChoices          = new List <Tuple <string, bool> >(),
                           PlayerCards          = new List <CardSummary>(),
                           HumanTurn            = false,
                           CurrentTurn          = string.Empty,
                           MustRedeal           = false
                       }
            }
            ;
            else
            {
                return new PickState
                       {
                           TurnType             = turnType.ToString(),
                           RequestingPlayerTurn = humanPlayer?.Id == requestingPlayerId,
                           PickChoices          = pickChoices,
                           PlayerCards          = requestingPlayer?.Cards?.Select(c => CardUtil.GetCardSummary(c))?.ToList(),
                           HumanTurn            = humanPlayer != null,
                           CurrentTurn          = currentPlayer?.Name,
                           MustRedeal           = currentHand.MustRedeal
                       }
            };
        }