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 btnSavePuzzle_Click(object sender, RoutedEventArgs e) { var SaveFDlog = new SaveFileDialog(); SaveFDlog.Title = pRes.filePuzzleFile; SaveFDlog.FileName = fNameSDK; SaveFDlog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; GNPXApp000.SlvMtdCList[0] = true; if (!(bool)SaveFDlog.ShowDialog()) { return; } fNameSDK = SaveFDlog.FileName; bool append = (bool)chbAdditionalSave.IsChecked; bool fType81 = (bool)chbFile81Nocsv.IsChecked; bool SolSort = (bool)chbSolutionSort.IsChecked; bool SolSet = (bool)cbxProbSolSetOutput.IsChecked; bool SolSet2 = (bool)chbAddAlgorithmList.IsChecked; if (GNP00.SDKProbLst.Count == 0) { if (pGP.BDL.All(p => p.No == 0)) { return; } pGP.ID = GNP00.SDKProbLst.Count; GNP00.SDKProbLst.Add(pGP); GNP00.CurrentPrbNo = 0; _SetScreenProblem(); } GNP00.GNPX_Eng.Set_MethodLst_Run(AllMthd: false); //true:All Method GNP00.SDK_FileOutput(fNameSDK, append, fType81, SolSort, SolSet, SolSet2); }
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 }
private void btnNewProblem_Click(object sender, RoutedEventArgs e) { if (pGP.BDL.All(P => P.No == 0)) { return; } GNP00.SDK_Save_ifNotContain(); GNP00.CreateNewPrb(); //reserve space for new problems _SetScreenProblem(); //Show free numbers }
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; } }
//Copy/Paste Puzzle(board<-->clipboard) private void Grid_PreviewKeyDown(object sender, KeyEventArgs e) { bool KeySft = (Keyboard.Modifiers & ModifierKeys.Shift) > 0; bool KeyCtrl = (Keyboard.Modifiers & ModifierKeys.Control) > 0; var P = Mouse.GetPosition(PB_GBoard); var(W, H) = (PB_GBoard.Width, PB_GBoard.Height); if (P.X < 0 || P.Y < 0 || P.X >= W || P.Y >= H) { return; } if (e.Key == Key.C && KeyCtrl) { string st = pGP.CopyToBuffer(); try{ Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, st); } catch (System.Runtime.InteropServices.COMException) { /* NOP */ } } else if (e.Key == Key.F && KeyCtrl) { string st = pGP.ToGridString(KeySft); try{ Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, st); } catch (System.Runtime.InteropServices.COMException) { /* NOP */ } } else if (e.Key == Key.V && KeyCtrl) { string st = (string)Clipboard.GetData(DataFormats.Text); Clipboard.Clear(); if (st == null || st.Length < 81) { return; } var UP = GNP00.SDK_ToUPuzzle(st, saveF: true); if (UP == null) { return; } GNP00.CurrentPrbNo = 999999999; //GNP00.SDKProbLst.Count-1 _SetScreenProblem(); _ResetAnalizer(false); //Clear analysis result } }
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); }
private void btnOpenPuzzleFile_Click(object sender, RoutedEventArgs e) { var OpenFDlog = new OpenFileDialog(); OpenFDlog.Multiselect = false; OpenFDlog.Title = pRes.filePuzzleFile; OpenFDlog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; if ((bool)OpenFDlog.ShowDialog()) { fNameSDK = OpenFDlog.FileName; GNP00.SDK_FileInput(fNameSDK, (bool)chbInitialState.IsChecked); txtFileName.Text = fNameSDK; _SetScreenProblem(); GNP00._SDK_Ctrl_Initialize(); btnProbPre.IsEnabled = (GNP00.CurrentPrbNo >= 1); btnProbNxt.IsEnabled = (GNP00.CurrentPrbNo < GNP00.SDKProbLst.Count - 1); } }
private void btnSaveToFavorites_Click(object sender, RoutedEventArgs e) { GNP00.btnFavfileOutput(true, SolSet: true, SolSet2: true); }
private void SuDoKuSolver() { try{ lblUnderAnalysis.Foreground = Brushes.LightGreen; Lbl_onAnalyzerM.Foreground = Brushes.LightGreen; if ((string)btnSolve.Content != pRes.msgSuspend) { int mc = GNP00.GNPX_Eng.Set_MethodLst_Run( ); if (mc <= 0) { GNP00.ResetMethodList(); } lblUnderAnalysis.Visibility = Visibility.Visible; Lbl_onAnalyzerM.Visibility = Visibility.Visible; //GNPZ_Engin.SolInfoB = false; if (GNP00.SDKCntrl.retNZ == 0) { GNP00.SDKCntrl.LoopCC = 0; } SDK_Ctrl.MltProblem = 1; //single SDK_Ctrl.lvlLow = 0; SDK_Ctrl.lvlHgh = 999; GNP00.SDKCntrl.CbxDspNumRandmize = false; GNP00.SDKCntrl.GenLStyp = 1; GNPXApp000.chbConfirmMultipleCells = (bool)chbConfirmMultipleCells.IsChecked; GNPZ_Engin.SolInfoB = true; AnalyzerLap.Reset(); if (GNP00.AnalyzerMode == "Solve" || GNP00.AnalyzerMode == "MultiSolve") { if (GNP00.pGP.SolCode < 0) { GNP00.pGP.SolCode = 0; } ErrorStopB = !_cellFixSub(); List <UCell> pBDL = pGP.BDL; if (pBDL.Count(p => p.No == 0) == 0) //analysis completed { _SetScreenProblem(); goto AnalyzerEnd; } OnWork = 1; txbStepCC.Text = (++AnalyzerCC).ToString(); btnSolve.Content = pRes.msgSuspend; lblUnderAnalysis.Content = pRes.lblUnderAnalysis; txbStepMCC.Text = txbStepCC.Text; btnMultiSolve.Content = btnSolve.Content; Lbl_onAnalyzerM.Content = lblUnderAnalysis.Content; lblUnderAnalysis.Foreground = Brushes.Orange; Lbl_onAnalyzerM.Foreground = Brushes.Orange; Lbl_onAnalyzerTS.Content = ""; Lbl_onAnalyzerTSM.Content = ""; this.Cursor = Cursors.Wait; if (!ErrorStopB) { __DispMode = ""; AnalyzerLap.Start(); //============================================================== tokSrc = new CancellationTokenSource(); //for Cancellation taskSDK = new Task(() => GNP00.SDKCntrl.AnalyzerReal(tokSrc.Token), tokSrc.Token); taskSDK.ContinueWith(t => task_SDKsolver_Completed()); //procedures used on completion taskSDK.Start(); } else { __DispMode = "Complated"; } if (GNP00.AnalyzerMode != "MultiSolve") { displayTimer.Start(); // <- To avoid unresolved operation trouble. } // displayTimer.Start(); //-------------------------------------------------------------- } else { try{ tokSrc.Cancel(); taskSDK.Wait(); btnSolve.Content = pRes.btnSolve; } catch (AggregateException e2) { WriteLine(e2.Message); __DispMode = "Canceled"; } } AnalyzerEnd: return; } } catch (Exception ex) { WriteLine(ex.Message); WriteLine(ex.StackTrace); } }
private void btnSDKAnalyzerAuto_Click(object sender, RoutedEventArgs e) { if (OnWork == 1) { return; } GNP00.AnalyzerMode = "SolveUp"; GNP00.GNPX_Eng.MethodLst_Run.ForEach(P => P.UsedCC = 0); if ((string)btnSolveUp.Content == pRes.msgSuspend) { tokSrc.Cancel(); try{ taskSDK.Wait(); } catch (AggregateException) { __DispMode = "Canceled"; } displayTimer.Start(); OnWork = 0; } else { List <UCell> pBDL = pGP.BDL; if (pBDL.Count(p => p.No == 0) == 0) //complate { _SetScreenProblem(); goto AnalyzerEnd; } if (pBDL.Any(p => (p.No == 0 && p.FreeB == 0))) //No Solution { lblAnalyzerResult.Text = pRes.msgNoSolution; goto AnalyzerEnd; } OnWork = 2; btnSolveUp.Content = null; btnSolveUp.Content = pRes.msgSuspend; lblUnderAnalysis.Content = pRes.lblUnderAnalysis; lblUnderAnalysis.Foreground = Brushes.Orange; int mc = GNP00.GNPX_Eng.Set_MethodLst_Run( ); if (mc <= 0) { GNP00.ResetMethodList(); } _ResetAnalizer(true); //Clear Analysis Result GNP00.GNPX_Eng.AnalyzerCounterReset(); GNPZ_Engin.SolInfoB = false; SDK_Ctrl.lvlLow = 0; SDK_Ctrl.lvlHgh = 999; //============================================================== tokSrc = new CancellationTokenSource(); CancellationToken ct = tokSrc.Token; taskSDK = new Task(() => GNP00.SDKCntrl.AnalyzerRealAuto(ct), ct); taskSDK.ContinueWith(t => task_SDKsolverAuto_Completed()); AnalyzerLap.Reset(); taskSDK.Start(); //-------------------------------------------------------------- this.Cursor = Cursors.Wait; AnalyzerLap.Start(); __DispMode = ""; AnalyzerEnd: displayTimer.Start(); return; } }
private void btnDeleteProblem_Click(object sender, RoutedEventArgs e) { GNP00.SDK_Remove(); _SetScreenProblem(); //Show free numbers }