예제 #1
0
        private void CheckNAryColAgainstColsAndSubs(LinearElement col, int colIdx, int val)
        {
            var valIdxs           = new HashSet <int>(col.Where(r => r.PossibleValues.Contains(val)).Select(r => r.y));
            var complimentaryCols = board.Cols.Where((element, i) => i / Global.SIZE != colIdx / Global.SIZE);

            var buddyCols = complimentaryCols.Where(c => new HashSet <int>(c.Where(s => s.PossibleValues.Contains(val)).Select(s => s.y)).SetEquals(valIdxs));

            if (buddyCols.Any())
            {
                if (buddyCols.Count() > 1)
                {
                    throw new InvalidOperationException("More than one buddy row. Your logic is flawed. Great job, f**k wad");
                }

                var buddyCol = buddyCols.Single();

                var affectedRows = board.Cols.Where((element, i) => i / Global.SIZE != colIdx / Global.SIZE && i / Global.SIZE != buddyCol.First().x / Global.SIZE);
                var changesMade  = false;
                foreach (var affectedRow in affectedRows)
                {
                    foreach (int i in valIdxs)
                    {
                        changesMade = affectedRow[i].RemoveValue(val) || changesMade;
                    }
                }

                if (changesMade)
                {
                    _solutionSteps.Add(solutionStep(StepType.NAryAmbiguousLinearExclusion));
                }
            }
        }
예제 #2
0
 public SubGrid()
 {
     _squares = new Square[Global.SIZE, Global.SIZE];
     _rows    = new LinearElement[Global.SIZE];
     _columns = new LinearElement[Global.SIZE];
     for (int i = 0; i < Global.SIZE; i++)
     {
         _rows[i]    = new LinearElement();
         _columns[i] = new LinearElement();
     }
 }
예제 #3
0
        public Board(int?[,] initialValues)
        {
            _squares  = new Square[Global.BOARD_SIZE, Global.BOARD_SIZE];
            _rows     = new LinearElement[Global.BOARD_SIZE];
            _columns  = new LinearElement[Global.BOARD_SIZE];
            _subGrids = new SubGrid[Global.SIZE, Global.SIZE];
            for (int i = 0; i < Global.BOARD_SIZE; i++)
            {
                _rows[i]    = new LinearElement();
                _columns[i] = new LinearElement();
                _subGrids[i / Global.SIZE, i % Global.SIZE] = new SubGrid();
            }

            Initialize(initialValues);
        }