private int CountNumberOfElementsBeforeAndAfterInRow(int rowIdx, int startingColIdx, Color colorToFind) { var array = WorkingGrid.GetRow(rowIdx); var count = 0; var i = startingColIdx - 1; while (i >= 0 && array[i].Equals(colorToFind)) { count++; i--; } i = startingColIdx + 1; while (i < ColCount && array[i].Equals(colorToFind)) { count++; i++; } return(count); }
private void SetupSelectionAndFields(Selection selection) { _selection = selection; if (_selection == Selection.Row) { _items = Rows; _oppositeItems = Columns; _selectionCount = ColCount; _getArray = (rowNumber => WorkingGrid.GetRow(rowNumber)); _getCell = ((x, y) => WorkingGrid[x, y]); } else { _items = Columns; _oppositeItems = Rows; _selectionCount = RowCount; _getArray = (colNumber => WorkingGrid.GetColumn(colNumber)); _getCell = ((x, y) => WorkingGrid[y, x]); } }
private bool CanConnectedColorReachCellInRow(int rowIdx, int colIdx, ColorClassifier rowCc) { var array = WorkingGrid.GetRow(rowIdx); var firstIndex = IndexOf(array, rowCc.MyColor); var lastIndex = LastIndexOf(array, rowCc.MyColor); if (firstIndex <= OutOfBoundsConst) { return(true); } if (firstIndex > colIdx) { //a,_,_,_,b,_,_,_,_,a: "b" er connected, og Count = 2. //colIdx = 1 //firstIndex = 4 //lastIndex = 4 var minIdx = lastIndex - rowCc.Count + 1; //3 if (colIdx < minIdx) { return(false); } } else if (lastIndex < colIdx) { //a,a,a,_,b,_,_,_,_,a: "b" er connected, og Count = 2. //colIdx = 6 //firstIndex = 4 //lastIndex = 4 var maxIdx = firstIndex + rowCc.Count - 1; //5 if (colIdx > maxIdx) { return(false); } } return(true); }