Esempio n. 1
0
        private static bool UnoptimizedSearch(Queens queens, int N)
        {
            queens.Init();
            int col, row;

            for (int i = 0; i < N * K; i++)
            {
                if (N <= 50)
                {
                    queens.PrintQueens();
                }

                if (queens.IsValid())
                {
                    return(true);
                }
                col = GetColWithMaxConflicts(queens.queens);
                if (col == -1)
                {
                    break;
                }

                row = GetRowWithMinConflicts(queens.queens, col);
                if (row == -1)
                {
                    break;
                }

                queens.MooveQueen(col, row);
            }
            return(queens.IsValid());
        }
Esempio n. 2
0
        private static bool Search(Queens queens, int N)
        {
            int col, row;

            for (int i = 0; i < N * K; i++)
            {
                if (queens.IsValid())
                {
                    return(true);
                }
                col = queens.GetColWithMaxConflicts();
                if (col == -1)
                {
                    break;
                }

                row = queens.GetRowWithMinConflicts(col);
                if (row == -1)
                {
                    break;
                }

                queens.MooveQueen(col, row);
            }
            return(queens.IsValid());
        }