private void LstBxMltAns_SelectionChanged(object sender, SelectionChangedEventArgs e) { try{ if (SDK_Ctrl.UGPMan == null) { return; } var Q = (UProbS)LstBxMltAns.SelectedItem; if (Q == null) { return; } selXUPP = Q.IDmp1 - 1; if (selXUPP < 0) { return; } var U = UPP[selXUPP]; lblAnalyzerResultM.Text = "[" + (Q.IDmp1) + "] " + Q.Sol_ResultLong; List <UPuzzle> pMltUProbLst = SDK_Ctrl.UGPMan.MltUProbLst; if (pMltUProbLst == null || pMltUProbLst.Count <= selXUPP) { return; } UPuzzle pGPx = pMltUProbLst[selXUPP]; SDK_Ctrl.UGPMan.pGPsel = pGPx; if (pGP.IDm != selXUPP) { SDK_Ctrl.UGPMan.GPMnxt = null; } GNP00.GNPX_Eng.pGP = pGPx; } catch (Exception e2) { WriteLine($"{e2.Message}\r{e2.StackTrace}"); } }
private UPuzzle _SetScreenProblem( ) { UPuzzle P = GNP00.GetCurrentProble( ); _Display_GB_GBoard(); if (P != null) { txtProbNo.Text = (P.ID + 1).ToString(); txtProbName.Text = P.Name; nUDDifficultyLevel.Text = P.DifLevel.ToString(); if (GNP00.pGP.pMethod != null) { int DiffL = (GNP00.pGP.pMethod == null)? 0: GNP00.pGP.pMethod.DifLevel; lblCurrentnDifficultyLevel.Content = $"Difficulty: {DiffL}"; //CurrentLevel if (lblAnalyzerResult.Text != "") { lblCurrentnDifficultyLevel.Visibility = Visibility.Visible; } else { lblCurrentnDifficultyLevel.Visibility = Visibility.Hidden; } } btnProbPre.IsEnabled = (P.ID > 0); btnProbNxt.IsEnabled = (P.ID < GNP00.SDKProbLst.Count - 1); _Set_DGViewMethodCounter(); } return(P); }
private void btnCopyProblem_Click(object sender, RoutedEventArgs e) { UPuzzle UPcpy = pGP.Copy(0, 0); UPcpy.Name = "copy"; GNP00.CreateNewPrb(UPcpy); //reserve space for new problems _SetScreenProblem(); //Show free numbers }
public void SDK_Save_ifNotContain() { UPuzzle pGP = GNPX_Eng.pGP; if (!Contain(pGP)) { SDK_Save_EngGP(); } }
public UPuzzle GetCurrentProble( ) { UPuzzle P = null; if (CurrentPrbNo >= 0 && CurrentPrbNo <= SDKProbLst.Count - 1) { P = SDKProbLst[CurrentPrbNo]; } return(P); }
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); }
public void CreateNewPrb(UPuzzle UP = null) { if (UP == null) { UP = new UPuzzle("New Problem"); } UP.ID = SDKProbLst.Count; GNPX_Eng.SetGP(UP); SDK_Save(UP); CurrentPrbNo = 999999999; }
//==================================================================================== 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); } }
public void btnFavfileOutput(bool fType81 = true, bool SolSet = false, bool SolSet2 = false) { string LRecord; string fNameFav = "SDK_Favorite.txt"; var tokSrc = new CancellationTokenSource(); //procedures for suspension GNPXApp000.SlvMtdCList[0] = true; //use all methods UPuzzle pGP = GNPX_Eng.pGP; GNPX_Eng.AnMan.Set_CellFreeB(); GNPX_Eng.sudokAnalyzerAuto(tokSrc.Token); string prbMessage; int difLvl = GNPX_Eng.GetDifficultyLevel(out prbMessage); using (var fpW = new StreamWriter(fNameFav, true, Encoding.UTF8)){ if (fType81) { LRecord = ""; pGP.BDL.ForEach(q => { LRecord += Max(q.No, 0).ToString(); }); LRecord = LRecord.Replace("0", "."); LRecord += $" {(pGP.ID+1)} {pGP.DifLevel} \"{pGP.Name}\""; if (SolSet && SolSet2) { LRecord += $" \"{SetSolution(pGP,SolSet2:true,SolAll:true)}\""; //解を出力 } if (pGP.TimeStamp != null) { LRecord += $" \"{pGP.TimeStamp}\""; } } else { LRecord = $"{pGP.ID+1}, {GNPX_Eng.pGP.DifLevel} \"{pGP.Name}\", \"{prbMessage}\""; fpW.WriteLine(LRecord); for (int r = 0; r < 9; r++) { int n = pGP.BDL[r * 9 + 0].No; LRecord = n.ToString(); for (int c = 1; c < 9; c++) { n = pGP.BDL[r * 9 + c].No; LRecord += $", {n}"; } LRecord += "\r"; } } fpW.WriteLine(LRecord); } GNPXApp000.SlvMtdCList[0] = false;//use selected methods }
public void SDK_TransIX(int[] TrPara, bool TransB = false, bool DspSolB = false) { int rx = TrPara[8], cx = 1 - rx; for (int j = 0; j < 2; j++) { for (int k = 0; k < 9; k++) { int n = RCX[j, k / 3 + 9]; RCX[j + 2, k] = RCX[j, n + k % 3]; } } List <UCell> UCL = null; if (TransB) { UCL = new List <UCell>(); } int [] AnsN2 = new int[81]; int r, c, w; for (int rc = 0; rc < 81; rc++) { r = RCX[rx + 2, rc / 9]; c = RCX[cx + 2, rc % 9]; if (rx == 1) { w = r; r = c; c = w; } int rc2 = r * 9 + c; AnsN2[rc] = UPbas.AnsNum[rc2]; if (TransB) { UCell P = UPbas.BDL[rc2]; UCL.Add(new UCell(rc, P.No, P.FreeB)); } } if (TransB) { UPuzzle UP = pGP.Copy(0, 0); UP.BDL = UCL; UP.AnsNum = AnsN2; pGNP.SDKProbLst[ID] = UP; if (!DspSolB) { UP.BDL.ForEach(P => { P.No = Max(P.No, 0); }); } pGNP.CurrentPrbNo = ID; } SetIDCode(TrPara, AnsN2); }
public void Force_NextSuccessor(int RX) { rxCTRL = RX - 1; for (int r = RX; r < 9; r++) { LSR[r].firstB = true; } List <UCell> BDL = GeneratePuzzleCandidate(); //problem generation UPuzzle P = new UPuzzle(BDL); pGNPX_Eng.SetGP(P); }
public void SDK_ProblemListSet(UPuzzle GPx) { GPx.ID = SDKProbLst.Count; //// if(GPx.BDL.Any(q=>q.FreeB>0)) SDKProbLst.Add(GPx); if (SDK_Ctrl.FilePut_GenPrb) { string fName = "AutoGen" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt"; emergencyFilePut("AutoGen", fName); } CurrentPrbNo = SDKProbLst.Count - 1; }
//===== Pattern capture ===== public int patternImport(UPuzzle pGP) { int nc = 0; foreach (var P in pGP.BDL) { int n = P.No > 0? 1: 0; GPat[P.r, P.c] = n; nc += n; } _PatternToBit( ); //Bit Representation of the Pattern return(nc); }
public void _SDK_Ctrl_Initialize() { AnalyzerMode = "Solve"; GNPX_Eng.pGP.Sol_ResultLong = ""; UPuzzle pGP = GetCurrentProble(); GNPX_Eng.SetGP(pGP); GNPX_Eng.AnalyzerCounterReset( ); GNPX_Eng.AnMan.ResetAnalysisResult(true); //Return to initial state GNPX_Eng.AnMan.Set_CellFreeB(); SDK_Ctrl.UGPMan = null; //initialize Multi_solver GNPX_Eng.pGP.extRes = ""; }
public UPuzzle Copy(int stageNo, int IDm) { UPuzzle P = (UPuzzle)this.MemberwiseClone(); P.BDL = new List <UCell>(); foreach (var q in BDL) { P.BDL.Add(q.Copy()); } P.HTicks = DateTime.Now.Ticks;; P.stageNo = this.stageNo + 1; P.IDm = IDm; return(P); }
private void displayTimer_Tick(object sender, EventArgs e) { _Display_GB_GBoard(); //****************** UPuzzle GPML = null; if (GNP00.GSmode == "DigRecogCmp" || GNP00.GSmode == "DigRecogCancel") { if (GNP00.SDK81 != null) { GNP00.CurrentPrbNo = 999999999; GPML = GNP00.SDK_ToUProblem(GNP00.SDK81, saveF: true); GNP00.CurrentPrbNo = GPML.ID; //20180731 } displayTimer.Stop(); /* * btnRecog.Content="Input"; * bdbtnRecog.BorderBrush=Brushes.Blue; * cameraMessageBox.Content = (GNP00.GSmode=="DigRecogCmp")? "Fixed": "Canceled"; * cameraMessageBox.Foreground = Brushes.LightBlue; */ _SetScreenProblem(); GNP00.GSmode = "tabACreate"; } /* * bool? B=SDK_Ctrl.paraSearching; * if(B!=null && !(bool)B){ * displayTimer.Stop(); * _SetScreenProblem( ); * SDK_Ctrl.paraSearching=null; * } */ switch (GNP00.GSmode) { case "DigRecogTry": case "tabACreate": _Display_CreateProblem(); break; case "tabBMultiSolve": case "tabASolve": _Display_AnalyzeProb(); break; } lblResourceMemory.Content = "Memory: " + GC.GetTotalMemory(true).ToString("N0"); if (((++__GCCounter__) % 1000) == 0) { GC.Collect(); __GCCounter__ = 0; } }
//========================================================== public bool SnapSaveGP(bool saveAll = false) { if (SDK_Ctrl.UGPMan == null) { return(false); } try{ if (!SDK_Ctrl.MltAnsSearch) { UPuzzle GPX = pGP.Copy(pGP.stageNo + 1, 0); GPX.__SolRes = GPX.Sol_ResultLong.Replace("\r", " "); SDK_Ctrl.UGPMan.MltUProbLst.Add(GPX); SDK_Ctrl.UGPMan.pGPsel = GPX; return(false); } if (SDK_Ctrl.UGPMan.MltUProbLst == null) { SDK_Ctrl.UGPMan.MltUProbLst = new List <UPuzzle>(); } if (SDK_Ctrl.UGPMan.MltUProbLst.Count >= (int)SDK_Ctrl.MltAnsOption["AllMethod"]) { SDK_Ctrl.MltAnsOption["abortResult"] = pRes.msgUpperLimitBreak; return(false); } string __SolRes = pGP.Sol_ResultLong.Replace("\r", " "); if (saveAll || SDK_Ctrl.UGPMan.MltUProbLst.All(P => (P.__SolRes != __SolRes))) { Thread.Sleep(1); int IDm = SDK_Ctrl.UGPMan.MltUProbLst.Count; UPuzzle GPX = pGP.Copy(pGP.stageNo + 1, IDm); GPX.__SolRes = GPX.Sol_ResultLong.Replace("\r", " "); SDK_Ctrl.UGPMan.MltUProbLst.Add(GPX); SDK_Ctrl.UGPMan.pGPsel = GPX; NuPz_Win.UPP.Add(new UProbS(GPX)); } // else{ // WriteLine(" SnapSave GPSDK_Ctrl.UGPMan.MltUProbLst: "+SDK_Ctrl.UGPMan.MltUProbLst.Count+pGP.__SolRes); // } } catch (Exception e) { WriteLine(e.Message + "\r" + e.StackTrace); } pBDL.ForEach(p => p.ResetAnalysisResult()); pGP.SolCode = -1; return(true); }
public UPuzzle SDK_ToUProblem(string st, string name = "", int difLvl = 0, bool saveF = false) { List <UCell> B = _stringToBDL(st); if (B == null) { return(null); } var UP = new UPuzzle(999999999, B, name, difLvl); if (saveF) { SDK_Save(UP); } return(UP); }
private RenderTargetBitmap bmpPD = new RenderTargetBitmap(176, 176, 96, 96, PixelFormats.Default);//176=18*9+2*4+1*6 private void _Display_CreateProblem() { txbNoOfTrials.Text = GNP00.SDKCntrl.LoopCC.ToString(); txbNoOfTrialsCum.Text = SDK_Ctrl.TLoopCC.ToString(); txbBasicPattern.Text = GNP00.SDKCntrl.PatternCC.ToString(); int n = gamGen05.Text.ToInt(); lblNoOfProblems1.Content = (n - _ProgressPer).ToString(); UPuzzle pGP = GNP00.pGP; if (pGP != null) { int nn = GNP00.SDKProbLst.Count; if (nn > 0) { txtProbNo.Text = nn.ToString(); txtProbName.Text = GNP00.SDKProbLst.Last().Name; nUDDifficultyLevel.Text = pGP.DifLevel.ToString(); } } string st = AnalyzerLapElaped; Lbl_onAnalyzerTS.Content = st; Lbl_onAnalyzerTSM.Content = st; txbEpapsedTimeTS3.Text = st; if (__DispMode != null && __DispMode != "") { _SetScreenProblem(); displayTimer.Stop(); AnalyzerLap.Stop(); btnCreateProblemMlt.Content = pRes.btnCreateProblemMlt; } __DispMode = ""; if ((bool)chbCreateProblemEx2.IsChecked) { SDKGrp.GBPatternDigit(bmpPD, Sol99sta); } else { bmpPD.Clear(); } PB_BasePatDig.Source = bmpPD; }
private void _Display_GB_GBoard(UPuzzle GPML = null, bool DevelopB = false) { if (GNP00.AnalyzerMode == "MultiSolve" && __DispMode != "Complated") { return; } try{ UPuzzle currentP = GPML ?? pGP; if (currentP == null) { return; } lblUnderAnalysis.Visibility = (GNP00.GSmode == "tabASolve")? Visibility.Visible: Visibility.Hidden; Lbl_onAnalyzerM.Visibility = Visibility.Visible; SDKGrp.GBoardPaint(bmpGZero, currentP.BDL, GNP00.GSmode, sNoAssist); PB_GBoard.Source = bmpGZero; //◆currentP.BDL set __Set_CellsPZMCount(); txtProbNo.Text = (currentP.ID + 1).ToString(); txtProbName.Text = currentP.Name; nUDDifficultyLevel.Text = currentP.DifLevel.ToString(); //The following code "pMethod" is rewritten to another thread. //This may cause an access violation. //here Try with try{...} catch(Exception){...}. int DiffL = (GNP00.pGP.pMethod == null)? 0: GNP00.pGP.pMethod.DifLevel; // lblCurrentnDifficultyLevel.Content = $"Difficulty: {DiffL}"; //CurrentLevel if (DevelopB) { _Display_Develop(); } if (GNP00.GSmode == "tabASolve") { _Display_ExtResultWin(); } } catch (Exception e) { WriteLine(e.Message + "\r" + e.StackTrace); #if DEBUG using (var fpW = new StreamWriter("Exception_002e.txt", true, Encoding.UTF8)){ fpW.WriteLine($"---{DateTime.Now} {e.Message} \r{e.StackTrace}"); } #endif } }
private UPuzzle CreateDigitToUProblem(int[] SDK81) { string st = ""; for (int rc = 0; rc < 81; rc++) { int nn = SDK81[rc]; if (nn > 9) { nn = 0; } st += st.ToString(); } UPuzzle UP = GNP00.SDK_ToUProblem(st, saveF: true); return(UP); }
public void SDK_Remove() { UPuzzle pGP = GNPX_Eng.pGP; int PnoMemo = CurrentPrbNo; if (PnoMemo == SDKProbLst.Count - 1) { PnoMemo--; } if (Contain(pGP)) { SDKProbLst.Remove(pGP); } int id = 0; SDKProbLst.ForEach(P => P.ID = (id++)); CurrentPrbNo = PnoMemo; }
private void DspNumRandmize(UPuzzle P) { List <int> ranNum = new List <int>(); for (int r = 0; r < 9; r++) { ranNum.Add(rnd.Next(0, 9) * 10 + r); } ranNum.Sort((x, y) => (x - y)); for (int r = 0; r < 9; r++) { ranNum[r] %= 10; } int n; P.BDL.ForEach(q => { if ((n = q.No) > 0) { q.No = ranNum[n - 1] + 1; } }); }
private void Initialize(bool StartF = true) { pGNPX_Eng.Set_MethodLst_Run(AllMthd: true, GenLogUse: false); //True:All Method pGNP.SetSolution(pGP, false, SolAll: true); //Solver pGP.AnsNum = pGP.BDL.ConvertAll(P => P.No).ToArray(); TrPara = new int[18]; RCX = new int[4, 12]; for (int k = 0; k < 9; k++) { RCX[0, k] = RCX[1, k] = k; } for (int k = 0; k < 3; k++) { RCX[0, k + 9] = RCX[1, k + 9] = k * 3; } if (StartF) { UPorg = pGP.Copy(0, 0); } UPbas = pGP.Copy(0, 0); }
public void btnTransRes() { if (pGP.AnsNum == null) { return; } UPbas = UPorg.Copy(0, 0); UPuzzle tGP = UPorg.Copy(0, 0); pGNP.SDKProbLst[ID] = tGP; pGNP.GNPX_Eng.pGP = tGP; TrPara = new int[18]; RCX = new int[4, 12]; for (int k = 0; k < 9; k++) { RCX[0, k] = RCX[1, k] = k; } for (int k = 0; k < 3; k++) { RCX[0, k + 9] = RCX[1, k + 9] = k * 3; } }
public SDKSolutionEventArgs(UPuzzle GPX) { this.UPB = new UProbS(GPX); this.GPX = GPX; }
public void GBoardPaintPrint(RenderTargetBitmap bmp, UPuzzle pGP) { if (pGP == null) { return; } int LWid = pGNP00.lineWidth; int CSiz = pGNP00.cellSize; int CSizP = CSiz + LWid; Brush brBoad = new SolidColorBrush(Colors.White); Point ptS, ptE; //RenderTargetBitmap Rbmp; Rect Rrct = new Rect(0, 0, CSiz, CSiz); //Courier GFont gFnt32 = new GFont("Courier", 32, FontWeights.DemiBold, FontStyles.Normal); GFormattedText GF32 = new GFormattedText(gFnt32); var drawVisual = new DrawingVisual(); using (DrawingContext DC = drawVisual.RenderOpen()){ DC.DrawRectangle(brBoad, null, new Rect(0, 0, bmp.Width, bmp.Height)); Brush br = new SolidColorBrush(Colors.Black); Point pt = new Point(); foreach (UCell BDX in pGP.BDL) { int r = BDX.r, c = BDX.c; pt.X = c * CSizP + LWid / 2 + (c / 3); pt.Y = r * CSizP + LWid / 2 + (r / 3); Rrct.X = pt.X; Rrct.Y = pt.Y; int No = BDX.No; if (No != 0) { #region Problem/solved cell pt.X += 10; pt.Y += 2; string NoStr = Abs(No).ToString(); DC.DrawText(GF32.GFText(NoStr, br), pt); #endregion } } #region Draw line on board Pen pen1 = new Pen(br, 1), pen2 = new Pen(br, 2), pen; int hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(0, hh); ptE = new Point(CSiz * 10 - 2, hh); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(hh, 0); ptE = new Point(hh, CSiz * 10 - 2); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } #endregion } bmp.Render(drawVisual); return; }
public void SDK_Save(UPuzzle UP) { UP.ID = SDKProbLst.Count; SDKProbLst.Add(UP); }
public bool Contain(UPuzzle UP) { return(SDKProbLst.Find(P => P.HTicks == UP.HTicks) != null); }
public void CESetGP(UPuzzle UP) { GNPX_Eng.SetGP(UP); }