/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package org.drools.examples.sudoku

agenda-group "validate"

rule "terminate group"
salience -100
when
then
    System.out.println( "Validation complete." );
    drools.halt();
end

rule "duplicate in cell row"
when
    $c: Cell( $v: value != null ) 
    $cr: CellRow( cells contains $c )
    exists Cell( this != $c, value == $v, cellRow == $cr ) 
then
    System.out.println( "cell " + $c.toString() + " has a duplicate in row " + $cr.getNumber() );
end

rule "duplicate in cell col"
when
    $c: Cell( $v: value != null ) 
    $cc: CellCol( cells contains $c )
    exists Cell( this != $c, value == $v, cellCol == $cc ) 
then
    System.out.println( "cell " + $c.toString() + " has a duplicate in col " + $cc.getNumber() );
end

rule "duplicate in cell sqr"
when
    $c: Cell( $v: value != null ) 
    $cs: CellSqr( cells contains $c )
    exists Cell( this != $c, value == $v, cellSqr == $cs ) 
then
    System.out.println( "cell " + $c.toString() + " has duplicate in its square of nine." );
end
