示例#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]);
            }
        }
示例#2
0
文件: Pinvoke.cs 项目: YkeSmit1/TOSR
 public static extern int SolveAllBoards(IntPtr boardsPBN, out SolvedBoards solvedBoard);
示例#3
0
 public static extern int SolveAllBoards(ref BoardsPBN boardsPBN, out SolvedBoards solvedBoard);