Esempio n. 1
0
        public void Go()
        {
            algorithmX          = new AlgorithmX();
            algorithmX.callBack = CallBack;
            tableau             = new Node[5 * 25 + 3 * 8, 130];

            index = 0;
            HouseConstraints();
            ElementConstraints();
            ExtraConstraints();
            SingleConstraints();
            PairConstraints();
            NextToConstraints();
            RightOfConstraints();

            ClearCells();
            algorithmX.Init(tableau);

            bool retVal = algorithmX.Search();

            if (retVal)
            {
                Console.WriteLine("Congratulations !");
            }
            else
            {
                Console.WriteLine("No solution");
            }
        }
Esempio n. 2
0
        void Go()
        {
            AlgorithmX algorithmX = new AlgorithmX();

            algorithmX.callBack = CallBack;
            Node[,] tableau     = new Node[94, 46];


            for (int e = 0; e < 94; e++)
            {
                int r = e / 8;
                int c = e % 8;
                for (int rule = 0; rule < 46; rule++)
                {
                    if (e < 64 && (rule == r || rule == 8 + c))
                    {
                        tableau[e, rule] = new Node(e, rule);
                    }
                    else if (e < 64 && rule == 16 + r + c)
                    {
                        tableau[e, rule] = new Node(e, rule);
                    }
                    else if (e < 64 && rule == 31 + 7 - r + c)
                    {
                        tableau[e, rule] = new Node(e, rule);
                    }
                    else if (e >= 64 && rule == e - 64 + 16)
                    {
                        tableau[e, rule] = new Node(e, rule);
                    }
                }
            }

            bool retVal = true;

            algorithmX.Init(tableau);

            DateTime t0 = DateTime.Now;

            retVal = algorithmX.Search();
            DateTime t1 = DateTime.Now;


            if (retVal)
            {
                Console.WriteLine("\nCongratulations !, solved in {0} ms", (t1 - t0).TotalMilliseconds);
            }
            else
            {
                Console.WriteLine("\nSorry, no solution !");
            }

            CheckSolution(algorithmX.result);
        }
Esempio n. 3
0
        public Pentominoes()
        {
            InitializeComponent();

            pictureBox          = new PictureBox();
            pictureBox.Location = new Point(10, 10);
            pictureBox.Paint   += new PaintEventHandler(OnDraw);
            Controls.Add(pictureBox);

            pentominoes = new List <Pentomino>();
            BasicPentominoes();

            algorithmX          = new AlgorithmX();
            algorithmX.callBack = CallBack;

            foreach (Pentomino p in pentominoes)
            {
                p.Print();
                Console.WriteLine();
            }

            comboBox1.SelectedIndex = 4;
        }
Esempio n. 4
0
        void Go()
        {
            AlgorithmX algorithmX = new AlgorithmX();

            algorithmX.callBack = CallBack;
            Node[,] tableau     = new Node[729, 324];
            StreamReader stream = new StreamReader(Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + "/sudoku22533.txt");

            string s = stream.ReadLine();

            string[] split = s.Split(new char[] { '=' });
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    string c = split[split.Length - 1].Substring(9 * i + j, 1);
                    sudoku[i, j] = int.Parse(c == "." ? "0" : c);
                }
            }

            Print();

            for (int r = 0; r < 9; r++)
            {
                for (int c = 0; c < 9; c++)
                {
                    for (int n = 0; n < 9; n++)
                    {
                        int tr = 81 * r + 9 * c + n;
                        int tc = 9 * r + c;
                        if (sudoku[r, c] == 0 || sudoku[r, c] - 1 == n)
                        {
                            tableau[tr, tc] = new Node(tr, tc);
                        }
                    }
                }
            }

            for (int r = 0; r < 9; r++)
            {
                for (int n = 0; n < 9; n++)
                {
                    for (int c = 0; c < 9; c++)
                    {
                        int tr = 81 * r + 9 * c + n;
                        int tc = 81 + 9 * r + n;
                        if (sudoku[r, c] == 0 || sudoku[r, c] - 1 == n)
                        {
                            tableau[tr, tc] = new Node(tr, tc);
                        }
                    }
                }
            }

            for (int c = 0; c < 9; c++)
            {
                for (int n = 0; n < 9; n++)
                {
                    for (int r = 0; r < 9; r++)
                    {
                        int tr = 81 * r + 9 * c + n;
                        int tc = 162 + 9 * c + n;
                        if (sudoku[r, c] == 0 || sudoku[r, c] - 1 == n)
                        {
                            tableau[tr, tc] = new Node(tr, tc);
                        }
                    }
                }
            }

            for (int i1 = 0; i1 < 3; i1++)
            {
                for (int i2 = 0; i2 < 3; i2++)
                {
                    for (int n = 0; n < 9; n++)
                    {
                        for (int j1 = 0; j1 < 3; j1++)
                        {
                            for (int j2 = 0; j2 < 3; j2++)
                            {
                                int tr = 81 * (3 * i1 + j1) + 9 * (3 * i2 + j2) + n;
                                int tc = 243 + 9 * (3 * i1 + i2) + n;
                                if (sudoku[3 * i1 + j1, 3 * i2 + j2] == 0 || sudoku[3 * i1 + j1, 3 * i2 + j2] - 1 == n)
                                {
                                    tableau[tr, tc] = new Node(tr, tc);
                                }
                            }
                        }
                    }
                }
            }

            bool retVal = true;

            algorithmX.Init(tableau);

            DateTime t0 = DateTime.Now;

            retVal = algorithmX.Search();
            DateTime t1 = DateTime.Now;


            if (retVal)
            {
                Console.WriteLine("\nCongratulations !, solved in {0} ms", (t1 - t0).TotalMilliseconds);
            }
            else
            {
                Console.WriteLine("\nSorry, no solution !");
            }

            CheckSolution(algorithmX.result);
        }