예제 #1
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
        private void Vs_solve_Report(Suduku current, int ProcessedStates, int Radius)
        {
            this.ProcessedStates = ProcessedStates;

            this.CurrnetDepth = Radius;
            this.latestTable  = current.Table;
        }
예제 #2
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 private void btnNext_Click(object sender, EventArgs e)
 {
     if (this.stackSuduku.Count > 0)
     {
         currentSuduku        = stackSuduku.Pop();
         txtCurrentDepth.Text = "= " + currentSuduku.Depth;
         DrawSuduku(currentSuduku);
     }
 }
예제 #3
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 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);
     }
 }
예제 #4
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 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);
 }
예제 #5
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 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);
     });
 }
예제 #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);
        }
예제 #7
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
        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);
                    }
                }
            }
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #10
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 private void Slv_InfoEvent(Suduku su, int ProcessedCount)
 {
     CurrnetDepth     = su.Depth;
     ProcessedStates  = ProcessedCount;
     this.latestTable = su.Table;
 }
예제 #11
0
파일: Form1.cs 프로젝트: p30home/Suduku_SA
 private void cboSusukuType_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentSuduku = new Suduku((SudukuType)(sender as ComboBox).SelectedItem);
     Reset();
 }