beaucoup
All checks were successful
Linux arm64 / Build (push) Successful in 1m47s

This commit is contained in:
2025-01-10 14:47:20 +01:00
parent 34cf7b5da8
commit 09ba8c00cb
13 changed files with 147 additions and 46 deletions

View File

@@ -0,0 +1,15 @@
package sudoku.constraint;
import sudoku.Bloc;
import sudoku.Case;
import sudoku.Sudoku;
public class BlockConstraint implements IConstraint{
@Override
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
Bloc bloc = s.getCase(x, y).getBloc();
return !bloc.getCases().contains(new Case(newSymbolIndex));
}
}

View File

@@ -0,0 +1,16 @@
package sudoku.constraint;
import sudoku.Sudoku;
public class ColumnConstraint implements IConstraint {
@Override
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
for (int i = 0; i < s.getSize(); i++) {
if (s.getCase(x, newSymbolIndex).getSymboleIndex() == newSymbolIndex)
return false;
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
package sudoku.constraint;
import java.util.ArrayList;
import java.util.List;
import sudoku.Sudoku;
public interface IConstraint {
boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex);
default List<Integer> getPossibleSymbols(final Sudoku s, int x, int y) {
List<Integer> possibilities = new ArrayList<>();
for (int i = 0; i < s.getSize(); i++) {
if (canBePlaced(s, x, y, i)) {
possibilities.add(i);
}
}
return possibilities;
}
}

View File

@@ -0,0 +1,16 @@
package sudoku.constraint;
import sudoku.Sudoku;
public class LineConstraint implements IConstraint {
@Override
public boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex) {
for (int i = 0; i < s.getSize(); i++) {
if (s.getCase(newSymbolIndex, y).getSymboleIndex() == newSymbolIndex)
return false;
}
return true;
}
}