/// <summary> /// Checks the 4 neighbours of the provided cell /// and adds the neighbour to the list of possible neighbour cells /// </summary> /// <param name="direction">The direction to search towards</param> /// <param name="cell">The cell to search among the neighbours of.</param> /// <param name="cageIndex">The cage index to search in.</param> /// <param name="addingNeighbourToCageOfCell"> /// Whether we want to add a neighbourcell to the cage of the current cell, or /// we want to add the current cell into the neighbour's cage. /// </param> private void CollectCell(Direction direction, Cell cell, int cageIndex, bool addingNeighbourToCageOfCell) { Cell alteredCell = cell.WithAlteredIndecesByDirection(direction); int row = alteredCell.Row; int col = alteredCell.Col; if (addingNeighbourToCageOfCell /* If we want to join one of the neighbour cells to the cage of "cell". * If the neighbour is in any of the cages, and the neighbour cell is in the cage of "cell".*/ ? !se.Killer.IsCellInAnyCage(row, col) && !IsCageContainValue(se.Solution[row, col], cageIndex, se.Solution) /* If we want to join "cell" to the cage of one of the neighbour cells. * This can happen when "cell" is left empty, and the cells around it are already in a cage. * If the neighbour is in a cage, and the cage of the neighbour cell doesn't contain the value of "cell".*/ : se.Killer.IsCellInAnyCage(row, col) && !IsCageContainValue(se.Solution[cell.Row, cell.Col], se.Killer.CageIndeces[row, col], se.Solution)) possibleNeighbourCells.Add(new Cell(row, col)); }