public static Palace  GeneratePalaceByRandom()
        {
            Palace        p   = new Palace();
            HashSet <int> set = new HashSet <int>();
            int           M   = scale * scale;
            Random        r   = new Random(DateTime.Now.Millisecond);

            for (int i = 0; i < scale; i++)
            {
                for (int j = 0; j < scale; j++)
                {
                    int n = r.Next(M);
                    while (set.Contains(n))
                    {
                        n = r.Next(M);
                    }
                    p.Numbers [i, j] = n;
                    if (n == 0)
                    {
                        p.NullCell = Cells[i, j];
                    }
                    set.Add(n);
                }
            }
            p.HASH = p.GetHashCode();
            return(p);
        }
        /// <summary>
        /// 经过交换后,产生另一个节点。
        /// </summary>
        /// <param name="act"></param>
        /// <returns></returns>
        public Palace Swap(Action act)
        {
            Palace p = new Palace(this);

            p.Swap(act, false);
            return(p);
        }
Exemple #3
0
 public void play(Palace p)
 {
     foreach (Action act in acts)
     {
         p.Swap(act, true);
     }
     MessageBox.Show("ok");
 }
 public Palace(Palace p)
 {
     Numbers = new int[scale, scale];
     for (int i = 0; i < scale; i++)
         for (int j = 0; j < scale; j++)
             Numbers[i, j] = p.Numbers[i, j];
     this.HASH = p.HASH;
     this.NullCell = p.NullCell;
 }
Exemple #5
0
 private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (p != null)
     {
         p.Undraw();
     }
     Palace.InitStaticPalace(scale, g, margin, width, height);
     p = Palace.GenerateTheDestinationPalace();
     p.ReDraw();
 }
 public Palace(Palace p)
 {
     Numbers = new int[scale, scale];
     for (int i = 0; i < scale; i++)
     {
         for (int j = 0; j < scale; j++)
         {
             Numbers[i, j] = p.Numbers[i, j];
         }
     }
     this.HASH     = p.HASH;
     this.NullCell = p.NullCell;
 }
 public Form1()
 {
     InitializeComponent();
     this.WindowState = FormWindowState.Maximized;
     this.StartPosition = FormStartPosition.CenterScreen;
     MaxScale = 10;
     scale =3;
     margin = 50;
     width = this.Width;
     height = this.Height;
     g = CreateGraphics();
     Palace.InitStaticPalace(scale, g, margin, width, height);
     p = Palace.GenerateTheDestinationPalace();
     th = new Thread(new ThreadStart(ThreadFun));
 }
Exemple #8
0
 public Form1()
 {
     InitializeComponent();
     this.WindowState   = FormWindowState.Maximized;
     this.StartPosition = FormStartPosition.CenterScreen;
     MaxScale           = 10;
     scale  = 3;
     margin = 50;
     width  = this.Width;
     height = this.Height;
     g      = CreateGraphics();
     Palace.InitStaticPalace(scale, g, margin, width, height);
     p  = Palace.GenerateTheDestinationPalace();
     th = new Thread(new ThreadStart(ThreadFun));
 }
        public override bool Equals(object obj)
        {
            Palace p = (Palace)obj;

            for (int i = 0; i < scale; i++)
            {
                for (int j = 0; j < scale; j++)
                {
                    if (this[i, j].Equals(p[i, j]) == false)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #10
0
        /// <summary>
        /// 画数字
        /// </summary>
        public void DrawNumber(Palace p)
        {
            this.UnDrawNumber();
            int    fontSize = 200 / this.Scale;
            Font   f        = new Font("Arial", fontSize);
            int    num      = p.Numbers[this.x, this.y];
            string s        = num.ToString();

            if (num < 10)
            {
                s = "0" + s;
            }
            if (num == 0)
            {
                s = "";
            }
            this.g.DrawString(s, f, blackBrush, this.LEFT, this.UP);
        }
Exemple #11
0
        public static Palace GenerateTheDestinationPalace()
        {
            Palace p = new Palace();
            int    n = 1;

            for (int i = 0; i < scale; i++)
            {
                for (int j = 0; j < scale; j++)
                {
                    if (n != scale * scale)
                    {
                        p.Numbers[j, i] = n;
                    }
                    n++;
                }
            }
            p.NullCell = Cells[scale - 1, scale - 1];
            DestHash   = p.GetHashCode();
            p.HASH     = DestHash;
            return(p);
        }
 public void play( Palace p)
 {
     foreach (Action act in acts)
         p.Swap(act, true);
     MessageBox.Show("ok");
 }
Exemple #13
0
 private void toolStripMenuItem3_Click(object sender, EventArgs e)
 {
     p = Palace.GenerateTheDestinationPalace();
     p.ReDraw();
 }
 public Node(Palace pp, Action pact)
 {
     this.p = pp.Swap(pact);
     act = pact;
     Children = new List<Node>();
 }
Exemple #15
0
 public Node(Palace pp, Action pact)
 {
     this.p   = pp.Swap(pact);
     act      = pact;
     Children = new List <Node>();
 }
 /// <summary>
 /// 画数字
 /// </summary>
 public void DrawNumber(Palace p)
 {
     this.UnDrawNumber();
     int fontSize = 200 / this.Scale;
     Font f=new Font("Arial", fontSize);
     int num = p.Numbers[this.x, this.y];
     string s = num.ToString();
     if (num < 10) s = "0" + s;
     if (num == 0) s = "";
     this.g.DrawString(s, f, blackBrush, this.LEFT, this.UP);
 }
 private void 生成九宫ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     p=Palace.GeneratePalaceByRandom();
     p.ReDraw();
 }
 private void 设置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (p != null) p.Undraw();
     Palace.InitStaticPalace(scale, g, margin, width, height);
     p = Palace.GenerateTheDestinationPalace();
     p.ReDraw();
 }
 private void toolStripMenuItem3_Click(object sender, EventArgs e)
 {
     p=Palace.GenerateTheDestinationPalace();
     p.ReDraw();
 }
Exemple #20
0
 private void 生成九宫ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     p = Palace.GeneratePalaceByRandom();
     p.ReDraw();
 }
Exemple #21
0
 public Engine(Palace pp)
 {
     p = pp;
 }