Compare commits
4 Commits
master
...
createPlus
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e67e7a9d4 | |||
|
|
70eef1646d | ||
| 5dfe4382fe | |||
|
|
059886c2a4 |
@@ -2,10 +2,15 @@ package gui;
|
||||
|
||||
import gui.constants.Fonts;
|
||||
import gui.constants.Images;
|
||||
import gui.constants.Symbols;
|
||||
import gui.menu.MainMenu;
|
||||
import gui.menu.StateMachine;
|
||||
import imgui.app.Application;
|
||||
import imgui.app.Configuration;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
@@ -41,6 +46,13 @@ public class Main extends Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(new Main());
|
||||
MultiDoku doku = SudokuFactory.createBasicPlusShapedMultidoku(3, 3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
try {
|
||||
SudokuFactory.fillDoku(doku, Difficulty.Easy);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
SudokuPrinter.printMultiDoku(doku, 3, 3, Symbols.Numbers);
|
||||
//launch(new Main());
|
||||
}
|
||||
}
|
||||
@@ -90,29 +90,23 @@ public class RenderableMultidoku {
|
||||
}
|
||||
|
||||
private static Coordinate getMaxSudokuCoordinate(Map<Sudoku, Coordinate> sudokusOffset) {
|
||||
Coordinate maxCoordinate = null;
|
||||
Sudoku maxSudoku = null;
|
||||
float maxDistanceSquared = 0;
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
Sudoku lastSudoku = null;
|
||||
for (var entry : sudokusOffset.entrySet()) {
|
||||
Coordinate coordinate = entry.getValue();
|
||||
float distanceSquared = coordinate.getX() * coordinate.getX() + coordinate.getY() * coordinate.getY();
|
||||
if (maxCoordinate == null) {
|
||||
maxCoordinate = coordinate;
|
||||
maxDistanceSquared = distanceSquared;
|
||||
maxSudoku = entry.getKey();
|
||||
}
|
||||
|
||||
if (distanceSquared > maxDistanceSquared) {
|
||||
maxDistanceSquared = distanceSquared;
|
||||
maxSudoku = entry.getKey();
|
||||
maxCoordinate = coordinate;
|
||||
}
|
||||
if (coordinate.getX() > maxX)
|
||||
maxX = coordinate.getX();
|
||||
if (coordinate.getY() > maxY)
|
||||
maxY = coordinate.getY();
|
||||
lastSudoku = entry.getKey();
|
||||
}
|
||||
|
||||
int blockWidth = maxSudoku.getBlockWidth();
|
||||
int blockHeight = maxSudoku.getSize() / blockWidth;
|
||||
Coordinate maxCoordinate = new Coordinate(maxX, maxY);
|
||||
// tous les sudokus sont censés faire la même taille
|
||||
int sudokuSize = lastSudoku.getSize();
|
||||
|
||||
return new Coordinate(maxCoordinate.getX() + maxSudoku.getSize(), maxCoordinate.getY() + maxSudoku.getSize());
|
||||
return new Coordinate(maxCoordinate.getX() + sudokuSize, maxCoordinate.getY() + sudokuSize);
|
||||
}
|
||||
|
||||
public static RenderableMultidoku fromMultidoku(MultiDoku doku) {
|
||||
|
||||
@@ -14,10 +14,14 @@ public enum SudokuType {
|
||||
(constraints, params) -> SudokuFactory.createBasicEmptyRectangleDoku(params[0], params[1], constraints)),
|
||||
RandomBloc("Blocs aléatoires", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicEmptyRandomBlockDoku(params[0], constraints)),
|
||||
MultiDokuSquare("Multidoku carré (X)", 1,
|
||||
MultiDokuXSquare("Multidoku carré (X)", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], constraints)),
|
||||
MultidokuRectangle("Multidoku rectangle (X)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], params[1], constraints));
|
||||
MultidokuXRectangle("Multidoku rectangle (X)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], params[1], constraints)),
|
||||
MultiDokuPSquare("Multidoku carré (+)", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicPlusShapedMultidoku(params[0], constraints)),
|
||||
MultiDokuPRectangle("Multidoku rectangle (+)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicPlusShapedMultidoku(params[0], params[1], constraints));
|
||||
|
||||
String displayName;
|
||||
SudokuMaker maker;
|
||||
|
||||
@@ -234,24 +234,7 @@ public class SudokuFactory {
|
||||
public static MultiDoku createBasicXShapedMultidoku(int size, List<IConstraint> constraints) {
|
||||
assert (size > 1);
|
||||
|
||||
/*
|
||||
* 2 3
|
||||
* 1
|
||||
* 4 5
|
||||
*/
|
||||
|
||||
Sudoku sudoku1 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku2 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku3 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku4 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku5 = createSquareSudoku(size, constraints);
|
||||
|
||||
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - size, 1 - size));
|
||||
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(size - 1, 1 - size));
|
||||
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(1 - size, size - 1));
|
||||
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(size - 1, size - 1));
|
||||
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
return createBasicXShapedMultidoku(size, size, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,6 +270,55 @@ public class SudokuFactory {
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Créée un MultiDoku de Blocks carrés de taille size composé de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blockss d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
* @param size int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicPlusShapedMultidoku(int size, List<IConstraint> constraints) {
|
||||
assert (size > 1);
|
||||
|
||||
return createBasicPlusShapedMultidoku(size, size, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme width par height composé
|
||||
* de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blocks d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
* @param width int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @param height int, hauteur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicPlusShapedMultidoku(int width, int height, List<IConstraint> constraints) {
|
||||
assert (width > 1 && height > 1);
|
||||
|
||||
/*
|
||||
* 3
|
||||
* 2 1 4
|
||||
* 5
|
||||
*/
|
||||
|
||||
Sudoku sudoku1 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku2 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku3 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku4 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku5 = createRectangleSudoku(width, height, constraints);
|
||||
|
||||
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - height, 0));
|
||||
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(0, 1 - width));
|
||||
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(height - 1, 0));
|
||||
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(0, width - 1));
|
||||
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
}
|
||||
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver solver = new RandomSolver();
|
||||
solver.solve(doku);
|
||||
@@ -309,8 +341,7 @@ public class SudokuFactory {
|
||||
public static MultiDoku createBasicEmptyRandomBlockDoku(int blockSize, List<IConstraint> constraints) {
|
||||
int blockCellCount = blockSize * blockSize;
|
||||
List<Cell> cells = initCells(blockCellCount);
|
||||
List<Cell> homeLessCells = new ArrayList<>();
|
||||
homeLessCells.addAll(cells);
|
||||
List<Cell> homeLessCells = new ArrayList<>(cells);
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < blockCellCount; i++) {
|
||||
|
||||
Reference in New Issue
Block a user