This rule fires twice although there is only one matching case. I use Drools 6.5.0. Final. Looking at the log, it takes $card2 as $card1 and vice versa in the second round.
rule "Rule1"
salience 1
when
$card1 : (used == false)
$card2 : (used == false, number = $card1.number)
exists Hand(name == name1)
exists Hand(name == name2 || name == name3)
not Hand(name == name4)
then
$card1.setUsed(true); $card2.setUsed(true);
insert(new Hand(name1, $card1, $card2));
end
First of all, your rule looks malformed to me. The 2 first patterns are missing their types and there are variables (i.e. name1
) that don't come from anywhere.
Second, remember that the LHS of the rules in Drools works kind of like an SQL statement. If you don't specify any relationship between your patterns, the cartesian product of them will be used.
Hope it helps