SlideShare a Scribd company logo
Learning Rule Based
Programming
Using Games
Classes
Account
long accountNo
int balance
CashFlow
Date date
int amount
AccountPeriod
Date start
Date end
CashFlow Example
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account()
cf : CashFlow( type == CREDIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )
then
acc.balance += cf.amount;
end
acc.balance += cf.amount
CashFlow Rule
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account()
cf : CashFlow( type == CREDIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )
then
acc.balance += cf.amount;
end
acc.balance += cf.amount
CashFlow Rule
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account()
cf : CashFlow( type == CREDIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )
then
acc.balance += cf.amount;
end
acc.balance += cf.amount
CashFlow Rule
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account()
cf : CashFlow( type == CREDIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )
then
acc.balance += cf.amount;
end
acc.balance += cf.amount
CashFlow Rule
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account()
cf : CashFlow( type == CREDIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )
then
acc.balance += cf.amount;
end
acc.balance += cf.amount
CashFlow Rule
rule "Increase balance for AccountPeriod Credits"

when

ap : AccountPeriod( )

acc : Account( )

cf : CashFlow( type == CashFlowType.CREDIT,

accountNo == acc.accountNo,

date >= ap.start && <= ap.end )

then

acc.balance = acc.balance + cf.amount;

end
rule "Decrease balance for AccountPeriod Debits"

when

ap : AccountPeriod( )

acc : Account( )

cf : CashFlow( type == CashFlowType.DEBIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )

then

acc.balance = acc.balance - cf.amount;

end
CashFlow
date amount type accountNo
12-Jan-12 100 CREDIT 1
2-Feb-12 200 DEBIT 1
18-May-12 50 CREDIT 1
9-Mar-12 75 CREDIT 1
AccountingPeriod
start end
01-JAN-2012 31-MAR-2012
Account
accountNo balance
1 0
CashFlow
date amount type accountNo
12-Jan-12 100 CREDIT 1
9-Mar-12 75 CREDIT 1
CashFlow
date amount type accountNo
2-Feb-12 200 DEBIT 1
Account
accountNo balance
1 -25
CashFlow Example
rule "Print blance for AccountPeriod" salience -50

when

ap : AccountPeriod()

acc : Account( )

then

System.out.println( "Account Number " + acc.accountNo
+ " balance " + acc.balance );

end
Agenda
1 increase balance
arbitrary2 decrease balance
3 increase balance
4 print balance
CashFlow Example
AccountingPeriod
start end
01-Apr-2012 30-JUN-2012
rule "Increase balance for AccountPeriod Credits"

when

ap : AccountPeriod( )

acc : Account( )

cf : CashFlow( type == CashFlowType.CREDIT,

accountNo == acc.accountNo,

date >= ap.start && <=
ap.end )

then

acc.balance = acc.balance + cf.amount;

end
rule "Decrease balance for AccountPeriod Debits"

when

ap : AccountPeriod( )

acc : Account( )

cf : CashFlow( type == CashFlowType.DEBIT,
accountNo == acc.accountNo,
date >= ap.start && <= ap.end )

then

acc.balance = acc.balance - cf.amount;

