protected override void Initialize() { Tools.initilize(this.Content); exCell = new Cell(0, new Vector2(50, 50), 0); base.Initialize(); }
public static IReadOnlyCollection<Cell> GetIntersectingCells(Board board, Cell cellA, Cell cellB) { var associatedA = GetAssociatedCells(board, cellA); var asoociatedB = GetAssociatedCells(board, cellB); return associatedA.Intersect(asoociatedB).ToList(); }
/// <summary> /// Initializes a new <see cref="Sudoku.Grid"/> and prepares its Rows, Columns, Boxes and Cells. /// </summary> public Grid() { Rows = new Row[9]; Columns = new Column[9]; Boxes = new Box[9]; for (var i=0; i<9; i++) { Rows[i] = new Row(i, this); Columns[i] = new Column(i, this); Boxes[i] = new Box(i, this); } Cells = new Cell[81]; for (var i=0; i<81; i++) { Cell c = new Cell { Grid = this, Location = i, Row = RowOf(i), Column = ColumnOf(i), Box = BoxOf(i) }; c.Possibilities.UnionWith(Enumerable.Range(1,9)); Cells[i] = c; } }
public void Initialize(Cell[,] parentGrid, int sidelength) { _subgridWidth = (int) Math.Sqrt(sidelength); AvailableNumbers = new List<CellValue>(Enum.GetValues(typeof (CellValue)).Cast<CellValue>()); if (sidelength < 25) for (int i = 25; i >= sidelength + 1; i--) AvailableNumbers.RemoveAt(i); AvailableNumbers.Remove(CellValue.None); RelatedCells = GetRelatedCells(sidelength,parentGrid); }
public static IReadOnlyCollection<Cell> GetAssociatedCells(Board board, Cell cell) { var output = new List<Cell>(); output.AddRange(GetBox(board, cell).Cells); output.AddRange(GetColumn(board, cell).Cells); output.AddRange(GetRow(board, cell).Cells); output.RemoveAll(c => c == cell); return output.Distinct().ToList(); }
public Range(int width, int height, bool initialize) { _width = width; _height = height; _grid = new Dictionary<Location, Cell>(_width * _height); if (initialize) { for (int i = 0; i < width; ++i) for (int j = 0; j < height; ++j) this[i, j] = new Cell(0); } }
public override IScore GetCellScore(Cell cell) { if (cell.CellScore == null) { IScore score = Score.EmptyScore; if (cell.Moves.Count > 0) { foreach (var move in cell.Moves) { if (move.MoveScore == null) { move.MoveScore = GetScore(move); score = (MultiPartScore)score + (MultiPartScore)move.MoveScore; } } } cell.CellScore = score; } return cell.CellScore; }
public Grid(string gridstring) { //magic numbers if (gridstring.Length < 16 || gridstring.Length > 625) { throw new Exception("gridstring too short, expected 16,81,256 or 625 got " + gridstring.Length); } //[ROW,COLUMN] SideLength = (int)Math.Sqrt(gridstring.Length); Cells = new Cell[SideLength, SideLength]; string parsedString = gridstring.Replace("\n", "").Replace(" ", "0"); int i = 0; for (int row = 0; row < SideLength; row++) { for (int column = 0; column < SideLength; column++) { int number = -1; if (parsedString[i] >= 65) { //parse letter to number if (parsedString[i] <= 90) number = parsedString[i] - 64; else if (parsedString[i] >= 97 && parsedString[i] <= 122) number = parsedString[i] - 96; } else number = int.Parse(parsedString[i].ToString()); Cells[row, column] = new Cell(row, column, number); if (number != 0) PresolvedCells.Add(Cells[row, column]); i++; } } foreach (Cell cell in Cells) cell.Initialize(Cells,SideLength); }
public MainViewModel() { Values = new List<List<Cell>>(); for (int i = 0; i < 9; i++) { var inner = new List<Cell>(); Values.Add(inner); for (int j = 0; j < 9; j++) { var cell = new Cell(); cell.Value = (j + 1).ToString(); cell.IsLocked = (j % 2 == 0); if (j == 3) { cell.Value = ""; cell.Options = "1,4,7"; } inner.Add(cell); } } }
public bool ContainsCell(Cell cell) { return ContainsCell(cell.Coordinates); }
public static Unit GetBox(Board board, Cell cell) { return board.Boxes.First(b => b.Cells.Contains(cell)); }
public static Unit GetColumn(Board board, Cell cell) { return board.Columns.First(c => c.Cells.Contains(cell)); }
List<Cell> GetRelatedCells(int sideLength,Cell[,] parentGrid) { List<Cell> cells = new List<Cell>(); for (int column = 0; column < sideLength; column++) { if (column == Column) continue; cells.Add(parentGrid[Row, column]); } for (int row = 0; row < sideLength; row++) { if (row == Row) continue; cells.Add(parentGrid[row, Column]); } int subGridWidth = _subgridWidth; int subGridRowStart = Row / subGridWidth * subGridWidth; int subGridColumnStart = Column / subGridWidth * subGridWidth; for (int row = subGridRowStart; row < subGridRowStart + subGridWidth; row++) { for (int column = subGridColumnStart; column < subGridColumnStart + subGridWidth; column++) { if (row == Row && column == Column) continue; if (!cells.Contains(parentGrid[row, column])) cells.Add(parentGrid[row, column]); } } return cells; }
private void CreateCells(string input) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { var cell = new Cell(input.Substring(i * 9 + j, 1), string.Format("r{0}c{1}", i + 1, j + 1)); _cells[i, j] = cell; } } }
public abstract IScore GetCellScore(Cell cell);
public SudokuBoard(int[,] presets) { if ((presets.GetLength(0) > 9) || (presets.GetLength(1) > 9)) throw new Exception("Error - Sudoku board size too large"); else { board = new Cell[9,9]; rows = new List<Section>(); columns = new List<Section>(); regions = new List<Section>(); // Initialize each section for (int i = 0; i < 9; i++) { rows.Add(new Section(SectionType.ROW)); // initialize each Row columns.Add(new Section(SectionType.COLUMN)); // initalize each Column regions.Add(new Section(SectionType.REGION)); // initialize each Region } // Initalize each cell with it's preset value and whether or not it's a blank (modifiable) square for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { if ((presets[i, j] > 0) && (presets[i, j] <= 9)) // if coordinate is a preset cell, set it to value and isBlank false board[i, j] = new Cell(presets[i, j], false, j, i); else // else set it to zero and isBlank true board[i, j] = new Cell(0, true, j, i); } } // Assign each row and column it's group of cells List<Cell> rowCells = new List<Cell>(); List<Cell> colCells = new List<Cell>(); for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { rowCells.Add(board[i, j]); // load up all cells in row colCells.Add(board[j, i]); // load up all cells in column } rows[i].AssignCells(rowCells); // set each rows cells columns[i].AssignCells(colCells); // set each columns cells rowCells = new List<Cell>(); // generate new List after each row as to not delete from memory colCells = new List<Cell>(); // generate new List after each column as to not delete from memory } // Assign each region it's group of cells List<Cell> regCells = new List<Cell>(); int reg = 0; for (int i = 0; i < board.GetLength(0); i += 3) { for (int j = 0; j < board.GetLength(1); j += 3) { for (int k = i; k < i + 3; k++) for (int l = j; l < j + 3; l++) regCells.Add(board[k, l]); // load up all cells in region regions[reg].AssignCells(regCells); // set each regions cells ++reg; // increment counter for List of regions regCells = new List<Cell>(); // generate new List after each region as to not delete from memory } } // Assign each cell their sections int regNum = 0; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { if ((j % 3 == 0) && (j != 0)) // step over one region horizontally every 3 cells regNum++; board[i, j].SetSections(rows[i], columns[j], regions[regNum]); } if (i < 2) // bring region back to 0 regNum = 0; else if (i < 5) // bring region back to 3 regNum = 3; else if (i < 8) // bring region back to 6 regNum = 6; } } }
public NumberButton(Cell cell) { this.Cell = cell; InitializeComponent(); }
public static Unit GetRow(Board board, Cell cell) { return board.Rows.First(r => r.Cells.Contains(cell)); }