package sudoku;

public class ContrainteBloc implements Contrainte {
    @Override
    public boolean estRespectee(Grille grille, Case c) {
        int blocSize = (int) Math.sqrt(grille.getTaille());
        int startRow = (c.getLigne() / blocSize) * blocSize;
        int startCol = (c.getColonne() / blocSize) * blocSize;
        Symbole symbole = c.getSymbole();
        
        for (int i = 0; i < blocSize; i++) {
            for (int j = 0; j < blocSize; j++) {
                Case currentCase = grille.getCase(startRow + i, startCol + j);
                if (currentCase != c && currentCase.getSymbole() != null && currentCase.getSymbole().equals(symbole)) {
                    return false;
                }
            }
        }
        return true;
    }
}