Esempio n. 1
0
        private void Vs_solve_Report(Suduku current, int ProcessedStates, int Radius)
        {
            this.ProcessedStates = ProcessedStates;

            this.CurrnetDepth = Radius;
            this.latestTable  = current.Table;
        }
Esempio n. 2
0
 private void btnNext_Click(object sender, EventArgs e)
 {
     if (this.stackSuduku.Count > 0)
     {
         currentSuduku        = stackSuduku.Pop();
         txtCurrentDepth.Text = "= " + currentSuduku.Depth;
         DrawSuduku(currentSuduku);
     }
 }
Esempio n. 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (currentSuduku != null && currentSuduku.Parent != null)
     {
         stackSuduku.Push(currentSuduku);
         currentSuduku        = currentSuduku.Parent;
         txtCurrentDepth.Text = " =" + currentSuduku.Depth;
         DrawSuduku(currentSuduku);
     }
 }
Esempio n. 4
0
 private void Slv_Report(Suduku current, double temperature, double score)
 {
     this.latestTable = current.Table;
     if (this.Diagram.IsDisposed)
     {
         this.Diagram = new DiagramForm();
         this.Diagram.Show();
     }
     this.Diagram.Update(temperature, current.ConflictCount);
 }
Esempio n. 5
0
 private void Slv_ProblemSolved(Suduku goalState, int ProcessedState)
 {
     currentSuduku = goalState;
     watch.Stop();
     this.InvokeIfRequired(f =>
     {
         pnlInfo.BackColor = Color.LightGreen;
         DrawSuduku(goalState);
         this.Text               = "Suduku Solved!";
         txtCurrentDepth.Text    = "=" + goalState.Depth.ToString();
         txtProcessedStates.Text = "=" + ProcessedState;
         txtEllapsedTime.Text    = watch.Elapsed.TotalSeconds + " s";
         Loading(false);
     });
 }
Esempio n. 6
0
        public static Suduku GetNextRandom(this Suduku current, bool HoldPointer = false)
        {
            Random rand = new Random((int)DateTime.Now.Ticks);
            var    x    = rand.Next(0, (int)current.SudukuType);
            var    y1   = rand.Next(0, (int)current.SudukuType);
            var    y2   = y1;

            while (y2 == y1)
            {
                y2 = rand.Next(0, (int)current.SudukuType);
            }

            var next = current.Swap(x, y1, x, y2, HoldPointer);

            return(next);
        }
Esempio n. 7
0
        private void DrawSuduku(Suduku su)
        {
            var  upper  = (int)su.SudukuType;
            bool loaded = upper * upper == pnlSuduku.Controls.Count;

            if (!loaded)
            {
                pnlSuduku.Controls.Clear();
            }
            var spiliter = su.SudukuType == SudukuType.Nine_Nine ? 3 : 2;

            Color[] spltColor = new Color[] { Color.LightGray, Color.LightSlateGray };
            var     width     = pnlSuduku.Width / upper;
            var     height    = pnlSuduku.Height / upper;
            var     conficts  = su.GetConflicts();

            for (int i = 0; i < upper; i++)
            {
                for (int j = 0; j < upper; j++)
                {
                    if (loaded)
                    {
                        var l = pnlSuduku.Controls[(i * upper) + j] as Label;
                        l.Text      = su.Table[i, j].ToString();
                        l.ForeColor = conficts[i, j] > 0 ? Color.Red : Control.DefaultForeColor;
                    }
                    else
                    {
                        Label lbl = new Label
                        {
                            Text        = su.Table[i, j].ToString(),
                            Width       = width,
                            Height      = height,
                            TextAlign   = ContentAlignment.MiddleCenter,
                            BackColor   = spltColor[Math.Abs((i / spiliter) - (j / spiliter)) % 2],
                            ForeColor   = conficts[i, j] > 0 ? Color.Red : Control.DefaultForeColor,
                            Font        = new Font(Control.DefaultFont, FontStyle.Bold),
                            Location    = new Point(width * j, height * i),
                            BorderStyle = BorderStyle.FixedSingle
                        };
                        pnlSuduku.Controls.Add(lbl);
                    }
                }
            }
        }
Esempio n. 8
0
        public void Start(Suduku su, double limitedMinutes)
        {
            this.LimitedMinute = limitedMinutes;
            sp.Reset();
            sp.Start();
            var  current = su;
            long a       = 0;

            while (!current.Solved && this.T > 0)
            {
                a++;
                this.T = this.Schedule(a);
                var next = Next(current, this.T);
                var dE   = current.ConflictPercent - next.ConflictPercent;
                if (dE > 0)
                {
                    current = next;
                }
                else
                {
                    dE = dE < 0 ? dE * -1 : dE;
                    var r = rand.NextDouble();
                    var p = this.T; //Math.Pow( Math.Pow(Math.E, (double)dE / this.T),-1);
                    if (r <= p)
                    {
                        current = next;
                    }
                }

                if (a % 100 == 0 && this.Report != null)
                {
                    this.Report(current, this.T, current.ConflictPercent);
                }
            }

            if (this.ProblemSolved != null)
            {
                this.ProblemSolved(current, (int)a);
            }
        }
Esempio n. 9
0
        private Suduku Next(Suduku su, double t)
        {
            var x  = rand.Next(0, (int)su.SudukuType);
            var y1 = rand.Next(0, (int)su.SudukuType);
            var y2 = y1;

            while (y2 == y1)
            {
                y2 = rand.Next(0, (int)su.SudukuType);
            }

            var next = su.Swap(x, y1, x, y2, false);

            if (dic.ContainsKey(next.GetHashCode()))
            {
                return(Next(su, t));
            }
            else
            {
                return(next);
            }
        }
Esempio n. 10
0
 private void Slv_InfoEvent(Suduku su, int ProcessedCount)
 {
     CurrnetDepth     = su.Depth;
     ProcessedStates  = ProcessedCount;
     this.latestTable = su.Table;
 }
Esempio n. 11
0
 private void cboSusukuType_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentSuduku = new Suduku((SudukuType)(sender as ComboBox).SelectedItem);
     Reset();
 }