当前位置: 首页>>代码示例>>C#>>正文


C# Dir.Clone方法代码示例

本文整理汇总了C#中Dir.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Dir.Clone方法的具体用法?C# Dir.Clone怎么用?C# Dir.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dir的用法示例。


在下文中一共展示了Dir.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Expand

        private void Expand(Dir[,] choice, int r, int c, int from, int to, int totalScore, int stage, int mask)
        {
            if (r == n_)
            {
                from *= 3;
                to *= 3;
                int fromStart = 0, fromEnd = 2;
                if ((stage & 0x1) > 0)
                {
                    // can only accept states with no start or end
                    fromEnd = 0;
                }
                else if (stage == 0x2)
                {
                    // has end in the column but no start, can only accept states with start (only)
                    fromStart = 1;
                    fromEnd = 1;
                }

                int toAdd = 0;
                if ((stage & 0x2) > 0) toAdd = 2;
                else if (stage == 0x1) toAdd = 1;

                for (int fromAdd = fromStart; fromAdd <= fromEnd; fromAdd++)
                {
                    List<Entry> parents = prev_[from + fromAdd];

                    for (int i = 0; i < parents.Count; i++)
                    {
                        int currentScore = parents[i].score + totalScore;

                        DisjointSet groups = new DisjointSet(n_);
                        bool invalid = false;
                        for (int j = 0; j < n_; j++)
                        {
                            if (choice[j, 0] == Dir.Down || choice[j, 1] == Dir.Up)
                            {
                                groups.Union(j, j - 1);
                            }
                            if (choice[j, 0] == Dir.Left || choice[j, 1] == Dir.Right)
                            {
                                // find out whether the rhs has connected to anything above it
                                int rhs = (parents[i].groups >> j * 2) & 0x3;
                                int connected = -1;
                                for (int k = j - 1; k >= 0; k--)
                                {
                                    if (choice[k, 0] == Dir.Left || choice[k, 1] == Dir.Right)
                                    {
                                        if (((parents[i].groups >> k * 2) & 0x3) == rhs)
                                        {
                                            connected = k;
                                            break;
                                        }
                                    }
                                }
                                if (connected != -1)
                                {
                                    invalid |= !groups.Union(connected, j);
                                    // this forms a closed loop, which is an invalid formation
                                    if (invalid) break;
                                }
                                // else rhs does not connect to anything above it
                            }
                        }

                        if (invalid) continue;

                        toAdd = Math.Max(toAdd, fromAdd);
                        List<Entry> current = next_[to + toAdd];
                        int toGroups = groups.Normalize(mask);
                        bool fnd = false;
                        var currentSolution = parents[i].solution.Select(s => s).ToList();
                        currentSolution.Add((Dir[,])choice.Clone());
                        for (int j = 0; j < current.Count; j++)
                        {
                            if (current[j].groups == toGroups)
                            {
                                if (currentScore > current[j].score)
                                {
                                    current[j].score = currentScore;
                                    current[j].solution = currentSolution;
                                }
                                fnd = true;
                                break;
                            }
                        }
                        if (!fnd)
                        {
                            current.Add(new Entry(toGroups, currentScore, currentSolution));
                        }
                    }
                }

                return;
            }

            for (int k = 0; k < Dirs.Values.GetLength(0); k++)
            {
                if (grid_[r, c] == 0 && k > 0) break;
                if (stage == 1 && Dirs.Values[k, 0] == Dir.None && k > 0) break;
//.........这里部分代码省略.........
开发者ID:liux0229,项目名称:scratch,代码行数:101,代码来源:OnePersonGameSolver.cs


注:本文中的Dir.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。