end
CashFlow
date amount type accountNo
12-Jan-12 100 CREDIT 1
2-Feb-12 200 DEBIT 1
18-May-12 50 CREDIT 1
9-Mar-12 75 CREDIT 1
Account
accountNo balance
1 0
CashFlow
date amount type accountNo
18-May-12 75 CREDIT 1
CashFlow
date amount type accountNo
Account
accountNo balance
1 25
CashFlow Example
Number Guess
Number Guess
public class Game {

private int biggest;

private int smallest;

private int guessCount;
public class Guess {

private int value;
public class GameRules {

private int maxRange;

private int allowedGuesses;
public class RandomNumber {

private int randomNumber;
public class NumberGuessMain {



public static void main(String[] args) {

KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();

final KieSession ksession = kc.newKieSession( "NumberGuessKS");



ksession.insert( new GameRules( 100, 5 ) );

ksession.insert( new RandomNumber() );

ksession.insert( new Game() );



ksession.fireAllRules();

}



}

public class Game {

private int biggest;

private int smallest;

private int guessCount;
public class Guess {

private int value;
public class GameRules {

private int maxRange;

private int allowedGuesses;
public class RandomNumber {

private int randomNumber;
<kbase name="NumberGuessKB" packages="org.drools.games.numberguess">

<ksession name="NumberGuessKS"/>

</kbase>
rule Main when

rules : GameRules( )

game : Game( guessCount < rules.allowedGuesses )

not Guess()

then

setFocus("Guess");

end

rule "Get user Guess" agenda-group "Guess" when

$r : RandomNumber()

rules : GameRules( )

game : Game( )

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 = game.guessCount + 1 }


int i = Integer.parseInt( br.readLine() );

insert( new Guess( i ) );

end
rule "Record the highest Guess" agenda-group "Guess" no-loop when

game : Game( )

r : RandomNumber()

guess : Guess( value > r.value)

then

modify ( game ) { biggest = guess.value };

retract( guess );

System.out.println( "Your guess was too high" );

end
rule "Record the highest Guess" agenda-group "Guess" no-loop when

game : Game( )

r : RandomNumber()

guess : Guess( value > r.value)

then

modify ( game ) { biggest = guess.value };

retract( guess );

System.out.println( "Your guess was too high" );

end
rule "Record the lowest Guess" agenda-group "Guess" when

game : Game( )

r : RandomNumber()

guess : Guess(value < r.value )

then

modify ( game ) { smallest = guess.value };

retract( guess );

System.out.println( "Your guess was too low" );

end
rule "Record the highest Guess" agenda-group "Guess" no-loop when

game : Game( )

r : RandomNumber()

guess : Guess( value > r.value)

then

modify ( game ) { biggest = guess.value };

retract( guess );

System.out.println( "Your guess was too high" );

end
rule "Record the lowest Guess" agenda-group "Guess" when

game : Game( )

r : RandomNumber()

guess : Guess(value < r.value )

then

modify ( game ) { smallest = guess.value };

retract( guess );

System.out.println( "Your guess was too low" );

end
rule "Guess correct" agenda-group "Guess" when

game : Game( )

r : RandomNumber()

guess : Guess( value == r.value)

then

System.out.println( "You guessed correctly" );

end

rule Main when

rules : GameRules( )

game : Game( guessCount < rules.allowedGuesses )

not Guess()

then

setFocus("Guess");

end

rule "No more Guesses" when

rules : GameRules( )

game : Game( guessCount == rules.allowedGuesses )

not Guess()

r : RandomNumber()

then

System.out.println( "You have no more guessesnThe correct guess was " + r.value );

end
Wumpus
Wumpus
Wumpus
• Performance measure
–gold: +1000, death: -1000
–-1 per step, -10 for using the arrow
• Environment
–Squares adjacent to wumpus are smelly
–Squares adjacent to pit are breezy
–Glitter if gold is in the same square
–Shooting kills wumpus if you are facing it
–Shooting uses up the only arrow
–Grabbing picks up gold if in same square
–Releasing drops the gold in same square
• Sensors: Stench, Breeze, Glitter, Bump, Scream
• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Wumpus
Adventures in Drools
Adventures
rooms = [ 

"basement" : new Room("basement"), 

"lounge" : new Room("lounge"),

"dining room” : new Room("dining room"),

“kitchen" : new Room("kitchen"), 

"ground floor hallway" : new Room("ground floor hallway"), 

"bedroom1" : new Room("bedroom1"),

"bedroom2" : new Room("bedroom2"),

“bathroom" : new Room("bathroom"),

"office" : new Room("office"),

"first floor hallway" : new Room("first floor hallway")

];
doors = [

"d1" : new Door( rooms[“kitchen", rooms["basement"] ),



"d2" : new Door( rooms["ground floor hallway"], rooms["lounge"]),

"d3" : new Door( rooms["ground floor hallway"], rooms["dining room"] ),

"d4" : new Door( rooms["ground floor hallway"], rooms["kitchen"]),

"d5" : new Door( rooms["ground floor hallway"], rooms[ "first floor hallway"] ), 



"d6" : new Door( rooms["first floor hallway"], rooms[ "bedroom1"] ),

"d7" : new Door( rooms["first floor hallway”], rooms[ "bedroom2"] ),

"d8" : new Door( rooms["first floor hallway"], rooms[ "bathroom"] ),

"d9" : new Door( rooms["first floor hallway”], rooms[ "office"] ) 

];

Adventures
characters = [ "hero" : new Character( "hero" ),
"monster" : new Character( "monster" ) ];
items = [
"umbrella" : new Item( "umbrella" ),
"desk" : new Item( "desk", false ),
"draw" : new Item( "draw", false ),
"envelop" : new Item( "envelop" ),
"key1" : new Key("basement key")
];
locations = [
"monster" : new Location( characters["monster"], rooms["basement"] ),
"hero" : new Location( characters["hero"], rooms["ground floor hallway"] ),
"umbrella" : new Location( items["umbrella"], rooms["lounge"] ),
"desk" : new Location( items["desk"], rooms["office"] ),
"draw" : new Location( items["draw"], items["desk"] ),
"envelop" : new Location( items["envelop"], items["draw"] ),
"key1" : new Location( items["key1"], items["envelop"] )
];
with(doors["d1"]){ lockStatus = LockStatus.LOCKED, key = items["key1"] };
Adventures
Adventures
Adventures
Adventures
Adventures
Adventures
Adventures
Adventures
Adventures
Adventures "desk" : new Location( items["desk"], rooms["office"] ),
"draw" : new Location( items["draw"], items["desk"] ),
"envelop" : new Location( items["envelop"], items["draw"] ),
"key1" : new Location( items["key1"], items["envelop"] )
Reasoning with Graphs
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
ksession.insert( new Location("Office", "House") );

ksession.insert( new Location("Kitchen", "House") );

ksession.insert( new Location("Knife", "Kitchen") );

ksession.insert( new Location("Cheese", "Kitchen") );

ksession.insert( new Location("Desk", "Office") );

ksession.insert( new Location("Chair", "Office") );

ksession.insert( new Location("Computer", "Desk") );

ksession.insert( new Location("Draw", "Desk") );
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go1"

when

String( this == "go1" )

isContainedIn("Office", "House"; )

then

System.out.println( "office is in the house" );

end
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go1"

when

String( this == "go1" )

isContainedIn("Office", "House"; )

then

System.out.println( "office is in the house" );

end
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go1"

when

String( this == "go1" )

isContainedIn("Office", "House"; )

then

System.out.println( "office is in the house" );

end
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
ksession.insert( "go1" );

ksession.fireAllRules();
---
go1
office is in the house
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go1"

when

String( this == "go1" )

isContainedIn("Office", "House"; )

then

System.out.println( "office is in the house" );

end
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
ksession.insert( "go1" );

ksession.fireAllRules();
---
go1
office is in the house
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
isContainedIn(x==Office, y==House)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go1"

when

String( this == "go1" )

isContainedIn("Office", "House"; )

then

System.out.println( "office is in the house" );

end
rule "go" salience 10

when

$s : String( )

then

System.out.println( $s );

end
ksession.insert( "go1" );

ksession.fireAllRules();
---
go1
office is in the house
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(x==Office, y==House)
isContainedIn(x==Office, y==House)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
isContainedIn(x==Draw, y==House)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(z==Office, y==House)
isContainedIn(x==Draw, y==House)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(z==Office, y==House)
isContainedIn(x==Draw, z==Office)
isContainedIn(x==Draw, y==House)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(z==Office, y==House)
isContainedIn(x==Draw, z==Office)
Location(z==Kitchen, y==House)
isContainedIn(x==Draw, z==Kitchen)
isContainedIn(x==Draw, y==House)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
isContainedIn(x==Draw, y==Office)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(z==Desk, y==Office)
isContainedIn(x==Draw, y==Office)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(z==Desk, y==Office)
isContainedIn(x==Draw, z==Desk)
isContainedIn(x==Draw, y==Office)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
isContainedIn(x==Draw, y==Desk)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go2"

when

String( this == "go2" )

isContainedIn("Draw", "House"; )

then

System.out.println( "Draw in the House" );

end
query isContainedIn( String x, String y )

Location( x, y; )

or

( Location( z, y; ) and isContainedIn( x, z; ) )

end
Location(x==Draw, y==Desk)
isContainedIn(x==Draw, y==Desk)
ksession.insert( "go2" );

ksession.fireAllRules();
---
go2
Draw in the House
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go3"

when

String( this == "go3" )

isContainedIn("Key", "Office"; )

then

System.out.println( "Key in the Office" );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go3"

when

String( this == "go3" )

isContainedIn("Key", "Office"; )

then

System.out.println( "Key in the Office" );

end
ksession.insert( "go3" );

ksession.fireAllRules();
---
go3
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go3"

when

String( this == "go3" )

isContainedIn("Key", "Office"; )

then

System.out.println( "Key in the Office" );

end
ksession.insert( "go3" );

ksession.fireAllRules();
---
go3
ksession.insert( new Location("Key", "Draw") );

ksession.fireAllRules();
---
Key in the Office
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go4"

when

String( this == "go4" )

isContainedIn(thing, "Office"; )

then

System.out.println( "thing " + thing + " is in the Office" );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go4"

when

String( this == "go4" )

isContainedIn(thing, "Office"; )

then

System.out.println( "thing " + thing + " is in the Office" );

end
Out Var
(unbound)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go4"

when

String( this == "go4" )

isContainedIn(thing, "Office"; )

then

System.out.println( "thing " + thing + " is in the Office" );

end
ksession.insert( "go4" );

ksession.fireAllRules();
---
go4
thing Key is in the Office
thing Computer is in the Office
thing Draw is in the Office
thing Desk is in the Office
thing Chair is in the Office
Out Var
(unbound)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go5"

when

String( this == "go5" )

isContainedIn(thing, location; )

then

System.out.println( "thing " + thing + " is in " + location );

end
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go5"

when

String( this == "go5" )

isContainedIn(thing, location; )

then

System.out.println( "thing " + thing + " is in " + location );

end
Out Var
(unbound)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go5"

when

String( this == "go5" )

isContainedIn(thing, location; )

then

System.out.println( "thing " + thing + " is in " + location );

end
Out Var
(unbound)
Out Var
(unbound)
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Backward Chaining
rule "go5"

when

String( this == "go5" )

isContainedIn(thing, location; )

then

System.out.println( "thing " + thing + " is in " + location );

end
ksession.insert( "go5" );

ksession.fireAllRules();
---
go5
thing Knife is in House
thing Cheese is in House
thing Key is in House
thing Computer is in House
thing Draw is in House
thing Desk is in House
thing Chair is in House
thing Key is in Office
thing Computer is in Office
thing Draw is in Office
thing Key is in Desk
thing Office is in House
Out Var
(unbound)
Out Var
(unbound)
thing Computer is in Desk
thing Knife is in Kitchen
thing Cheese is in Kitchen
thing Kitchen is in House
thing Key is in Draw
thing Draw is in Desk
thing Desk is in Office
thing Chair is in Office
House
Location("Office",
"House ")
Location("Kitchen",
"House")
Location("Desk",
"Office")
Location("Chair",
"Office")
Location("Computer",
"Desk")
Location("Draw",
"Desk")
Location("Knife",
"Kitchen")
Location("Cheese",
"Kitchen")
Location("Key",
"Draw")
Invaders
Init
Keys
Move Bullet
Draw
Invaders
Invaders
Invaders
Invaders
Invaders
Invaders

More Related Content

What's hot

Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Mark Proctor
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術名辰 洪
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationMark Proctor
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript名辰 洪
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teamscentralohioissa
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhDIVYA SINGH
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Astrails
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesJose Manuel Jurado Diaz
 
Python: the coolest is yet to come
Python: the coolest is yet to comePython: the coolest is yet to come
Python: the coolest is yet to comePablo Enfedaque
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]User1test
 
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
Lowering in C#: What really happens with your code?, from NDC Oslo 2019Lowering in C#: What really happens with your code?, from NDC Oslo 2019
Lowering in C#: What really happens with your code?, from NDC Oslo 2019David Wengier
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseSages
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012Amazon Web Services
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesDavid Wengier
 
Client-side Rendering with AngularJS
Client-side Rendering with AngularJSClient-side Rendering with AngularJS
Client-side Rendering with AngularJSDavid Lapsley
 

What's hot (20)

Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術
 
JBoss World 2011 - Drools
JBoss World 2011 - DroolsJBoss World 2011 - Drools
JBoss World 2011 - Drools
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentation
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teams
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
 
Java Se next Generetion
Java Se next GeneretionJava Se next Generetion
Java Se next Generetion
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best Practices
 
Epic South Disasters
Epic South DisastersEpic South Disasters
Epic South Disasters
 
Python: the coolest is yet to come
Python: the coolest is yet to comePython: the coolest is yet to come
Python: the coolest is yet to come
 
V8
V8V8
V8
 
Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]Adodb Scripts And Some Sample Scripts[1]
Adodb Scripts And Some Sample Scripts[1]
 
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
Lowering in C#: What really happens with your code?, from NDC Oslo 2019Lowering in C#: What really happens with your code?, from NDC Oslo 2019
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
 
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
 
A (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project FilesA (very) opinionated guide to MSBuild and Project Files
A (very) opinionated guide to MSBuild and Project Files
 
Client-side Rendering with AngularJS
Client-side Rendering with AngularJSClient-side Rendering with AngularJS
Client-side Rendering with AngularJS
 

Viewers also liked

Drools Happenings 7.0 - Devnation 2016
Drools Happenings 7.0 - Devnation 2016Drools Happenings 7.0 - Devnation 2016
Drools Happenings 7.0 - Devnation 2016Mark Proctor
 
Big Data, Analytics and Real Time Event Processing
Big Data, Analytics and Real Time Event Processing Big Data, Analytics and Real Time Event Processing
Big Data, Analytics and Real Time Event Processing WSO2
 
Desarrollo de un agente buscador inteligente de metadatos
Desarrollo de un agente buscador inteligente  de metadatosDesarrollo de un agente buscador inteligente  de metadatos
Desarrollo de un agente buscador inteligente de metadatosHugo Banda
 
Intelligent Business Processes
Intelligent Business ProcessesIntelligent Business Processes
Intelligent Business ProcessesSandy Kemsley
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep diveMario Fusco
 
Next-Generation BPM - How to create intelligent Business Processes thanks to ...
Next-Generation BPM - How to create intelligent Business Processes thanks to ...Next-Generation BPM - How to create intelligent Business Processes thanks to ...
Next-Generation BPM - How to create intelligent Business Processes thanks to ...Kai Wähner
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflowMark Proctor
 
Intelligent Capture and Digital Transformation
Intelligent Capture and Digital TransformationIntelligent Capture and Digital Transformation
Intelligent Capture and Digital TransformationSandy Kemsley
 
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...StampedeCon
 

Viewers also liked (10)

Drools Happenings 7.0 - Devnation 2016
Drools Happenings 7.0 - Devnation 2016Drools Happenings 7.0 - Devnation 2016
Drools Happenings 7.0 - Devnation 2016
 
Big Data, Analytics and Real Time Event Processing
Big Data, Analytics and Real Time Event Processing Big Data, Analytics and Real Time Event Processing
Big Data, Analytics and Real Time Event Processing
 
Desarrollo de un agente buscador inteligente de metadatos
Desarrollo de un agente buscador inteligente  de metadatosDesarrollo de un agente buscador inteligente  de metadatos
Desarrollo de un agente buscador inteligente de metadatos
 
The Future of Work
The Future of WorkThe Future of Work
The Future of Work
 
Intelligent Business Processes
Intelligent Business ProcessesIntelligent Business Processes
Intelligent Business Processes
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep dive
 
Next-Generation BPM - How to create intelligent Business Processes thanks to ...
Next-Generation BPM - How to create intelligent Business Processes thanks to ...Next-Generation BPM - How to create intelligent Business Processes thanks to ...
Next-Generation BPM - How to create intelligent Business Processes thanks to ...
 
rules, events and workflow
rules, events and workflowrules, events and workflow
rules, events and workflow
 
Intelligent Capture and Digital Transformation
Intelligent Capture and Digital TransformationIntelligent Capture and Digital Transformation
Intelligent Capture and Digital Transformation
 
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...
Real Time Event Processing and In-­memory analysis of Big Data - StampedeCon ...
 

Similar to Learning Rule Based Programming using Games @DecisionCamp 2016

Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Geoffrey De Smet
 
Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Fred Heath
 
main.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfmain.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfarwholesalelors
 
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Andrés Viedma Peláez
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
redis überall
redis überallredis überall
redis überallzucaritask
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionIban Martinez
 
Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docxajoy21
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_AltHiroshi Ono
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfdeepakangel
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfizabellejaeden956
 

Similar to Learning Rule Based Programming using Games @DecisionCamp 2016 (20)

Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)Hybrid rule engines (rulesfest 2010)
Hybrid rule engines (rulesfest 2010)
 
Clojure workshop
Clojure workshopClojure workshop
Clojure workshop
 
Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015
 
project
projectproject
project
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
main.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfmain.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdf
 
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
CQRS and Event Sourcing
CQRS and Event SourcingCQRS and Event Sourcing
CQRS and Event Sourcing
 
redis überall
redis überallredis überall
redis überall
 
Dalembert
DalembertDalembert
Dalembert
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introduction
 
Write a banking program that simulates the operation of your local ba.docx
 Write a banking program that simulates the operation of your local ba.docx Write a banking program that simulates the operation of your local ba.docx
Write a banking program that simulates the operation of your local ba.docx
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
PyCon2009_AI_Alt
PyCon2009_AI_AltPyCon2009_AI_Alt
PyCon2009_AI_Alt
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
You are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdfYou are not setting any values for those variables(name, ID, interes.pdf
You are not setting any values for those variables(name, ID, interes.pdf
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
 

More from Mark Proctor

Rule Modularity and Execution Control
Rule Modularity and Execution ControlRule Modularity and Execution Control
Rule Modularity and Execution ControlMark Proctor
 
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...Mark Proctor
 
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)Mark Proctor
 
RuleML2015 : Hybrid Relational and Graph Reasoning
RuleML2015 : Hybrid Relational and Graph Reasoning RuleML2015 : Hybrid Relational and Graph Reasoning
RuleML2015 : Hybrid Relational and Graph Reasoning Mark Proctor
 
Red Hat Summit 2015 : Drools, jBPM and UberFire Roadmaps
Red Hat Summit 2015 : Drools, jBPM and UberFire RoadmapsRed Hat Summit 2015 : Drools, jBPM and UberFire Roadmaps
Red Hat Summit 2015 : Drools, jBPM and UberFire RoadmapsMark Proctor
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyMark Proctor
 
Drools and jBPM 6 Overview
Drools and jBPM 6 OverviewDrools and jBPM 6 Overview
Drools and jBPM 6 OverviewMark Proctor
 
UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)Mark Proctor
 
Property Reactive RuleML 2013
Property Reactive RuleML 2013Property Reactive RuleML 2013
Property Reactive RuleML 2013Mark Proctor
 
Reactive Transitive Closures with Drools (Backward Chaining)
Reactive Transitive Closures with Drools (Backward Chaining)Reactive Transitive Closures with Drools (Backward Chaining)
Reactive Transitive Closures with Drools (Backward Chaining)Mark Proctor
 
Drools 6.0 (JudCon 2013)
Drools 6.0 (JudCon 2013)Drools 6.0 (JudCon 2013)
Drools 6.0 (JudCon 2013)Mark Proctor
 
UberFire Quick Intro and Overview (early beta Jul 2013)
UberFire Quick Intro and Overview (early beta Jul 2013)UberFire Quick Intro and Overview (early beta Jul 2013)
UberFire Quick Intro and Overview (early beta Jul 2013)Mark Proctor
 
UberFire (JudCon 2013)
UberFire (JudCon 2013)UberFire (JudCon 2013)
UberFire (JudCon 2013)Mark Proctor
 
Drools 6.0 (Red Hat Summit 2013)
Drools 6.0 (Red Hat Summit 2013)Drools 6.0 (Red Hat Summit 2013)
Drools 6.0 (Red Hat Summit 2013)Mark Proctor
 
Games development with the Drools rule engine
Games development with the Drools rule engineGames development with the Drools rule engine
Games development with the Drools rule engineMark Proctor
 
Drools & jBPM future roadmap talk
Drools & jBPM future roadmap talkDrools & jBPM future roadmap talk
Drools & jBPM future roadmap talkMark Proctor
 
Drools @ IntelliFest 2012
Drools @ IntelliFest 2012Drools @ IntelliFest 2012
Drools @ IntelliFest 2012Mark Proctor
 
JUDCon India 2012 Drools Fusion
JUDCon  India 2012 Drools FusionJUDCon  India 2012 Drools Fusion
JUDCon India 2012 Drools FusionMark Proctor
 
JUDCon India 2012 Drools Expert
JUDCon  India 2012 Drools ExpertJUDCon  India 2012 Drools Expert
JUDCon India 2012 Drools ExpertMark Proctor
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info SheetMark Proctor
 

More from Mark Proctor (20)

Rule Modularity and Execution Control
Rule Modularity and Execution ControlRule Modularity and Execution Control
Rule Modularity and Execution Control
 
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...
Reducing the Cost of the Linear Growth Effect using Adaptive Rules with Unlin...
 
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)
Drools, jBPM and OptaPlanner (NYC and DC Sept 2017 - Keynote Talk Video)
 
RuleML2015 : Hybrid Relational and Graph Reasoning
RuleML2015 : Hybrid Relational and Graph Reasoning RuleML2015 : Hybrid Relational and Graph Reasoning
RuleML2015 : Hybrid Relational and Graph Reasoning
 
Red Hat Summit 2015 : Drools, jBPM and UberFire Roadmaps
Red Hat Summit 2015 : Drools, jBPM and UberFire RoadmapsRed Hat Summit 2015 : Drools, jBPM and UberFire Roadmaps
Red Hat Summit 2015 : Drools, jBPM and UberFire Roadmaps
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
 
Drools and jBPM 6 Overview
Drools and jBPM 6 OverviewDrools and jBPM 6 Overview
Drools and jBPM 6 Overview
 
UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)
 
Property Reactive RuleML 2013
Property Reactive RuleML 2013Property Reactive RuleML 2013
Property Reactive RuleML 2013
 
Reactive Transitive Closures with Drools (Backward Chaining)
Reactive Transitive Closures with Drools (Backward Chaining)Reactive Transitive Closures with Drools (Backward Chaining)
Reactive Transitive Closures with Drools (Backward Chaining)
 
Drools 6.0 (JudCon 2013)
Drools 6.0 (JudCon 2013)Drools 6.0 (JudCon 2013)
Drools 6.0 (JudCon 2013)
 
UberFire Quick Intro and Overview (early beta Jul 2013)
UberFire Quick Intro and Overview (early beta Jul 2013)UberFire Quick Intro and Overview (early beta Jul 2013)
UberFire Quick Intro and Overview (early beta Jul 2013)
 
UberFire (JudCon 2013)
UberFire (JudCon 2013)UberFire (JudCon 2013)
UberFire (JudCon 2013)
 
Drools 6.0 (Red Hat Summit 2013)
Drools 6.0 (Red Hat Summit 2013)Drools 6.0 (Red Hat Summit 2013)
Drools 6.0 (Red Hat Summit 2013)
 
Games development with the Drools rule engine
Games development with the Drools rule engineGames development with the Drools rule engine
Games development with the Drools rule engine
 
Drools & jBPM future roadmap talk
Drools & jBPM future roadmap talkDrools & jBPM future roadmap talk
Drools & jBPM future roadmap talk
 
Drools @ IntelliFest 2012
Drools @ IntelliFest 2012Drools @ IntelliFest 2012
Drools @ IntelliFest 2012
 
JUDCon India 2012 Drools Fusion
JUDCon  India 2012 Drools FusionJUDCon  India 2012 Drools Fusion
JUDCon India 2012 Drools Fusion
 
JUDCon India 2012 Drools Expert
JUDCon  India 2012 Drools ExpertJUDCon  India 2012 Drools Expert
JUDCon India 2012 Drools Expert
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info Sheet
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...Sri Ambati
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

Learning Rule Based Programming using Games @DecisionCamp 2016

  • 2. Classes Account long accountNo int balance CashFlow Date date int amount AccountPeriod Date start Date end CashFlow Example
  • 3. select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end acc.balance += cf.amount CashFlow Rule
  • 4. select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end acc.balance += cf.amount CashFlow Rule
  • 5. select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end acc.balance += cf.amount CashFlow Rule
  • 6. select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end acc.balance += cf.amount CashFlow Rule
  • 7. select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end acc.balance += cf.amount CashFlow Rule
  • 8. rule "Increase balance for AccountPeriod Credits"
 when
 ap : AccountPeriod( )
 acc : Account( )
 cf : CashFlow( type == CashFlowType.CREDIT,
 accountNo == acc.accountNo,
 date >= ap.start && <= ap.end )
 then
 acc.balance = acc.balance + cf.amount;
 end rule "Decrease balance for AccountPeriod Debits"
 when
 ap : AccountPeriod( )
 acc : Account( )
 cf : CashFlow( type == CashFlowType.DEBIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end )
 then
 acc.balance = acc.balance - cf.amount;
 end CashFlow date amount type accountNo 12-Jan-12 100 CREDIT 1 2-Feb-12 200 DEBIT 1 18-May-12 50 CREDIT 1 9-Mar-12 75 CREDIT 1 AccountingPeriod start end 01-JAN-2012 31-MAR-2012 Account accountNo balance 1 0 CashFlow date amount type accountNo 12-Jan-12 100 CREDIT 1 9-Mar-12 75 CREDIT 1 CashFlow date amount type accountNo 2-Feb-12 200 DEBIT 1 Account accountNo balance 1 -25 CashFlow Example
  • 9. rule "Print blance for AccountPeriod" salience -50
 when
 ap : AccountPeriod()
 acc : Account( )
 then
 System.out.println( "Account Number " + acc.accountNo + " balance " + acc.balance );
 end Agenda 1 increase balance arbitrary2 decrease balance 3 increase balance 4 print balance CashFlow Example
  • 10. AccountingPeriod start end 01-Apr-2012 30-JUN-2012 rule "Increase balance for AccountPeriod Credits"
 when
 ap : AccountPeriod( )
 acc : Account( )
 cf : CashFlow( type == CashFlowType.CREDIT,
 accountNo == acc.accountNo,
 date >= ap.start && <= ap.end )
 then
 acc.balance = acc.balance + cf.amount;
 end rule "Decrease balance for AccountPeriod Debits"
 when
 ap : AccountPeriod( )
 acc : Account( )
 cf : CashFlow( type == CashFlowType.DEBIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end )
 then
 acc.balance = acc.balance - cf.amount;
 end CashFlow date amount type accountNo 12-Jan-12 100 CREDIT 1 2-Feb-12 200 DEBIT 1 18-May-12 50 CREDIT 1 9-Mar-12 75 CREDIT 1 Account accountNo balance 1 0 CashFlow date amount type accountNo 18-May-12 75 CREDIT 1 CashFlow date amount type accountNo Account accountNo balance 1 25 CashFlow Example
  • 13. public class Game {
 private int biggest;
 private int smallest;
 private int guessCount; public class Guess {
 private int value; public class GameRules {
 private int maxRange;
 private int allowedGuesses; public class RandomNumber {
 private int randomNumber;
  • 14. public class NumberGuessMain {
 
 public static void main(String[] args) {
 KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
 final KieSession ksession = kc.newKieSession( "NumberGuessKS");
 
 ksession.insert( new GameRules( 100, 5 ) );
 ksession.insert( new RandomNumber() );
 ksession.insert( new Game() );
 
 ksession.fireAllRules();
 }
 
 }
 public class Game {
 private int biggest;
 private int smallest;
 private int guessCount; public class Guess {
 private int value; public class GameRules {
 private int maxRange;
 private int allowedGuesses; public class RandomNumber {
 private int randomNumber; <kbase name="NumberGuessKB" packages="org.drools.games.numberguess">
 <ksession name="NumberGuessKS"/>
 </kbase>
  • 15. rule Main when
 rules : GameRules( )
 game : Game( guessCount < rules.allowedGuesses )
 not Guess()
 then
 setFocus("Guess");
 end
 rule "Get user Guess" agenda-group "Guess" when
 $r : RandomNumber()
 rules : GameRules( )
 game : Game( )
 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 = game.guessCount + 1 } 
 int i = Integer.parseInt( br.readLine() );
 insert( new Guess( i ) );
 end
  • 16. rule "Record the highest Guess" agenda-group "Guess" no-loop when
 game : Game( )
 r : RandomNumber()
 guess : Guess( value > r.value)
 then
 modify ( game ) { biggest = guess.value };
 retract( guess );
 System.out.println( "Your guess was too high" );
 end
  • 17. rule "Record the highest Guess" agenda-group "Guess" no-loop when
 game : Game( )
 r : RandomNumber()
 guess : Guess( value > r.value)
 then
 modify ( game ) { biggest = guess.value };
 retract( guess );
 System.out.println( "Your guess was too high" );
 end rule "Record the lowest Guess" agenda-group "Guess" when
 game : Game( )
 r : RandomNumber()
 guess : Guess(value < r.value )
 then
 modify ( game ) { smallest = guess.value };
 retract( guess );
 System.out.println( "Your guess was too low" );
 end
  • 18. rule "Record the highest Guess" agenda-group "Guess" no-loop when
 game : Game( )
 r : RandomNumber()
 guess : Guess( value > r.value)
 then
 modify ( game ) { biggest = guess.value };
 retract( guess );
 System.out.println( "Your guess was too high" );
 end rule "Record the lowest Guess" agenda-group "Guess" when
 game : Game( )
 r : RandomNumber()
 guess : Guess(value < r.value )
 then
 modify ( game ) { smallest = guess.value };
 retract( guess );
 System.out.println( "Your guess was too low" );
 end rule "Guess correct" agenda-group "Guess" when
 game : Game( )
 r : RandomNumber()
 guess : Guess( value == r.value)
 then
 System.out.println( "You guessed correctly" );
 end

  • 19. rule Main when
 rules : GameRules( )
 game : Game( guessCount < rules.allowedGuesses )
 not Guess()
 then
 setFocus("Guess");
 end
 rule "No more Guesses" when
 rules : GameRules( )
 game : Game( guessCount == rules.allowedGuesses )
 not Guess()
 r : RandomNumber()
 then
 System.out.println( "You have no more guessesnThe correct guess was " + r.value );
 end
  • 22. Wumpus • Performance measure –gold: +1000, death: -1000 –-1 per step, -10 for using the arrow • Environment –Squares adjacent to wumpus are smelly –Squares adjacent to pit are breezy –Glitter if gold is in the same square –Shooting kills wumpus if you are facing it –Shooting uses up the only arrow –Grabbing picks up gold if in same square –Releasing drops the gold in same square • Sensors: Stench, Breeze, Glitter, Bump, Scream • Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
  • 34. Adventures rooms = [ 
 "basement" : new Room("basement"), 
 "lounge" : new Room("lounge"),
 "dining room” : new Room("dining room"),
 “kitchen" : new Room("kitchen"), 
 "ground floor hallway" : new Room("ground floor hallway"), 
 "bedroom1" : new Room("bedroom1"),
 "bedroom2" : new Room("bedroom2"),
 “bathroom" : new Room("bathroom"),
 "office" : new Room("office"),
 "first floor hallway" : new Room("first floor hallway")
 ]; doors = [
 "d1" : new Door( rooms[“kitchen", rooms["basement"] ),
 
 "d2" : new Door( rooms["ground floor hallway"], rooms["lounge"]),
 "d3" : new Door( rooms["ground floor hallway"], rooms["dining room"] ),
 "d4" : new Door( rooms["ground floor hallway"], rooms["kitchen"]),
 "d5" : new Door( rooms["ground floor hallway"], rooms[ "first floor hallway"] ), 
 
 "d6" : new Door( rooms["first floor hallway"], rooms[ "bedroom1"] ),
 "d7" : new Door( rooms["first floor hallway”], rooms[ "bedroom2"] ),
 "d8" : new Door( rooms["first floor hallway"], rooms[ "bathroom"] ),
 "d9" : new Door( rooms["first floor hallway”], rooms[ "office"] ) 
 ];

  • 35. Adventures characters = [ "hero" : new Character( "hero" ), "monster" : new Character( "monster" ) ]; items = [ "umbrella" : new Item( "umbrella" ), "desk" : new Item( "desk", false ), "draw" : new Item( "draw", false ), "envelop" : new Item( "envelop" ), "key1" : new Key("basement key") ]; locations = [ "monster" : new Location( characters["monster"], rooms["basement"] ), "hero" : new Location( characters["hero"], rooms["ground floor hallway"] ), "umbrella" : new Location( items["umbrella"], rooms["lounge"] ), "desk" : new Location( items["desk"], rooms["office"] ), "draw" : new Location( items["draw"], items["desk"] ), "envelop" : new Location( items["envelop"], items["draw"] ), "key1" : new Location( items["key1"], items["envelop"] ) ]; with(doors["d1"]){ lockStatus = LockStatus.LOCKED, key = items["key1"] };
  • 45. Adventures "desk" : new Location( items["desk"], rooms["office"] ), "draw" : new Location( items["draw"], items["desk"] ), "envelop" : new Location( items["envelop"], items["draw"] ), "key1" : new Location( items["key1"], items["envelop"] )
  • 46. Reasoning with Graphs House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 47. Backward Chaining query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 48. Backward Chaining ksession.insert( new Location("Office", "House") );
 ksession.insert( new Location("Kitchen", "House") );
 ksession.insert( new Location("Knife", "Kitchen") );
 ksession.insert( new Location("Cheese", "Kitchen") );
 ksession.insert( new Location("Desk", "Office") );
 ksession.insert( new Location("Chair", "Office") );
 ksession.insert( new Location("Computer", "Desk") );
 ksession.insert( new Location("Draw", "Desk") ); House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 49. Backward Chaining rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 50. Backward Chaining rule "go1"
 when
 String( this == "go1" )
 isContainedIn("Office", "House"; )
 then
 System.out.println( "office is in the house" );
 end rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 51. Backward Chaining rule "go1"
 when
 String( this == "go1" )
 isContainedIn("Office", "House"; )
 then
 System.out.println( "office is in the house" );
 end rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 52. Backward Chaining rule "go1"
 when
 String( this == "go1" )
 isContainedIn("Office", "House"; )
 then
 System.out.println( "office is in the house" );
 end rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end ksession.insert( "go1" );
 ksession.fireAllRules(); --- go1 office is in the house query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 53. Backward Chaining rule "go1"
 when
 String( this == "go1" )
 isContainedIn("Office", "House"; )
 then
 System.out.println( "office is in the house" );
 end rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end ksession.insert( "go1" );
 ksession.fireAllRules(); --- go1 office is in the house query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end isContainedIn(x==Office, y==House) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 54. Backward Chaining rule "go1"
 when
 String( this == "go1" )
 isContainedIn("Office", "House"; )
 then
 System.out.println( "office is in the house" );
 end rule "go" salience 10
 when
 $s : String( )
 then
 System.out.println( $s );
 end ksession.insert( "go1" );
 ksession.fireAllRules(); --- go1 office is in the house query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(x==Office, y==House) isContainedIn(x==Office, y==House) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 55. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 56. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 57. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 58. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end isContainedIn(x==Draw, y==House) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 59. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(z==Office, y==House) isContainedIn(x==Draw, y==House) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 60. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(z==Office, y==House) isContainedIn(x==Draw, z==Office) isContainedIn(x==Draw, y==House) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 61. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(z==Office, y==House) isContainedIn(x==Draw, z==Office) Location(z==Kitchen, y==House) isContainedIn(x==Draw, z==Kitchen) isContainedIn(x==Draw, y==House) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 62. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end isContainedIn(x==Draw, y==Office) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 63. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(z==Desk, y==Office) isContainedIn(x==Draw, y==Office) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 64. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(z==Desk, y==Office) isContainedIn(x==Draw, z==Desk) isContainedIn(x==Draw, y==Office) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 65. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end isContainedIn(x==Draw, y==Desk) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 66. Backward Chaining rule "go2"
 when
 String( this == "go2" )
 isContainedIn("Draw", "House"; )
 then
 System.out.println( "Draw in the House" );
 end query isContainedIn( String x, String y )
 Location( x, y; )
 or
 ( Location( z, y; ) and isContainedIn( x, z; ) )
 end Location(x==Draw, y==Desk) isContainedIn(x==Draw, y==Desk) ksession.insert( "go2" );
 ksession.fireAllRules(); --- go2 Draw in the House House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 67. Backward Chaining rule "go3"
 when
 String( this == "go3" )
 isContainedIn("Key", "Office"; )
 then
 System.out.println( "Key in the Office" );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 68. Backward Chaining rule "go3"
 when
 String( this == "go3" )
 isContainedIn("Key", "Office"; )
 then
 System.out.println( "Key in the Office" );
 end ksession.insert( "go3" );
 ksession.fireAllRules(); --- go3 House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 69. Backward Chaining rule "go3"
 when
 String( this == "go3" )
 isContainedIn("Key", "Office"; )
 then
 System.out.println( "Key in the Office" );
 end ksession.insert( "go3" );
 ksession.fireAllRules(); --- go3 ksession.insert( new Location("Key", "Draw") );
 ksession.fireAllRules(); --- Key in the Office House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 70. Backward Chaining rule "go4"
 when
 String( this == "go4" )
 isContainedIn(thing, "Office"; )
 then
 System.out.println( "thing " + thing + " is in the Office" );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 71. Backward Chaining rule "go4"
 when
 String( this == "go4" )
 isContainedIn(thing, "Office"; )
 then
 System.out.println( "thing " + thing + " is in the Office" );
 end Out Var (unbound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 72. Backward Chaining rule "go4"
 when
 String( this == "go4" )
 isContainedIn(thing, "Office"; )
 then
 System.out.println( "thing " + thing + " is in the Office" );
 end ksession.insert( "go4" );
 ksession.fireAllRules(); --- go4 thing Key is in the Office thing Computer is in the Office thing Draw is in the Office thing Desk is in the Office thing Chair is in the Office Out Var (unbound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 73. Backward Chaining rule "go5"
 when
 String( this == "go5" )
 isContainedIn(thing, location; )
 then
 System.out.println( "thing " + thing + " is in " + location );
 end House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 74. Backward Chaining rule "go5"
 when
 String( this == "go5" )
 isContainedIn(thing, location; )
 then
 System.out.println( "thing " + thing + " is in " + location );
 end Out Var (unbound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 75. Backward Chaining rule "go5"
 when
 String( this == "go5" )
 isContainedIn(thing, location; )
 then
 System.out.println( "thing " + thing + " is in " + location );
 end Out Var (unbound) Out Var (unbound) House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 76. Backward Chaining rule "go5"
 when
 String( this == "go5" )
 isContainedIn(thing, location; )
 then
 System.out.println( "thing " + thing + " is in " + location );
 end ksession.insert( "go5" );
 ksession.fireAllRules(); --- go5 thing Knife is in House thing Cheese is in House thing Key is in House thing Computer is in House thing Draw is in House thing Desk is in House thing Chair is in House thing Key is in Office thing Computer is in Office thing Draw is in Office thing Key is in Desk thing Office is in House Out Var (unbound) Out Var (unbound) thing Computer is in Desk thing Knife is in Kitchen thing Cheese is in Kitchen thing Kitchen is in House thing Key is in Draw thing Draw is in Desk thing Desk is in Office thing Chair is in Office House Location("Office", "House ") Location("Kitchen", "House") Location("Desk", "Office") Location("Chair", "Office") Location("Computer", "Desk") Location("Draw", "Desk") Location("Knife", "Kitchen") Location("Cheese", "Kitchen") Location("Key", "Draw")
  • 77.