public CellData(Dictionary <CellSetType, CellSet> cellSets, int y, int x) { Coordinates = new Coordinates { Y = y, X = x }; CellSets = new List <CellSetType>(); Value = 0; IsNumberAllowed = new bool[10]; for (int i = 1; i < 10; i++) { IsNumberAllowed[i] = true; } foreach (var cellSetType in cellSets.Keys) { var cellSet = cellSets[cellSetType]; if (cellSet.ContainsCoordinate(y, x)) { CellSets.Add(cellSetType); } } HexagonCellSet = new CellSet(); HexagonCellSet.PopulateHexagon(y, x); }
private bool InsideElimination(CellData cellData, List <Coordinates> newNumbers) { var inside = CellSet.GetInside(cellData.CellSets); if (inside == CellSetType.NONE) { return(false); } var insideCellSet = _cellSets[inside]; var allowableNumbers = cellData.GetListOfAllowableNumbers(); // Get all free cells in each triangle. // For each cell. // For each number in that cell. // See if any of the other free cells allow it. // If none of them do, them we have to use that number. foreach (var allowableNumber in allowableNumbers) { var foundOtherNumber = false; foreach (var coordinate in insideCellSet.Coordinates) { if ((cellData.Coordinates.Y != coordinate.Y || cellData.Coordinates.X != coordinate.X) && _cells[coordinate.Y, coordinate.X].Value == 0) { if (_cells[coordinate.Y, coordinate.X].IsNumberAllowed[allowableNumber]) { foundOtherNumber = true; break; } } } if (!foundOtherNumber) { cellData.Value = allowableNumber; newNumbers.Add(new Coordinates { Y = cellData.Coordinates.Y, X = cellData.Coordinates.X }); return(true); } } return(false); }