/// <summary>Override; see base.</summary>
        public override ConstraintResult Process(SolverState state)
        {
            for (var cellIx = 0; cellIx < (state.LastPlacedCell != null ? 1 : AffectedCells != null ? AffectedCells.Length : state.GridSize); cellIx++)
            {
                var cell = state.LastPlacedCell ?? (AffectedCells != null ? AffectedCells[cellIx] : cellIx);
                if (state[cell] == null || (AffectedValues != null && !AffectedValues.Contains(state[cell].Value)))
                {
                    continue;
                }

                foreach (var relatedCell in AdjacentCells(cell, GridWidth, GridHeight, IncludeDiagonals))
                {
                    if (EnforcedCells == null || (EnforcedCellsOnly
                            ? (EnforcedCells.Contains(cell) && EnforcedCells.Contains(relatedCell))
                            : (EnforcedCells.Contains(cell) || EnforcedCells.Contains(relatedCell))))
                    {
                        if (state[cell].Value > state.MinValue && (AffectedValues == null || AffectedValues.Contains(state[cell].Value - 1)))
                        {
                            state.MarkImpossible(relatedCell, state[cell].Value - 1);
                        }
                        if (state[cell].Value < state.MaxValue && (AffectedValues == null || AffectedValues.Contains(state[cell].Value + 1)))
                        {
                            state.MarkImpossible(relatedCell, state[cell].Value + 1);
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
 /// <summary>Override; see base.</summary>
 public override sealed ConstraintResult Process(SolverState state)
 {
     for (var cellIx = 0; cellIx < (state.LastPlacedCell != null ? 1 : AffectedCells != null ? AffectedCells.Length : state.GridSize); cellIx++)
     {
         var cell = state.LastPlacedCell ?? (AffectedCells != null ? AffectedCells[cellIx] : cellIx);
         if (state[cell] == null || (AffectedValues != null && !AffectedValues.Contains(state[cell].Value)))
         {
             continue;
         }
         foreach (var relatedCell in getRelatedCells(cell))
         {
             if (EnforcedCells == null || EnforcedCells.Contains(relatedCell) || EnforcedCells.Contains(cell))
             {
                 state.MarkImpossible(relatedCell, state[cell].Value);
             }
         }
     }
     return(null);
 }