Exemple #1
0
        public PlayerPosition PlayCard(Card card, PlayerPosition playerPosition)
        {
            _nextPlayer = BridgeHelper.GetNextPlayerPosition(playerPosition);

            if (_currentTrick.Deck.Count == 0)
            {
                _currentTrick             = new Trick();
                _currentTrick.TrickDealer = playerPosition;
            }


            if (_currentTrick.Deck.Count <= 4)
            {
                card.PlayerPosition = playerPosition;
                _currentTrick.Deck.Cards.Add(card);
            }

            if (_currentTrick.Deck.Count == 4)
            {
                Tricks.Add(_currentTrick);
                var winner = FindWinner(_currentTrick, Contract.Trump);
                _currentTrick.TrickWinner = winner;
                _nextPlayer   = winner;
                _currentTrick = new Trick()
                {
                    TrickDealer = winner
                };
            }

            GameState[playerPosition].RemoveCard(card);

            return(_nextPlayer);
        }
Exemple #2
0
        public PlayerPosition PlayCard(Card card, PlayerPosition playerPosition)
        {
            _nextPlayer = BridgeHelper.GetNextPlayerPosition(playerPosition);

            if (_currentTrick.Deck.Count == 0)
            {
                _currentTrick = new Trick();
                _currentTrick.TrickDealer = playerPosition;
            }


            if (_currentTrick.Deck.Count <= 4)
            {
                card.PlayerPosition = playerPosition;
                _currentTrick.Deck.Cards.Add(card);
            }

            if (_currentTrick.Deck.Count == 4)
            {
                Tricks.Add(_currentTrick);
                var winner = FindWinner(_currentTrick, Contract.Trump);
                _currentTrick.TrickWinner = winner;
                _nextPlayer = winner;
                _currentTrick = new Trick() { TrickDealer = winner };
            }

            GameState[playerPosition].RemoveCard(card);

            return _nextPlayer;
        }
Exemple #3
0
        private PlayerPosition FindWinner(Trick trick, Trump trump)
        {
            var highestTrump             = trick.Deck.Cards.Where(c => c.Suit.Order == trump.Order).OrderByDescending(c => c.Rank.Score);
            var highestInTrickDealerSuit = trick.Deck.Cards.Where(c => c.Suit.Order == trick.TrickDealerSuit.Order).OrderByDescending(c => c.Rank.Score);

            return(highestTrump.Any()
                       ? highestTrump.First().PlayerPosition
                       : highestInTrickDealerSuit.First().PlayerPosition);
        }
Exemple #4
0
 public BridgeGame(Dictionary<PlayerPosition, Deck> state, PlayerPosition declarer)
 {
     GameState = state;
     Tricks = new List<Trick>();
     Declarer = declarer;
     Dummy = BridgeHelper.GetNextPlayerPosition(BridgeHelper.GetNextPlayerPosition(declarer));
     Contract = new Contract();
     _currentTrick = new Trick() { TrickDealer = Declarer };
 }
Exemple #5
0
        public BridgeGame(Dictionary <PlayerPosition, Deck> state, PlayerPosition declarer, string contract)
        {
            GameState = state;
            Tricks    = new List <Trick>();
            Declarer  = declarer;
            Dummy     = BridgeHelper.GetNextPlayerPosition(BridgeHelper.GetNextPlayerPosition(declarer));
            Contract  = new Contract(contract, declarer);

            _currentTrick = new Trick()
            {
                TrickDealer = BridgeHelper.GetNextPlayerPosition(declarer)
            };
        }
Exemple #6
0
 private PlayerPosition FindWinner(Trick trick, Trump trump)
 {
     var highestTrump = trick.Deck.Cards.Where(c => c.Suit.Order == trump.Order).OrderByDescending(c => c.Rank.Score);
     var highestInTrickDealerSuit = trick.Deck.Cards.Where(c => c.Suit.Order == trick.TrickDealerSuit.Order).OrderByDescending(c => c.Rank.Score);
     return highestTrump.Any()
                ? highestTrump.First().PlayerPosition
                : highestInTrickDealerSuit.First().PlayerPosition;
 }