public string SetSolution(UPuzzle GP, bool SolSet2, bool SolAll = false)
        {
            string solMessage = "";

            GNPX_Eng.pGP = GP;

            string prbMessage = "";

            if (SolAll || GNPX_Eng.pGP.DifLevel <= 0 || GNPX_Eng.pGP.Name == "")
            {
                foreach (var p in GP.BDL)
                {
                    if (p.No < 0)
                    {
                        p.No = 0;
                    }
                }

                GNPX_Eng.AnMan.Set_CellFreeB();
                GNPX_Eng.AnalyzerCounterReset();

                var tokSrc = new CancellationTokenSource();          //for suspension
                GNPX_Eng.sudokAnalyzerAuto(tokSrc.Token);

                if (GNPZ_Engin.retCode < 0)
                {
                    GNPX_Eng.pGP.DifLevel = -999;
                    GNPX_Eng.pGP.Name     = "unsolvable";
                }
                else
                {
                    if (GNPX_Eng.pGP.DifLevel <= 1 || GNPX_Eng.pGP.Name == "")
                    {
                        int difficult = GNPX_Eng.GetDifficultyLevel(out prbMessage);
                        if (GNPX_Eng.pGP.DifLevel <= 1)
                        {
                            GNPX_Eng.pGP.DifLevel = difficult;
                        }
                        if (GNPX_Eng.pGP.Name == "")
                        {
                            GNPX_Eng.pGP.Name = prbMessage;
                        }
                    }
                }
            }
            solMessage = "";    //prbMessage;
            if (SolSet2)
            {
                solMessage += GNPX_Eng.DGViewMethodCounterToString();
            }
                                                                              //適用手法を付加
                solMessage = solMessage.Trim();

            return(solMessage);
        }
Exemple #2
0
        //====================================================================================
        public void SDK_ProblemMakerReal(CancellationToken ct)    //Creating problems[Automatic]
        {
            try{
                int mlt = MltProblem;
                pGNPX_Eng.Set_MethodLst_Run();

                do
                {
                    if (ct.IsCancellationRequested)
                    {
                        ct.ThrowIfCancellationRequested(); return;
                    }

                    LoopCC++; TLoopCC++;
                    List <UCell> BDL = GeneratePuzzleCandidate( );   //Problem candidate generation
                    UPuzzle      P   = new UPuzzle(BDL);
                    pGNPX_Eng.SetGP(P);

                    pGNPX_Eng.AnalyzerCounterReset();
                    pGNPX_Eng.sudokAnalyzerAuto(ct);

                    if (GNPZ_Engin.retCode == 0)
                    {
#if DEBUG
                        __ret000 = true;  //##########
#endif
                        string prbMessage;
                        int    DifLevel = pGNPX_Eng.GetDifficultyLevel(out prbMessage);
                        if (DifLevel < lvlLow || lvlHgh < DifLevel)
                        {
                            continue;                                      //Difficulty check
                        }
#if DEBUG
                        __ret001 = true;  //##########
#endif
                        P.DifLevel   = DifLevel;
                        P.Name       = prbMessage;
                        P.TimeStamp  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                        P.solMessage = pGNPX_Eng.DGViewMethodCounterToString();
                        pGNP00.SDK_ProblemListSet(P);

                        SDKEventArgs se = new SDKEventArgs(ProgressPer: (--mlt));
                        Send_Progress(this, se);  //(can send information in the same way as LoopCC.)
                        if (CbxNextLSpattern)
                        {
                            rxCTRL = 0;                //Change LS pattern at next problem generation
                        }
                    }
                }while(mlt > 0);
            }
            catch (TaskCanceledException) { WriteLine("...Canceled by user."); }
            catch (Exception ex) { WriteLine(ex.Message + "\r" + ex.StackTrace); }
        }