/*
 * Copyright 2002, 2003, 2004, 2005 - <A href="http://www.koalog.com">Koalog</A>
 */
package com.koalog.jcs.examples;

import com.koalog.jcs.solver.SplitSolver;
import com.koalog.jcs.solver.SmallestDomainVariableHeuristic;
import com.koalog.jcs.solver.DecreasingOrderDomainHeuristic;

/**
 * A solver for the magic square problem.
 *
 @author Yan Georget
 */
public class MagicSquareSolver extends SplitSolver {
    //------------------------------------------------------------------------
    // CONSTRUCTORS
    //------------------------------------------------------------------------
    /**
     * Sole constructor.
     @param p a magic square problem
     */
    public MagicSquareSolver(MagicSquareProblem p) {
        super(p,
              new SmallestDomainVariableHeuristic(),
              new DecreasingOrderDomainHeuristic());
    }

    //------------------------------------------------------------------------
    // METHODS
    //------------------------------------------------------------------------
    /** @see com.koalog.jcs.solver.BacktrackSolver */
    public boolean choice() {
        if (choice(((MagicSquareProblemproblem).firstDiagonal)) {
            return true;
        }
        if (choice(((MagicSquareProblemproblem).secondDiagonal)) {
            return true;
        }
        return choice(((MagicSquareProblemproblem).elements);
    }
}