org.drools.examples.NumberGuess.drl Maven / Gradle / Ivy
The newest version!
package org.drools.examples
dialect "mvel"
import org.drools.examples.NumberGuessExample.RandomNumber
import org.drools.examples.NumberGuessExample.Guess
import org.drools.examples.NumberGuessExample.Game
import org.drools.examples.NumberGuessExample.GameRules
import java.io.InputStreamReader;
import java.io.BufferedReader;
rule "Get user Guess"
ruleflow-group "Guess"
no-loop
when
$r : RandomNumber()
rules : GameRules( allowed : allowedGuesses )
game : Game( guessCount < allowed )
not ( Guess() )
then
System.out.println( "You have " + ( rules.allowedGuesses - game.guessCount ) + " out of " + rules.allowedGuesses + " guesses left.\nPlease enter your guess from 0 to " + rules.maxRange );
br = new BufferedReader( new InputStreamReader( System.in ) );
modify ( game ) { guessCount += 1 }
i = br.readLine();
insert( new Guess( i ) );
end
rule "Record the biggest Guess"
ruleflow-group "Guess"
no-loop
when
game : Game( biggestGuess : biggest )
Guess( $value : value > biggestGuess )
then
modify ( game ) { biggest = $value };
end
rule "Record the smallest Guess"
ruleflow-group "Guess"
no-loop
when
game : Game( smallestGuess : smallest )
Guess( $value : value < smallestGuess )
then
modify ( game ) { smallest = $value };
end
rule "Guess incorrect, retract Guess"
ruleflow-group "Guess incorrect"
when
guess : Guess()
then
retract( guess );
end
rule "No more Guesses notification"
ruleflow-group "No more Guesses"
when
r : RandomNumber()
game : Game( )
then
System.out.println( "\nYou have no more guesses\nThe correct guess was " + r.value );
System.out.println( "Your smallest guess was " + game.smallest + "\nYour biggest guess was " + game.biggest );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy