// Start is called before the first frame update void Start() { InitializeNonogram(); InitializeLogicalMatrix(); //Draw the Board board.LogicalMatrix = LogicalMatrix; board.Draw(Height, Length); //Adjust Camera AdjustCameraSize(); //Execute Bounds matrix = new Matrix(_rowClues, _columnClues, Height, Length, board, board.LogicalMatrix); matrix.SolveMatrix(); Debug.Log("-----------------------------------------------"); Debug.Log("Rows"); Debug.Log(matrix.listToString(matrix.Rows)); //Start Backtracking Thread _backtracking = new Backtracking(matrix, LogicalMatrix); _thr = new Thread(_backtracking.StartBacktracking); _thr.Start(); _thr.IsBackground = true; }
public string Resolve(string input) { var lines = input.ToLines().ToList(); lines.RemoveAt(0); var results = new List <string>(); while (lines.Count != 0) { var line = lines[0]; lines.RemoveAt(0); var chunks = line.ToChunks(); _size = int.Parse(chunks[0]); var modelsCount = int.Parse(chunks[1]); _score = 0; _original = new int[_size, _size]; lines.Take(modelsCount).ForEach(l => { var ch = l.ToChunks(); var type = GetModelType(ch[0]); var row = int.Parse(ch[1]); var col = int.Parse(ch[2]); _original[row, col] = type; _score += GetStylePoints(type); }); lines.RemoveRange(0, modelsCount); _modifiable = new int[_size, _size]; _solution = new int[_size, _size]; _current = new int[_size, _size]; _original.CopyTo(_current, 0); var initial = new State(-1, -1, 0, 0, _score); var backtraking = new Backtracking <State>( expand: Expand); var result = backtraking.Begin(initial); results.Add(""); } var output = results .Select((x, i) => $"Case #{i + 1}: {x}") .ToArray(); return(output.JoinLines()); }
// Start is called before the first frame update void Start() { algthm = GetComponent <Backtracking>(); vslMazeCtrll = GetComponent <VisualMazeController>(); controlDataList = new List <ControlData>(); controlPhasesList = new List <ControlPhases>(); if (sectionImages.Length == 0) { sectionImages = new GameObject[steps]; for (int i = 0; i < steps; i++) { sectionImages[i] = GameObject.Find(SECTION + (i + 1)); sectionImages[i].SetActive(false); } } SolveMaze(); }
public void Test() { var configurator = new BacktrackingConfigurator<int, BitArray> (Size, PartialCheck, TotalCheck, GeneratePartiallyBacktrack, CreateArgument, ResetArgument/*, new [] { 3, 1, 2, 4 }, new [] { 4, 1, 2, 3 }*/); var backtracking = new Backtracking<int, BitArray> (configurator); int total = 0; foreach (var solution in backtracking) { ++total; } Console.WriteLine ($"Serial Total = {total}"); total = 0; var sums = new int[Size]; Parallel.For (1, Size + 1, (int i) => { //for (int i = 1; i < Size + 1; i++) { var init = new int[Size]; var last = new int[Size]; init [0] = last [0] = i; int v = 1, u = Size; for (int p = 1; p < Size; ++p) { if (v == i) ++v; init [p] = v++; if (u == i) --u; last [p] = u--; } var configurator2 = new BacktrackingConfigurator<int, BitArray> (Size, PartialCheck, TotalCheck, GeneratePartiallyBacktrack, CreateArgument, ResetArgument, init, last); var backtracking2 = new Backtracking<int, BitArray> (configurator2); int tot = 0; foreach (var solution in backtracking2) { ++tot; } sums [i - 1] = tot; //} }); Array.ForEach (sums, (o) => total += o); Console.WriteLine ($"Parallel Total = {total}"); /*var e1 = backtracking.GetEnumerator (); while (e1.MoveNext ()) { foreach (var part in e1.Current) { Console.Write ($"{part}"); } Console.WriteLine (); var e2 = backtracking.GetEnumerator (); while (e2.MoveNext ()) { foreach (var par in e2.Current) { Console.Write ($"{par}"); } Console.Write (" "); } Console.WriteLine (); Console.WriteLine (); }*/ /*foreach (var solution in backtracking) { foreach (var part in solution) { Console.Write ($"{part}"); } Console.WriteLine (); foreach (var sol in backtracking) { foreach (var part2 in sol) { Console.Write ($"{part2}"); } Console.Write (" "); } Console.WriteLine (); Console.WriteLine (); }*/ }
public void Test() { var configurator = new BacktrackingConfigurator<Point, char[,], bool[,]> (SearchSpace, PartialCheck, TotalCheck, Generate, CreateArgument, ResetArgument, new Point[] { new Point (1, 1), new Point (1, 2)/*, new Point (2, 2), new Point (2, 3) */}, new Point[] { new Point (1, 1), new Point (1, 2), new Point (2, 2), new Point (2, 3), new Point (3, 3), new Point (3, 4), new Point (4, 4), new Point (4, 5) }); var backtracking = new Backtracking<Point, char[,], bool[,]> (configurator); int total = 0; foreach (var solution in backtracking) { ++total; foreach (var part in solution) { Console.Write ($"({part.X}, {part.Y}) "); } Console.WriteLine (); } Console.WriteLine ($"Serial total: {total}"); }
public void SudokuAutomatischGenerieren(int schwierigkeitsgrad) { AutomatischGenerieren = true; FelderLeeren(); Random rnd = new Random(); do { _uc00.Text = rnd.Next(1, 9).ToString(); _uc20.Text = rnd.Next(1, 9).ToString(); _uc40.Text = rnd.Next(1, 9).ToString(); _uc60.Text = rnd.Next(1, 9).ToString(); _uc80.Text = rnd.Next(1, 9).ToString(); _uc23.Text = rnd.Next(1, 9).ToString(); _uc53.Text = rnd.Next(1, 9).ToString(); _uc71.Text = rnd.Next(1, 9).ToString(); ArrayFuellen(); } while (!IstGueltigesFeld()); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (_datenTesten[i, j] == 0) { _datenTesten[i, j] = -1; } } } Backtracking backtracking = new Backtracking(); backtracking._datenTesten = _datenTesten; backtracking.LoeseFeld(); LoesungLaden(); DatenInOberflaecheSchreiben(); //Zufällige Felder entfernen for (int i = 0; i < schwierigkeitsgrad; i++) { int x = rnd.Next(0, 8); int y = rnd.Next(0, 8); foreach (Control ctrl in Controls) { if (ctrl.Tag == null) { continue; } int yCtrl = int.Parse(ctrl.Name.Substring(3, 1)); int xCtrl = int.Parse(ctrl.Name.Substring(4, 1)); if (y == yCtrl && x == xCtrl && ctrl.Text == string.Empty) { i = i - 1; continue; } if (y == yCtrl && x == xCtrl) { ctrl.Text = ""; } } } foreach (Control ctrl in Controls) { if (ctrl.Tag == null) { continue; } if (ctrl.Text != string.Empty) { ((_ucSudokuFeldGross)ctrl).FreieEingabe = false; ((_ucSudokuFeldGross)ctrl).FarbenSetzen = false; ((_ucSudokuFeldGross)ctrl).GueltigeEingabe = Enums.Farbzuweisung.Leer; } else { ((_ucSudokuFeldGross)ctrl).FreieEingabe = true; ((_ucSudokuFeldGross)ctrl).FarbenSetzen = true; ((_ucSudokuFeldGross)ctrl).GueltigeEingabe = Enums.Farbzuweisung.Leer; } } foreach (Control ctrl in Controls) { if (!(ctrl is _ucSudokuFeldGross)) { continue; } _ucSudokuFeldGross feldGross = (_ucSudokuFeldGross)ctrl; for (int i = 0; i < 81; i++) { if (feldGross.Tag.ToString() == i.ToString()) { feldGross.Loesung = _loesung.Substring(i, 1); } } } AutomatischGenerieren = false; }
private void board_Load(object sender, EventArgs e) { //Size of the Window this.AutoSize = true; this.AutoSizeMode = AutoSizeMode.GrowAndShrink; //Intializing the array CSP_variable.chessBoard = new int[CSP_domain.numOfQueens, CSP_domain.numOfQueens]; //To Calculate the Time it take to solve Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //It is a method which is in class "Queens.cs" Backtracking.Backtrack(CSP_domain.numOfQueens, 0); stopwatch.Stop(); //It is a variable which is in class "Queens.cs" Backtracking.ElapsedTime = (stopwatch.Elapsed).ToString(); //All of the disigning are done in these loops for (int x = 0; x < CSP_domain.numOfQueens; x++) { for (int y = 0; y < CSP_domain.numOfQueens; y++) { Label tempLabel = new Label(); //Properties of Label tempLabel.Top = x_axis + (x * LabelHeight + Distance); tempLabel.Left = y_axis + (y * LabelWidth + Distance); tempLabel.Width = LabelWidth; tempLabel.Height = LabelHeight; tempLabel.Font = new Font("Arial", 24, FontStyle.Bold); //First if is going to color rows //in pattern of black and white if (x % 2 == 0) { tempLabel.BackColor = Color.White; //This if is coloring the each row's coloumn if (y % 2 == 1) { tempLabel.BackColor = Color.Black; } } else if (y % 2 == 0) { tempLabel.BackColor = Color.Black; } //If every thing is fine than Queen will going to be display!!! if (CSP_variable.chessBoard[x, y] == 1) { Image img = Image.FromFile(@"C:\Users\Muhammad Farhan\Desktop\NQueenUI\NQueenUI\queen.png"); tempLabel.Image = img; } else { tempLabel.Text = ""; } //Adding the Label in Control this.Controls.Add(tempLabel); } } }