示例#1
0
        public int generateMoveContext(MoveContext context, int minCount, List <MoveContext> list)
        {
            List <MoveContext> tmpList     = new List <MoveContext>();
            MoveContext        currContext = null;

            if (context.CurrDepth >= maxDepth || !context.BoardState.arePieces())
            {
                return(0);
            }

            bool isCapture = context.addChildBoardStates(moveFinder);

            int childsCount  = context.ChildsContext.Count;
            int addedContext = childsCount;

            if (childsCount == 0)
            {
                return(0);
            }

            while (context.ChildsContext.Count > 0)
            {
                list.Add(context.ChildsContext.Pop());
            }

            if (isCapture)
            {
                return(-childsCount);
            }

            if (childsCount >= minCount)
            {
                return(childsCount);
            }

            while (true)
            {
                for (int i = 0; i < addedContext; i++)
                {
                    currContext = list[list.Count - i - 1];
                    currContext.addChildBoardStates(moveFinder);
                    childsCount += currContext.ChildsContext.Count;

                    while (currContext.ChildsContext.Count > 0)
                    {
                        tmpList.Add(currContext.ChildsContext.Pop());
                    }
                }

                list.AddRange(tmpList);
                tmpList.Clear();

                if (childsCount == 0 || childsCount >= minCount || currContext.CurrDepth >= maxDepth)
                {
                    return(childsCount);
                }

                addedContext = childsCount;
                childsCount  = 0;
            }
        }