Пример #1
0
        public FutureTricks SolveBoardPbn(BridgeGame game, int target, int solutions, int mode)
        {
            if (game.CurrentTrick.Deck.Count > 3)
            {
                throw new ArgumentException("Invalid current trick cards count", "CurrentTrick.Deck.Count");
            }

            var deal = new DealPbn();

            deal.trump = game.Contract.Trump.Order;
            deal.first = game.CurrentTrick.TrickDealer.Order;

            deal.currentTrickRank = new int[3];
            deal.currentTrickSuit = new int[3];
            for (int i = 0; i < game.CurrentTrick.Deck.Count; i++)
            {
                var card = game.CurrentTrick.Deck.Cards[i];
                deal.currentTrickRank[i] = card.Rank.Score;
                deal.currentTrickSuit[i] = card.Suit.Order;
            }
            deal.remainCards = DdsHelper.PbnStringToChars(BridgeHelper.ToPbn(game));

            var ddsResult = new Integration.FutureTricks();

            //TODO: Support mutiple threads.
            var res = DdsImport.SolveBoardPBN(deal, target, solutions, mode, ref ddsResult, 0);

            if (res != 1)
            {
                throw new DdsSolveBoardException(res);
            }

            var result = new FutureTricks();

            result.Cards  = ddsResult.cards;
            result.Nodes  = ddsResult.nodes;
            result.Scores = ddsResult.score.ToList();
            for (int i = 0; i < 13; i++)
            {
                if (ddsResult.rank[i] != 0)
                {
                    var rank = new Rank(ddsResult.rank[i]);
                    var suit = new Suit(ddsResult.suit[i]);

                    result.FutureCards.Cards.Add(new Card(rank, suit));
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
Пример #2
0
        public static List <Contract> CalculateMakeableContracts(string pbn)
        {
            var ret     = new List <Contract>();
            var results = new DdTableResults();
            var dto     = new DdTableDealPbn(DdsHelper.PbnStringToChars(pbn));

            var res = DdsImport.CalcDDtablePBN(dto, ref results);

            if (res != 1)
            {
                throw new DdsCalcDDtableException(res);
            }

            /*
             *      S   H   D   C   NT
             *  N   0   4   8   12  16
             *  E   1   5   9   13  17
             *  S   2   6   10  14  18
             *  W   3   7   11  15  19
             */

            var index = 0;

            foreach (Trump trump in Trump.Trumps)
            {
                foreach (PlayerPosition player in PlayerPosition.Players)
                {
                    ret.Add(new Contract()
                    {
                        Trump          = trump,
                        PlayerPosition = player,
                        Level          = results.resTable[index] - 6
                    });
                    index++;
                }
            }

            return(ret);
        }