public CellViewModel(Cell cell) { CellId = cell.Id; Possibilities = Helper.GetSetDelimitedLineSepaPossibilities(cell.Cage.Possibilities, cell.UnusableNumbers); UnusableNumbers = Helper.GetNewlineSeparatedString(cell.UnusableNumbers); Operator = cell.Cage.Operation.GetString(); TargetValue = cell.Cage.TargetValue.ToString(); Value = cell.Value == 0 ? string.Empty : cell.Value.ToString(); BorderTop = cell.Cage.Cells.FirstOrDefault(neighbour => neighbour.Column == cell.Column && neighbour.Row == cell.Row - 1) == null; BorderBottom = cell.Cage.Cells.FirstOrDefault(neighbour => neighbour.Column == cell.Column && neighbour.Row == cell.Row + 1) == null; BorderLeft = cell.Cage.Cells.FirstOrDefault(neighbour => neighbour.Row == cell.Row && neighbour.Column == cell.Column - 1) == null; BorderRight = cell.Cage.Cells.FirstOrDefault(neighbour => neighbour.Row == cell.Row && neighbour.Column == cell.Column + 1) == null; }
public Grid(IEnumerable<Cage> cages) { Cages = new List<Cage>(cages); _dimension = Cages.Max(cage => cage.Cells.Max(cell => cell.Row)) + 1; CellMatrix = new Cell[_dimension, _dimension]; _cells = new List<Cell>(); Cages.ForEach(cage => { cage.Cells.ForEach(cell => { CellMatrix[cell.Row, cell.Column] = cell; _cells.Add(cell); }); }); }
public Cell DeepCopy() { Cell newCell = new Cell(this.Row, this.Column); newCell._unusableNumbers = new HashSet<int>(this._unusableNumbers); newCell.Value = this.Value; newCell.Id = this.Id; return newCell; }
internal List<Cell> Neighbours(Cell cell) { return _cells.FindAll(xCell => (xCell.Row == cell.Row || xCell.Column == cell.Column) && xCell != cell); }
void MarkCellAsSolved(Cell cell, int value, List<Cell> localCells = null) { cell.Value = value; List<Possibility> invalidPoss = cell.Cage.FindPossibilitiesNotContainingValue(value); if (localCells == null) { if (invalidPoss.Count > 0) { Step localStepAction = new Step(); localStepAction.FoundCell = cell; localStepAction.CellValue = value; localStepAction.InvalidPossibilities = invalidPoss; _log.LogStep("DeletingInvalidPossibilityAfterCellSolved", localStepAction); } DeleteCagePossibilities(cell.Cage, invalidPoss); AddUnusableNumbersToCells(_kenKenGrid.Neighbours(cell), new List<int> { value }); } else { cell.Cage.DeletePossibilities(invalidPoss); foreach (var affectedCell in localCells) { if (affectedCell != cell && (affectedCell.Row == cell.Row || affectedCell.Column == cell.Column)) affectedCell.UnusableNumbers.Add(cell.Value); } } }