Example #1
0
        private bool TrySetSingleElement(SkyscraperData d, int row, int col, int mask)
        {
            int v = (mask ^ -1) & (d.Data[row, col] & ((d.SetInRow[row] | d.SetInCol[col]) ^ -1));  //zostaja jedynki tam gdzie w masce sa 0, dodatkowo wylaczone juz ustawione bity

            if (d.CountBits(v) == 1)
            {
                d.SetSingleElementMask(row, col, v);
                if (!ReduceRowCol(d, row, col))
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Example #2
0
 private bool TryReduceSingleElement(SkyscraperData d, int row, int col, int mask, out bool singleset)
 {
     singleset = false;
     //if (d.CountBits(row, col) > 1)
     {
         d.RemoveElementMask(row, col, mask);
         if (d.CountBits(row, col) == 1)
         {
             if (((d.Data[row, col] & d.SetInRow[row]) != 0) || ((d.Data[row, col] & d.SetInCol[col]) != 0))
             {
                 SkyscrapersCounters.ReduceRCDoublesCut++;
                 return(false);
             }
             d.SetSingleElementMask(row, col, d.Data[row, col]);
             if (!ReduceRowCol(d, row, col))
             {
                 return(false);
             }
             singleset = true;
         }
     }
     return(true);
 }
Example #3
0
        public void ApplyConstraints(SkyscraperData d, int[] constraints)
        {
            //ograniczenia od lewej do prawej po N rzedow
            //po przejsciu N rzedow obrot tablicy w prawo i analiza kolejnych rzedow
            for (int i = constraints.Length - 1; i >= 0; i--)
            {
                if (constraints[i] > 0)
                {
                    int row = _n - 1 - i % _n;
                    if (constraints[i] == _n)
                    {
                        for (int k = 0; k < _n; k++)
                        {
                            d.Data[row, k] = SkyscraperData.Masks[k + 1];
                        }
                    }
                    else if (constraints[i] == 1)
                    {
                        d.Data[row, 0] = SkyscraperData.Masks[_n];
                    }
                    else
                    {
                        for (int el = _n; el > 1; el--)
                        {
                            for (int k = 0; k < constraints[i] - 1 - (_n - el); k++)
                            {
                                d.RemoveElement(row, k, el);
                            }
                        }
                    }
                }
                if (i % _n == 0)
                {
                    d.RotateRight();
                }
            }
            //po nalozeniu ograniczen wygenerowanie list indeksow pozycji nie jednobitowych
            for (int i = 0; i < _n; i++)
            {
                for (int j = 0; j < _n; j++)
                {
                    if (d.CountBits(i, j) > 1)
                    {
                        d.Rows[i].Add(j);
                        d.Cols[j].Add(i);
                    }
                }
            }

            //po nalozeniu ograniczen uwzglednienie wszystkich powstalych pozycji jednoelementowych (redukcja w wierszach i kolumnach)
            List <Tuple <int, int> > proc = new List <Tuple <int, int> >();

            for (int i = 0; i < _n; i++)
            {
                for (int j = 0; j < _n; j++)
                {
                    if (d.CountBits(i, j) == 1)
                    {
                        d.SetSingleElementMask(i, j, d.Data[i, j]);
                        proc.Add(new Tuple <int, int>(i, j));
                    }
                }
            }
            _dataReductor.ReduceData(d, proc);
        }