Exemplo n.º 1
0
        /// <summary>
        /// <param name="hands">new[] { "N:T984.AK96.KQJ9.4 Q652.QJT53.T3.AT AKJ73.7.752.KJ62 .842.A864.Q98753" ,
        /// "N:KT98.AK96.J964.4 Q652.QJT53.T3.AT AJ743.7.752.KJ62 .842.AKQ8.Q98753"}</param>
        /// </summary>
        public static IEnumerable <int> SolveAllBoards(IEnumerable <string> hands)
        {
            var nrOfHands = hands.Count();
            var dealsPBN  = new DealPbn[BoardsPBN.MAXNOOFBOARDS];

            for (var i = 0; i < nrOfHands; i++)
            {
                dealsPBN[i] = CreateDeal(hands.ElementAt(i));
            }

            var boardsBPN = new BoardsPBN
            {
                noOfBoards = 2,
                dealsPBN   = dealsPBN,
                targets    = Enumerable.Repeat(-1, BoardsPBN.MAXNOOFBOARDS).ToArray(),
                solutions  = Enumerable.Repeat(1, BoardsPBN.MAXNOOFBOARDS).ToArray(),
                modes      = Enumerable.Repeat(0, BoardsPBN.MAXNOOFBOARDS).ToArray()
            };

            var solvedBoards = new SolvedBoards
            {
                noOfBoards = nrOfHands
            };

            var ddsResults = new FutureTricks[BoardsPBN.MAXNOOFBOARDS];

            solvedBoards.solvedBoards = ddsResults;

            //IntPtr boardsBPNPtr = Marshal.AllocHGlobal(Marshal.SizeOf(boardsBPN));
            //Marshal.StructureToPtr(boardsBPN, boardsBPNPtr, false);

            //int cb = Marshal.SizeOf(solvedBoards);
            //IntPtr solvedBoardsPtr = Marshal.AllocHGlobal(cb);

            var res = Pinvoke.SolveAllBoards(ref boardsBPN, out solvedBoards);

            //solvedBoards = Marshal.PtrToStructure<SolvedBoards>(solvedBoardsPtr);

            if (res != 1)
            {
                var line = new StringBuilder(80);
                Pinvoke.ErrorMessage(res, line);
                throw new Exception(line.ToString());
            }
            foreach (var solvedBoard in solvedBoards.solvedBoards)
            {
                yield return(solvedBoard.score[0]);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// <param name="hands">new[] { "N:T984.AK96.KQJ9.4 Q652.QJT53.T3.AT AKJ73.7.752.KJ62 .842.A864.Q98753" ,
        /// "N:KT98.AK96.J964.4 Q652.QJT53.T3.AT AJ743.7.752.KJ62 .842.AKQ8.Q98753"}</param>
        /// </summary>
        public static IEnumerable <int> SolveAllBoards(IEnumerable <string> hands, int trumpSuit, int first)
        {
            var nrOfHands = hands.Count();

            var dealsPBN = new DealPbn[BoardsPBN.MAXNOOFBOARDS];

            for (var i = 0; i < nrOfHands; i++)
            {
                dealsPBN[i] = CreateDeal(hands.ElementAt(i), trumpSuit, first);
            }

            var boardsBPN = new BoardsPBN
            {
                noOfBoards = nrOfHands,
                dealsPBN   = dealsPBN,
                targets    = Enumerable.Repeat(-1, BoardsPBN.MAXNOOFBOARDS).ToArray(),
                solutions  = Enumerable.Repeat(1, BoardsPBN.MAXNOOFBOARDS).ToArray(),
                modes      = Enumerable.Repeat(0, BoardsPBN.MAXNOOFBOARDS).ToArray()
            };

            IntPtr boardsBPNPtr = Marshal.AllocHGlobal(Marshal.SizeOf(boardsBPN));

            Marshal.StructureToPtr(boardsBPN, boardsBPNPtr, false);

            var res = Pinvoke.SolveAllBoards(boardsBPNPtr, out var solvedBoards);

            if (res != 1)
            {
                var line = new StringBuilder(80);
                Pinvoke.ErrorMessage(res, line);
                throw new Exception(line.ToString());
            }

            for (var i = 0; i < solvedBoards.noOfBoards; i++)
            {
                yield return(13 - solvedBoards.solvedBoards[i].score[0]);
            }
        }
Exemplo n.º 3
0
 public static extern int SolveAllBoards(ref BoardsPBN boardsPBN, out SolvedBoards solvedBoard);