private void SetMatrixValues(IList <bool> mRow, BoardSquare boardSquare) { var row = boardSquare.GetRowIndex(); var column = boardSquare.GetColumnIndex(); var value = boardSquare.GetValue() - 1; int RegionIndex() { var regionSize = (int)Math.Sqrt(size); var regionNum1 = (int)Math.Floor(row / (double)regionSize) * regionSize + (int)Math.Floor(column / (double)regionSize); return(regionNum1); } // In order, sets of 81 indexes var positionConstraint = row * size + column; var rowConstraint = size * size + row * size + value; var columnConstraint = size * size * 2 + column * size + value; var regionConstraint = size * size * 3 + RegionIndex() * size + value; // Initialize matrix where the constraint is satisfied mRow[positionConstraint] = true; mRow[rowConstraint] = true; mRow[columnConstraint] = true; mRow[regionConstraint] = true; }
private IEnumerable <BoardSquare> GetNeighbours(BoardSquare currentSquare) { var Row = currentSquare.GetRowIndex(); var Column = currentSquare.GetColumnIndex(); var SubBoard = currentSquare.GetSubBoard(Column, Row); var PlacedValues = new List <BoardSquare>(); PlacedValues.AddRange(_board.GetRow(Row)); PlacedValues.AddRange(_board.GetColumn(Column)); PlacedValues.AddRange(_board.GetSubBoard(SubBoard)); return(PlacedValues); }