private static bool ClaimRoom(List <Cell> cells, ref Room room) { /*Rooms can only exist within one region*/ if (cells.Select(s => s.regionId).Distinct().Count() > 1) { return(false); } /*A room can only contain a complete sequence of sequenced cells*/ if (cells.Any(x => x.type != CellType.Cell)) { var sequencedCells = cells.Where(x => x.type != CellType.Cell).OrderBy(o => o.sequence).ToList(); for (int i = 0; i < sequencedCells.Count() - 1; i++) { if (sequencedCells[i].sequence != sequencedCells[i + 1].sequence - 1) { return(false); } } } foreach (var cell in cells) { cell.roomId = room.id; CellCollection.Update(cell); } return(true); }