/// <summary> /// Based on the position of the given cell it collects its possible neighbour cells /// which are candidates to be put in the given cage. /// </summary> /// <param name="cell">The cell which it searches for the neighbours of.</param> /// <param name="cageIndex">The cage index to examine.</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> /// <returns>The list of possible neighbour cells.</returns> public List<Cell> FindPossibleNeighbourCells(Cell cell, int cageIndex, bool addingNeighbourToCageOfCell) { possibleNeighbourCells = new List<Cell>(); if (cell.IsInFirstRow()) { log.Info("Cell is in first row."); CollectCell(Direction.DOWN, cell, cageIndex, addingNeighbourToCageOfCell); CornerAndThenRowCheck(cell, cageIndex, addingNeighbourToCageOfCell); return possibleNeighbourCells; } if (cell.IsInLastRow()) { log.Info("Cell is in last row."); CollectCell(Direction.UP, cell, cageIndex, addingNeighbourToCageOfCell); CornerAndThenRowCheck(cell, cageIndex, addingNeighbourToCageOfCell); return possibleNeighbourCells; } if (cell.IsInFirstColumn()) { log.Info("Cell is in first column."); CollectCell(Direction.RIGHT, cell, cageIndex, addingNeighbourToCageOfCell); CheckUpAndDown(cell, cageIndex, addingNeighbourToCageOfCell); return possibleNeighbourCells; } if (cell.IsInLastColumn()) { log.Info("Cell is in last column."); CollectCell(Direction.LEFT, cell, cageIndex, addingNeighbourToCageOfCell); CheckUpAndDown(cell, cageIndex, addingNeighbourToCageOfCell); return possibleNeighbourCells; } //If the cell indeces doesn't fit to any previous case, all 4 neighbours of it can be checked. CheckToLeftAndRight(cell, cageIndex, addingNeighbourToCageOfCell); CheckUpAndDown(cell, cageIndex, addingNeighbourToCageOfCell); return possibleNeighbourCells; }
private void CornerAndThenRowCheck(Cell cell, int cageIndex, bool addingNeighbourToCageOfCell) { //i=0: if cell is in the top left corner, i=8: if cell is in the bottom left corner if (cell.IsInFirstColumn()) { CollectCell(Direction.RIGHT, cell, cageIndex, addingNeighbourToCageOfCell); } //i=0: if cell is in the top right corner, i=8: if cell is in the bottom right corner else if (cell.IsInLastColumn()) { CollectCell(Direction.LEFT, cell, cageIndex, addingNeighbourToCageOfCell); } //If cell is in somewhere in the row except the corners else { CheckToLeftAndRight(cell, cageIndex, addingNeighbourToCageOfCell); } }