package sudoku;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class ContrainteCasePartagee implements Contrainte {
    private Set<Case> casesLiees;

    public ContrainteCasePartagee(Collection<Case> cases) {
        this.casesLiees = new HashSet<>(cases);
    }

    @Override
    public boolean estRespectee(Grille grille, Case caseActuelle) {
        if (!casesLiees.contains(caseActuelle))
            return true;

        Symbole reference = null;
        for (Case c : casesLiees) {
            if (c.getSymbole() == null)
                continue;
            if (reference == null) {
                reference = c.getSymbole();
            } else if (!c.getSymbole().equals(reference)) {
                return false;
            }
        }
        return true;
    }
}