feat: added method to fill sudoku from integer list
All checks were successful
Linux arm64 / Build (push) Successful in 1m4s
All checks were successful
Linux arm64 / Build (push) Successful in 1m4s
This commit is contained in:
@@ -12,6 +12,8 @@ import sudoku.io.SudokuSerializer;
|
||||
import sudoku.solver.Solver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public String getGreeting() {
|
||||
@@ -20,34 +22,18 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new Main().getGreeting());
|
||||
|
||||
int blockWidth = 2;
|
||||
int blockHeight = 2;
|
||||
var multidoku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||
var sudoku = multidoku.getSubGrid(0);
|
||||
//SudokuPrinter.printRectangleSudoku(sudoku, blockWidth , blockHeight);
|
||||
//Line 1:
|
||||
((MutableCell)sudoku.getCell(0)).setSymbolIndex(0);
|
||||
((MutableCell)sudoku.getCell(1)).setSymbolIndex(1);
|
||||
((MutableCell)sudoku.getCell(2)).setSymbolIndex(2);
|
||||
((MutableCell)sudoku.getCell(3)).setSymbolIndex(3);
|
||||
//Line 2:
|
||||
((MutableCell)sudoku.getCell(4)).setSymbolIndex(2);
|
||||
((MutableCell)sudoku.getCell(5)).setSymbolIndex(3);
|
||||
((MutableCell)sudoku.getCell(6)).setSymbolIndex(0);
|
||||
((MutableCell)sudoku.getCell(7)).setSymbolIndex(1);
|
||||
//Line 3:
|
||||
((MutableCell)sudoku.getCell(8)).setSymbolIndex(1);
|
||||
((MutableCell)sudoku.getCell(9)).setSymbolIndex(0);
|
||||
((MutableCell)sudoku.getCell(10)).setSymbolIndex(3);
|
||||
((MutableCell)sudoku.getCell(11)).setSymbolIndex(2);
|
||||
// Line 4
|
||||
((MutableCell)sudoku.getCell(12)).setSymbolIndex(3);
|
||||
((MutableCell)sudoku.getCell(13)).setSymbolIndex(2);
|
||||
((MutableCell)sudoku.getCell(14)).setSymbolIndex(1);
|
||||
((MutableCell)sudoku.getCell(15)).setSymbolIndex(0);
|
||||
|
||||
sudoku.setCellsSymbol(Arrays.asList(0,1,2,3, 2,3,0,1, 1,0,3,2, 3,2,1,0));
|
||||
SudokuPrinter.printRectangleSudoku(multidoku.getSubGrid(0), blockWidth , blockHeight);
|
||||
|
||||
//sudoku.setCellSymbol(8,3,0);
|
||||
|
||||
|
||||
|
||||
ArrayList<IConstraint> constraints = new ArrayList<>();
|
||||
constraints.add(new LineConstraint());
|
||||
constraints.add(new ColumnConstraint());
|
||||
@@ -55,6 +41,8 @@ public class Main {
|
||||
|
||||
System.out.println(sudoku.isValid(constraints));
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Solver solver = new Solver();
|
||||
ArrayList<IConstraint> constraints = new ArrayList<>();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Try to place a cell at the given coordinate
|
||||
*
|
||||
*
|
||||
* @return false if it can't be done
|
||||
*/
|
||||
public boolean setCellSymbol(int x, int y, int value) {
|
||||
@@ -49,6 +49,21 @@ public class Sudoku {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setCellsSymbol(List<Integer> values) {
|
||||
if (values.size() > this.cells.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
int x = i%this.blocks.size();
|
||||
int y = (i-x)/this.blocks.size();
|
||||
if (!this.setCellSymbol(x, y, values.get(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Cell getCell(int x, int y) {
|
||||
int index = y * getSize() + x;
|
||||
assert (isValidCoords(x, y));
|
||||
|
||||
Reference in New Issue
Block a user