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


C# Mesh.TrySolve方法代码示例

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


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

示例1: PerformAction

 private void PerformAction(bool? right, int closestEdge, int closestCell)
 {
     if (closestEdge != -1)
     {
         if (markedEdges.Contains(closestEdge))
             return;
         if (noToggle && Mesh.Edges[closestEdge].State != EdgeState.Empty)
             return;
         /*if (shiftPressed || controlPressed)
         {
             if (shiftPressed)
             {
                 if (lastShift == -1)
                     lastShift = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastShift, closestEdge, true);
                     if (lastShift != closestEdge)
                         undoTree.Do(colorAction);
                     lastShift = -1;
                 }
             }
             else if (controlPressed)
             {
                 if (lastControl == -1)
                     lastControl = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastControl, closestEdge, false);
                     if (lastControl != closestEdge)
                         undoTree.Do(colorAction);
                     lastControl = -1;
                 }
             }
             UpdateChildControls();
             return;
         }*/
         LoopClickAction action;
         if (right.HasValue)
         {
             action = new LoopClickAction(Mesh, closestEdge, right.Value, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
         }
         else
         {
             if (Mesh.Edges[closestEdge].State == lastState)
                 return;
             bool pretendRight = false;
             switch (lastState)
             {
                 case EdgeState.Filled:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Excluded)
                         pretendRight = true;
                     break;
                 case EdgeState.Excluded:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Empty)
                         pretendRight = true;
                     break;
                 case EdgeState.Empty:
                     if (Mesh.Edges[closestEdge].State == EdgeState.Filled)
                         pretendRight = true;
                     break;
             }
             action = new LoopClickAction(Mesh, closestEdge, pretendRight, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
         }
         if (!undoTree.Do(action))
         {
             /*
             redEdge = closestEdge;
             Thread thread = new Thread(new ThreadStart(ClearRed));
             thread.IsBackground = true;
             thread.Start();
              */
         }
         else if (noToggle)
         {
             /*
             if (MovePerformed != null)
                 MovePerformed(this, new MoveEventArgs(closestEdge, e.Button == MouseButtons.Left));
              * */
         }
         else
         {
             if (right.HasValue)
             {
                 lastState = Mesh.Edges[closestEdge].State;
             }
             bool satisified = true;
             for (int i = 0; i < Mesh.Cells.Count; i++)
             {
                 if (Mesh.Cells[i].TargetCount >= 0 && Mesh.Cells[i].FilledCount != Mesh.Cells[i].TargetCount)
                     satisified = false;
             }
             if (satisified)
             {
                 Mesh copy = new Mesh(Mesh);
                 try
                 {
                     copy.Clear();
                     bool failed = false;
                     if (copy.TrySolve() != SolveState.Solved)
//.........这里部分代码省略.........
开发者ID:Tilps,项目名称:LoopDeLoop,代码行数:101,代码来源:LoopDisplaySilverlight.cs

示例2: OnMouseUp


//.........这里部分代码省略.........
             return;
         if (shiftPressed || controlPressed)
         {
             if (shiftPressed)
             {
                 if (lastShift == -1)
                     lastShift = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(mesh, lastShift, closestEdge, true);
                     if (lastShift != closestEdge)
                         undoTree.Do(colorAction);
                     lastShift = -1;
                 }
             }
             else if (controlPressed)
             {
                 if (lastControl == -1)
                     lastControl = closestEdge;
                 else
                 {
                     ColorJoinAction colorAction = new ColorJoinAction(mesh, lastControl, closestEdge, false);
                     if (lastControl != closestEdge)
                         undoTree.Do(colorAction);
                     lastControl = -1;
                 }
             }
             this.Refresh();
             return;
         }
         LoopClickAction action = new LoopClickAction(mesh, closestEdge, e.Button, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto, useEdgeRestrictsInAuto, useCellPairsInAuto);
         if (!undoTree.Do(action))
         {
             redEdge = closestEdge;
             Thread thread = new Thread(new ThreadStart(ClearRed));
             thread.IsBackground = true;
             thread.Start();
         }
         else if (noToggle)
         {
             if (MovePerformed != null)
                 MovePerformed(this, new MoveEventArgs(closestEdge, e.Button == MouseButtons.Left));
         }
         else
         {
             bool satisified = true;
             for (int i = 0; i < mesh.Cells.Count; i++)
             {
                 if (mesh.Cells[i].TargetCount >= 0 && mesh.Cells[i].FilledCount != mesh.Cells[i].TargetCount)
                     satisified = false;
             }
             if (satisified)
             {
                 Mesh copy = new Mesh(mesh);
                 try
                 {
                     copy.SolverMethod = SolverMethod.Recursive;
                     copy.UseIntersectCellInteractsInSolver = false;
                     copy.Clear();
                     if (copy.TrySolve() == SolveState.Solved)
                     {
                         bool done = true;
                         for (int i = 0; i < mesh.Edges.Count; i++)
                         {
                             if (copy.SolutionFound.Edges[i].State == EdgeState.Filled)
                             {
                                 if (mesh.Edges[i].State != EdgeState.Filled)
                                     done = false;
                             }
                             else if (mesh.Edges[i].State == EdgeState.Filled)
                                 done = false;
                         }
                         if (done)
                         {
                             allDone = true;
                             if (Solved != null)
                                 Solved(this, EventArgs.Empty);
                             Thread thread = new Thread(new ThreadStart(Done));
                             thread.IsBackground = true;
                             thread.Start();
                         }
                     }
                 }
                 catch
                 {
                 }
             }
         }
         this.Refresh();
     }
     else if (closestCell != -1)
     {
         if (noToggle && mesh.Cells[closestCell].Color != 0)
             return;
         CellClickAction action = new CellClickAction(mesh, closestCell, e.Button);
         undoTree.Do(action);
         this.Refresh();
     }
     base.OnMouseUp(e);
 }
开发者ID:Tilps,项目名称:LoopDeLoop,代码行数:101,代码来源:LoopDisplay.cs

示例3: SelfTest

        private void SelfTest(int height, int width, MeshType meshType, bool extensive)
        {
            Output(string.Format("SelfTesting {0}, {1}, {2}, {3}", height, width, meshType, extensive));
            List<string> codes = new List<string>{"S", "SC", "SCO", "SCOM", "SC+OM", "SC+EOM", "SC+EOMP", "SC+EOMP+", "FC+EOMP+"};
            List<string> extraCodes = new List<string>{"SI", "SIC", "SIO", "SM", "SIM", "SOM", "SP", "SP+", "SC+EP", "SE", "SEP", "SC+E", "SCE", "SCP"};
            try
            {
                int solvedCount=0;
                for (int i = 0; i < (extensive ? 100 : 5); i++)
                {
                    Mesh m = new Mesh(width, height, meshType);
                    m.SetRatingCodeOptions("F");
                    m.GenerateBoringFraction = 0.5/height;
                    m.GenerateLengthFraction = 0.7;
                    m.Generate();
                    bool solved = false;
                    int lastDepth = int.MaxValue;
                    foreach (string code_in in codes)
                    {
                        bool solvedByCode = false;
                        for (int j = 0; j < (extensive ? height * height : 1); j++ )
                        {
                            string code = code_in;
                            if (extensive)
                                code += (j-1).ToString();
                            m.Clear();
                            m.SetRatingCodeOptions(code);
                            SolveState result = m.TrySolve();
                            if (result == SolveState.Solved)
                            {
                                solvedByCode = true;
                                if (!solved)
                                    solved = true;
                                if (extensive)
                                {
                                    if (j < lastDepth)
                                        lastDepth = j;
                                }
                            }
                            else
                            {
                                if (solved)
                                {
                                    if (!extensive || j > lastDepth || j == height*height-1)
                                    {
                                        Output(string.Format("Code {0} failed to solve puzzle solved with less powerful solvers.", code));
                                        using (TextWriter writer = File.CreateText("SelfTestOuput" + failCount + "-" + code + ".loop"))
                                        {
                                            m.Save(writer);
                                        }
                                    }
                                    failCount++;
                                }
                            }
                        }
                        if (solvedByCode)
                            solvedCount++;
                    }

                    m.FullClear();
                    m.SetRatingCodeOptions("S");
                    m.Generate();
                    foreach (string code in codes.Concat(extraCodes))
                    {
                        m.Clear();
                        m.SetRatingCodeOptions(code);
                        SolveState result = m.TrySolve();
                        if (result != SolveState.Solved)
                        {
                            Output(string.Format("Code {0} failed to solve puzzle generated with less powerful generator.", code));
                            using (TextWriter writer = File.CreateText("SelfTestOuput" + failCount + "-" + code + ".loop"))
                            {
                                m.Save(writer);
                            }
                            failCount++;
                        }
                    }
                }
                Output(string.Format("{0} codes solved {1} full generator puzzles {2} times.", codes.Count, extensive ? 100 : 5, solvedCount));
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    Output(string.Format("Failure {0}", ex));
                }
            }
        }
开发者ID:Tilps,项目名称:LoopDeLoop,代码行数:88,代码来源:HelpForm.cs


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