Exemplo n.º 1
0
        public void Reset()
        {
            List <Square> list = tableLayoutPanel1.Controls.OfType <Square>().OrderBy(a => a.Number).ToList();

            tableLayoutPanel1.Controls.Clear();
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    string order = PuzzleDriver.GetBasePuzzleOrder()[i * 3 + j].ToString();
                    var    sq    = list.SingleOrDefault(a => Regex.Replace(a.Name, "\\D*", "") == order);
                    if (sq != null)
                    {
                        tableLayoutPanel1.Controls.Add(sq, j, i);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Shuffle()
        {
            do
            {
                List <Square> list = tableLayoutPanel1.Controls.OfType <Square>().ToList();
                list.Add(null);
                List <Square> newList = new List <Square>();
                int[,] matrix = new int[3, 3];

                Random rnd = new Random();

                while (list.Count > 0)
                {
                    int r = rnd.Next(0, list.Count);
                    newList.Add(list[r]);
                    list.RemoveAt(r);
                }

                tableLayoutPanel1.Controls.Clear();
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        var obj = newList[i * 3 + j];
                        if (obj == null)
                        {
                            matrix[i, j] = obj?.Number ?? 0;
                            continue;
                        }

                        matrix[i, j] = obj.Number;

                        tableLayoutPanel1.Controls.Add(obj, i, j);
                    }
                }
            } while (!isSolvable(PuzzleDriver.GetBasePuzzleOrder(), GetSequentalOrder));
        }