DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400 Tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400 Tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ B T

⟦58d75cb11⟧ TextFile

    Length: 39690 (0x9b0a)
    Types: TextFile
    Names: »BANANAS2_ADA«

Derivation

└─⟦a7d1ea751⟧ Bits:30000550 8mm tape, Rational 1000, !users!projects 94_04_11
    └─ ⟦129cab021⟧ »DATA« 
        └─⟦this⟧ 
└─⟦f64eaa120⟧ Bits:30000752 8mm tape, Rational 1000, !projects 93 02 16
    └─ ⟦6f12a12be⟧ »DATA« 
        └─⟦this⟧ 
└─⟦2f6cfab89⟧ Bits:30000547 8mm tape, Rational 1000, !projects 94-01-04
    └─ ⟦d65440be7⟧ »DATA« 
        └─⟦this⟧ 

TextFile

with expertSystem ; use expertSystem;
with monkeyObject ; use monkeyObject;
with monkey, physicalObject, goal;

procedure bananas2 is

   package monkeyAndBananas is
      procedure find_the_bananas;
   end monkeyAndBananas;

   package body monkeyAndBananas is

      function as_name(str : string) return physical_object is
         the_name : physical_object;
         ln       : integer := 1;
      begin
         if str'LENGTH > maxLengthName then
            ln := maxLengthName;
         else
            ln := str'LENGTH;
         end if;
         the_name(1..ln) := str(1..ln);
         ln := ln + 1;
         while ln <= maxLengthName loop
            the_name(ln) := ' ';
            ln := ln + 1;
         end loop;
         return the_name;
      end as_name;

      function active_goal(a_goal : reference)  return boolean is
      begin
         return
            goal.status(a_goal) = active;
      end;
      function find_active is new collection.findOne(active_goal);

      function active_is_on(a_goal : reference) return boolean is
      begin
         return
            goal.status(a_goal) = active	and then
	    goal.goal_type(a_goal) = is_on;
      end;

      function active_holds(a_goal : reference) return boolean is
      begin
         return
            goal.status(a_goal) = active	and then
	    goal.goal_type(a_goal) = holds;
      end;

      function active_is_at(a_goal : reference) return boolean is
      begin
         return
            goal.status(a_goal) = active	and then
	    goal.goal_type(a_goal) = is_at;
      end;
-----------------------------------------------------------------------------
--          RULES                         context_on                       --
-----------------------------------------------------------------------------

      function match_1(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            goal.object_name(a_goal) = floor		and then
            monkey.is_on(a_monkey) /= floor;
      end;
      function rule_1 is new tupleCollection.join2(match_1);

      function on_floor_C 		return tupleCollection.object is
      begin
         return 
         rule_1(monkey.instances,goal.instances,ANY);
      end;

      procedure on_floor_A (MG : tuple.object) is
	 a_monkey, a_goal : reference;
      begin        
         a_monkey := tuple.first(MG);       
         a_goal   := tuple.second(MG);
         monkey.modify_is_on(a_monkey, floor);
         goal.modify_status(a_goal, satisfied);
         put_line("Jump onto the floor");
      end;

      function match_2(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            goal.object_name(a_goal) = floor		and then
            monkey.is_on(a_monkey) = floor;
      end;
      function rule_2 is new tupleCollection.join2(match_2);         

      function on_floor_satisfied_C	return tupleCollection.object is
      begin
         return 
         rule_2(monkey.instances,goal.instances,ANY);
      end;

      procedure on_floor_satisfied_A (MG : tuple.object) is
         a_goal : reference;
      begin
         a_goal := tuple.second(MG);
         goal.modify_status(a_goal, satisfied);
         put_line("Monkey is already on floor");
      end;

      function match_3(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
            physicalObject.is_on(an_object) = floor	and then
            monkey.is_at(a_monkey) = 
               physicalObject.is_at(an_object)		and then
            monkey.holds(a_monkey) = nil		and then
            monkey.is_on(a_monkey) /= goal.object_name(a_goal);
      end;
      function rule_3 is new tupleCollection.join3(match_3);         
     
      function on_physical_object_C	return tupleCollection.object is
      begin
         return 
         rule_3(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure on_physical_object_A (MGO : tuple.object) is
	 a_monkey, a_goal : reference;
      begin
         a_monkey := tuple.first(MGO);
         a_goal   := tuple.second(MGO);
         monkey.modify_is_on(a_monkey, goal.object_name(a_goal));
         goal.modify_status(a_goal, satisfied);
         put("Climb onto ");
         put_line(goal.object_name(a_goal));
      end;

      function match_4(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
            monkey.is_at(a_monkey) = 
               physicalObject.is_at(an_object)		and then
	    monkey.holds(a_monkey) /= nil;
      end;
      function rule_4 is new tupleCollection.join3(match_4);         

      function on_physical_object_holds_C return tupleCollection.object is
      begin
         return
         rule_4(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure on_physical_object_holds_A (MGO : tuple.object) is
      begin
         goal.make(active, holds, nil, (1,1));
--         put_line("make subgoal on_physical_object_holds");
      end;

      function match_5(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            physicalObject.name(an_object) = 
	       goal.object_name(a_goal)			and then
	    physicalObject.is_on(an_object) = floor  	and then
	    monkey.is_at(a_monkey) /= physicalObject.is_at(an_object);
      end;
      function rule_5 is new tupleCollection.join3(match_5);         

      function on_physical_object_at_monkey_C return tupleCollection.object is
      begin
         return
         rule_5(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure on_physical_object_at_monkey_A (MGO : tuple.object) is
	 an_object : reference;
      begin
         an_object := tuple.third(MGO);
         goal.make(active, is_at, nil,
                   physicalObject.is_at(an_object));
--         put_line("make subgoal on_physical_object_at_monkey");
      end;

      function match_6(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_on(a_goal)			and then
            physicalObject.name(an_object) = 
    	       goal.object_name(a_goal)			and then
	    physicalObject.is_on(an_object) = floor  	and then
	    monkey.is_at(a_monkey) = 
	       physicalObject.is_at(an_object)		and then
	    monkey.is_on(a_monkey) = goal.object_name(a_goal);
      end;
      function rule_6 is new tupleCollection.join3(match_6);         

      function on_physical_object_satisfied_C return tupleCollection.object is
      begin
         return
         rule_6(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure on_physical_object_satisfied_A (MGO : tuple.object) is
	 a_goal    : reference;
      begin
         a_goal := tuple.second(MGO);
         goal.modify_status(a_goal, satisfied);
         put("Monkey is already on ");
         put_line(goal.object_name(a_goal));
      end;

-----------------------------------------------------------------------------
--          RULES                         context_holds                    --
-----------------------------------------------------------------------------

      function match_7(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
            goal.object_name(a_goal) = nil		and then
            monkey.holds(a_monkey) /= nil		and then
            physicalObject.name(an_object) = monkey.holds(a_monkey);
      end;
      function rule_7 is new tupleCollection.join3(match_7);         

      function holds_nil_C		return tupleCollection.object is
      begin
         return
         rule_7(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_nil_A (MGO : tuple.object) is
         a_monkey, a_goal, an_object : reference;
      begin
         a_monkey  := tuple.first(MGO);
         a_goal    := tuple.second(MGO);
         an_object := tuple.third(MGO);
	 put("Drop  ");
	 put_line(monkey.holds(a_monkey));
	 goal.modify_status(a_goal, satisfied);
	 monkey.modify_object_held(a_monkey, nil);
	 physicalObject.modify_is_on(an_object, floor);
      end;

      function match_8(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
            goal.object_name(a_goal) = nil		and then
            monkey.holds(a_monkey) = nil;
      end;
      function rule_8 is new tupleCollection.join2(match_8);         

      function holds_nil_satisfied_C	return tupleCollection.object is
      begin
         return
         rule_8(monkey.instances,goal.instances,ANY);
      end;

      procedure holds_nil_satisfied_A (MG : tuple.object) is
	 a_goal    : reference;
      begin
         a_goal := tuple.second(MG);
         goal.modify_status(a_goal, satisfied);
         put_line("Monkey is holding nothing");
      end;

      function match_9(a_monkey,a_goal,an_object1,an_object2 : reference) 
      return boolean is
	 function match2(an_object : reference) return boolean is
	 begin
	    return
	       physicalObject.is_on(an_object) = goal.object_name(a_goal);
	 end;
	 function on_goal_object is new collection.findOne(match2);
      begin
         return
            active_holds(a_goal)			and then
            physicalObject.name(an_object1) = 
               goal.object_name(a_goal)			and then
            physicalObject.weight(an_object1) = 
	       light  					and then
	    physicalObject.is_on(an_object1) = 
	       ceiling					and then
	    physicalObject.name(an_object2) = 
               ladder					and then
	    physicalObject.is_on(an_object2) = 
               floor					and then
	    physicalObject.is_at(an_object1) = 
	        physicalObject.is_at(an_object2)	and then
	    monkey.is_on(a_monkey) = ladder		and then
	    monkey.holds(a_monkey) = nil		and then
            collection.isNull(on_goal_object(physicalObject.instances));
      end;
      function rule_9 is new tupleCollection.join4(match_9);         

      function holds_object_ceiling_C	return tupleCollection.object is
      begin
         return
	 rule_9(monkey.instances,goal.instances,physicalObject.instances,
			                        physicalObject.instances,ANY);
      end;

      procedure holds_object_ceiling_A (MGO1O2 : tuple.object) is
	 a_monkey, a_goal, an_object : reference;
      begin
         a_monkey  := tuple.first(MGO1O2);
         a_goal    := tuple.second(MGO1O2);
         an_object := tuple.third(MGO1O2);
	 goal.modify_status(a_goal, satisfied);
	 monkey.modify_object_held(a_monkey, goal.object_name(a_goal));
	 physicalObject.modify_is_on(an_object, nil);
	 put("Grab ");
	 put_line(goal.object_name(a_goal));
      end;

      function match_10(a_monkey,a_goal,an_object1,an_object2 : reference) 
      return boolean is
      begin
         return
            active_holds(a_goal)			and then
            physicalObject.name(an_object1) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object1) = 
	       light  					and then
	    physicalObject.is_on(an_object1) = 
	       ceiling					and then
	    physicalObject.name(an_object2) = 
               ladder					and then
	    physicalObject.is_on(an_object2) = 
               floor					and then
	    physicalObject.is_at(an_object1) = 
	       physicalObject.is_at(an_object2)		and then
	    monkey.is_on(a_monkey) /= ladder;
      end;
      function rule_10 is new tupleCollection.join4(match_10);         

      function holds_object_ceiling_on_C return tupleCollection.object is
      begin
         return
         rule_10(monkey.instances,goal.instances,physicalObject.instances,
			                         physicalObject.instances,ANY);
      end;

      procedure holds_object_ceiling_on_A (MGO1O2 : tuple.object) is
      begin
         goal.make(active, is_on, ladder, (1,1));
--         put_line("make subgoal holds_object_ceiling_on");
      end;

      function match_11(a_goal,an_object1,an_object2 : reference) 
      return boolean is
      begin
         return
            active_holds(a_goal)			and then
            physicalObject.name(an_object1) = 
               goal.object_name(a_goal)			and then
            physicalObject.weight(an_object1) = 
	       light  					and then
	    physicalObject.is_on(an_object1) = 
	       ceiling					and then
	    physicalObject.name(an_object2) = 
               ladder					and then
	    physicalObject.is_at(an_object1) /=
                physicalObject.is_at(an_object2);
      end;
      function rule_11 is new tupleCollection.join3(match_11);         

      function holds_object_ceiling_at_object_C return tupleCollection.object is
      begin
         return 
         rule_11(goal.instances,physicalObject.instances,
                                physicalObject.instances,ANY);
      end;

      procedure holds_object_ceiling_at_object_A (GO1O2 : tuple.object) is
	 an_object : reference;
      begin
	 an_object := tuple.second(GO1O2);
	 goal.make(active, is_at, ladder, physicalObject.is_at(an_object));
--         put_line("make subgoal holds_object_ceiling_at_object");
      end;

      function match_12(a_monkey,a_goal,an_object : reference) return boolean is
	 function match2(an_object : reference) return boolean is
	 begin
	    return
	       physicalObject.is_on(an_object) = goal.object_name(a_goal);
	 end;
	 function on_goal_object is new collection.findOne(match2);
      begin
         return
            active_holds(a_goal)			and then
	    physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object) = 
	       light	  				and then
	    physicalObject.is_on(an_object) /= 
	       ceiling					and then
	    monkey.is_at(a_monkey) =
	       physicalObject.is_at(an_object)		and then
	    monkey.is_on(a_monkey) = floor		and then
	    monkey.holds(a_monkey) = nil		and then
            collection.isNull(on_goal_object(physicalObject.instances));
      end; 
      function rule_12 is new tupleCollection.join3(match_12);         

      function holds_object_not_ceiling_C return tupleCollection.object is
      begin
         return 
         rule_12(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_object_not_ceiling_A (MGO : tuple.object) is
         a_monkey, a_goal, an_object : reference;
      begin
         a_monkey  := tuple.first(MGO);
         a_goal    := tuple.second(MGO);
         an_object := tuple.third(MGO);
         goal.modify_status(a_goal, satisfied);
         monkey.modify_object_held(a_monkey, goal.object_name(a_goal));
         physicalObject.modify_is_on(an_object, nil);
         put("Grab ");
         put_line(goal.object_name(a_goal));
      end;

      function match_13(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
            physicalObject.weight(an_object) = 
	       light	  				and then
	    physicalObject.is_on(an_object) /= 
	       ceiling					and then
	    monkey.is_at(a_monkey) =
	       physicalObject.is_at(an_object)		and then
	    monkey.is_on(a_monkey) /= floor;
      end;
      function rule_13 is new tupleCollection.join3(match_13);         

      function holds_object_not_ceiling_on_C return tupleCollection.object is
      begin
         return
         rule_13(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_object_not_ceiling_on_A (MGO : tuple.object) is
      begin
         goal.make(active, is_on, floor, (1,1));
--         put_line("make subgoal holds_object_not_ceiling_on");
      end;

      function match_14(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object) = 
	       light	  				and then
	    physicalObject.is_on(an_object) /= 
	       ceiling					and then
	    monkey.is_at(a_monkey) /= physicalObject.is_at(an_object);
      end;
      function rule_14 is new tupleCollection.join3(match_14);         

      function holds_object_not_ceiling_at_monkey_C 
      return tupleCollection.object is
      begin
         return
         rule_14(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_object_not_ceiling_at_monkey_A (MGO : tuple.object) is
	 an_object : reference;
      begin
         an_object := tuple.third(MGO);
         goal.make(active, is_at, nil, physicalObject.is_at(an_object));
--         put_line("make subgoal holds_object_not_ceiling_at_monkey");
      end;

      function match_15(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
	    physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object) = 
	       light	  				and then
	    monkey.is_at(a_monkey) =
	       physicalObject.is_at(an_object)		and then
	    monkey.holds(a_monkey) /= nil		and then
	    monkey.holds(a_monkey) /= goal.object_name(a_goal);
      end;
      function rule_15 is new tupleCollection.join3(match_15);         

      function holds_object_holds_C	return tupleCollection.object is
      begin
         return 
         rule_15(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_object_holds_A (MGO : tuple.object) is
      begin
         goal.make(active, holds, nil, (1,1));
--         put_line("make subgoal holds_object_holds");
      end;

      function match_16(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_holds(a_goal)			and then
	    physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object) = 
	       light	  				and then
	    physicalObject.is_on(an_object) = nil   	and then
	    monkey.is_at(a_monkey) =
	       physicalObject.is_at(an_object)		and then
	    monkey.holds(a_monkey) = goal.object_name(a_goal);
      end;
      function rule_16 is new tupleCollection.join3(match_16);         

      function holds_object_satisfied_C	return tupleCollection.object is
      begin
         return 
         rule_16(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure holds_object_satisfied_A (MGO : tuple.object) is
	 a_goal    : reference;
      begin
         a_goal := tuple.second(MGO);
         goal.modify_status(a_goal, satisfied);
         put("Object ");
         put(goal.object_name(a_goal));
         put_line(" is already being held");
      end;

-----------------------------------------------------------------------------
--          RULES                         context_at                       --
-----------------------------------------------------------------------------

      function match_17(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
	    physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    monkey.is_at(a_monkey) /=
	       goal.go_to(a_goal)			and then
	    monkey.holds(a_monkey) = 
               goal.object_name(a_goal)			and then
	    monkey.is_on(a_monkey) = floor;
      end;
      function rule_17 is new tupleCollection.join3(match_17);         

      function at_object_C		return tupleCollection.object is
      begin
         return 
         rule_17(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure at_object_A (MGO : tuple.object) is
	 a_monkey, a_goal, an_object : reference;
      begin
         a_monkey  := tuple.first(MGO);
         a_goal    := tuple.second(MGO);
         an_object := tuple.third(MGO);
	 goal.modify_status(a_goal, satisfied);
	 monkey.modify_coordinate(a_monkey, goal.go_to(a_goal));
	 physicalObject.modify_coordinate(an_object, goal.go_to(a_goal));
	 put("Move ");
	 put(goal.object_name(a_goal));
         put(" to (");
	 put(goal.go_to(a_goal).x);
         put(" , ");
	 put(goal.go_to(a_goal).y);
	 put_line(" )");
      end;

      function match_18(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
	    physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    monkey.is_on(a_monkey) /= floor		and then
	    monkey.holds(a_monkey) = 
               goal.object_name(a_goal)			and then
	    physicalObject.is_at(an_object) /= goal.go_to(a_goal);
      end;
      function rule_18 is new tupleCollection.join3(match_18);         

      function at_object_on_floor_C	return tupleCollection.object is
      begin
         return
         rule_18(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure at_object_on_floor_A (MGO : tuple.object) is
      begin
	 goal.make(active, is_on, floor, (1,1));
--         put_line("make subgoal at_object_on_floor");
      end;

      function match_19(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
            physicalObject.weight(an_object) = light 	and then
	    physicalObject.is_at(an_object) /= 
	       goal.go_to(a_goal)			and then
	    monkey.holds(a_monkey) /= goal.object_name(a_goal);
      end;
      function rule_19 is new tupleCollection.join3(match_19);         

      function at_object_holds_C	return tupleCollection.object is
      begin
         return
         rule_19(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure at_object_holds_A (MGO : tuple.object) is
	 a_goal    : reference;
      begin
	 a_goal := tuple.second(MGO);
	 goal.make(active, holds, goal.object_name(a_goal), (1,1));
--         put_line("make subgoal at_object_holds");
      end;

      function match_20(a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
            physicalObject.name(an_object) = 
               goal.object_name(a_goal)			and then
	    physicalObject.weight(an_object) = light 	and then
	    physicalObject.is_at(an_object) = goal.go_to(a_goal);
      end;
      function rule_20 is new tupleCollection.join2(match_20);         

      function at_object_satisfied_C	return tupleCollection.object is
      begin
         return
         rule_20(goal.instances,physicalObject.instances,ANY);
      end;

      procedure at_object_satisfied_A (GO : tuple.object) is
	 a_goal    : reference;
      begin
         a_goal := tuple.first(GO);
	 goal.modify_status(a_goal, satisfied);
	 put("The object ");
	 put(goal.object_name(a_goal));
	 put(" is already at (");
	 put(goal.go_to(a_goal).x);
         put(" , ");
	 put(goal.go_to(a_goal).y);
	 put_line(" )");
      end;

      function match_21(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
            goal.object_name(a_goal) = nil		and then
	    monkey.is_at(a_monkey) /=
	       goal.go_to(a_goal)			and then
	    monkey.is_on(a_monkey) = floor		and then
	    monkey.holds(a_monkey) = nil;
      end;
      function rule_21 is new tupleCollection.join2(match_21);         

      function at_monkey_C		return tupleCollection.object is
      begin
         return
         rule_21(monkey.instances,goal.instances,ANY);
      end;

      procedure at_monkey_A (MG : tuple.object) is
	 a_monkey, a_goal    : reference;
      begin
         a_monkey  := tuple.first(MG);
         a_goal    := tuple.second(MG);
	 goal.modify_status(a_goal, satisfied);
	 monkey.modify_coordinate(a_monkey, goal.go_to(a_goal));
	 put("Walk to (");
	 put(goal.go_to(a_goal).x);
         put(" , ");
	 put(goal.go_to(a_goal).y);
	 put_line(" )");
      end;

      function match_22(a_monkey,a_goal,an_object : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
	    goal.object_name(a_goal) = nil		and then
	    monkey.is_on(a_monkey) = floor		and then
	    physicalObject.name(an_object) = 
	       monkey.holds(a_monkey)			and then
	    monkey.is_at(a_monkey) /= goal.go_to(a_goal);
      end;
      function rule_22 is new tupleCollection.join3(match_22);         

      function at_monkey_object_C	return tupleCollection.object is
      begin
         return
         rule_22(monkey.instances,goal.instances,physicalObject.instances,ANY);
      end;

      procedure at_monkey_object_A (MGO : tuple.object) is
	 a_monkey, a_goal, an_object : reference;
      begin
         a_monkey  := tuple.first(MGO);
	 a_goal    := tuple.second(MGO);
	 an_object := tuple.third(MGO);
	 goal.modify_status(a_goal, satisfied);
	 physicalObject.modify_coordinate(an_object, goal.go_to(a_goal));
	 monkey.modify_coordinate(a_monkey, goal.go_to(a_goal));
	 put("Walk to (");
	 put(goal.go_to(a_goal).x);
         put(" , ");
	 put(goal.go_to(a_goal).y);
	 put(" ) carrying ");
	 put_line(monkey.holds(a_monkey));
      end;

      function match_23(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
            goal.object_name(a_goal) = nil		and then
            monkey.is_at(a_monkey) /=
            goal.go_to(a_goal)				and then
	    monkey.is_on(a_monkey) /= floor;
      end;
      function rule_23 is new tupleCollection.join2(match_23);         

      function at_monkey_on_C		return tupleCollection.object is
      begin
         return
         rule_23(monkey.instances,goal.instances,ANY);
      end;

      procedure at_monkey_on_A (MG : tuple.object) is
      begin
	 goal.make(active, is_on, floor, (1,1));
--         put_line("make subgoal at_monkey_on");
      end;

      function match_24(a_monkey,a_goal : reference) return boolean is
      begin
         return
            active_is_at(a_goal)			and then
            goal.object_name(a_goal) = nil		and then
            monkey.is_at(a_monkey) = goal.go_to(a_goal);
      end;
      function rule_24 is new tupleCollection.join2(match_24);         

      function at_monkey_satisfied_C	return tupleCollection.object is
      begin
         return
         rule_24(monkey.instances,goal.instances,ANY);
      end;

      procedure at_monkey_satisfied_A (MG : tuple.object) is
	 a_goal    : reference;
      begin
         a_goal := tuple.second(MG);
	 goal.modify_status(a_goal, satisfied);
	 put("Monkey is already at (");
	 put(goal.go_to(a_goal).x);
         put(" , ");
	 put(goal.go_to(a_goal).y);
	 put_line(" )");
      end;

      function match_25(a_goal : reference) return boolean is
      begin
         return 
            goal.status(a_goal) = satisfied		and then
            collection.isNull(find_active(goal.instances));
      end;
      function rule_25 is new collection.findOne(match_25);

      function congratulations_C			return boolean is
      begin   
         return
            not collection.isNull(rule_25(goal.instances));
      end;

      procedure congratulations_A is
      begin
         put_line("CONGRATULATIONS the goals are satisfied");
      end;


      function impossible_C				return boolean is
      begin
         return
            not collection.isNull(find_active(goal.instances));
      end;

      procedure impossible_A is
	 a_goal    : reference;
      begin
         a_goal := find_active(goal.instances);
         put("IMPOSSIBLE, the goal ");
	 put(g_type'IMAGE(goal.goal_type(a_goal)));
         put_line(" cannot be achieved");
      end;


      procedure create_test(i : positive) is
      begin
         case i is
      when 1 =>
	 physicalObject.make(as_name("bananas"), 
		             (9,9), 
                             light, 
                             ceiling);
	 physicalObject.make(as_name("couch"),   
			     (7,7), 
                             heavy, 
                             floor);
	 physicalObject.make(ladder,  
			     (4,3), 
			     light, 
			     floor);
	 monkey.make((7,7), 
                     as_name("couch"), 
		     as_name("blanket"));
	 physicalObject.make(as_name("blanket"), 
			     (7,7), 
			     light,  
                             nil);
         goal.make(active, 
                   holds, 
                   as_name("bananas"), 
                   (1,1));
      when 2 =>
	 physicalObject.make(as_name("bananas"), 
		             (7,7), 
                             light, 
                             ceiling);
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     floor);
	 physicalObject.make(as_name("blanket"), 
			     (5,5), 
			     light,  
                             floor);
	 monkey.make((5,5), 
                     ladder, 
		     nil);
         goal.make(active, 
                   holds, 
                   as_name("bananas"), 
                   (1,1));
      when 3 =>
	 physicalObject.make(ladder,  
			     (5,7), 
			     light, 
			     floor);
	 monkey.make((5,7), 
                     ladder, 
		     nil);
         goal.make(active, 
                   is_on, 
                   floor, 
                   (1,1));
      when 4 =>
	 physicalObject.make(ladder,  
			     (5,7), 
			     light, 
			     floor);
	 monkey.make((5,7), 
                     floor, 
		     nil);
         goal.make(active, 
                   is_on, 
                   floor, 
                   (1,1));
      when 5 =>
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     floor);
	 monkey.make((5,5), 
                     floor, 
		     nil);
         goal.make(active, 
                   is_on, 
                   ladder, 
                   (1,1));
      when 6 =>
	 monkey.make((5,5), 
                     floor, 
		     ladder);
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     nil);
         goal.make(active, 
                   is_on, 
                   ladder, 
                   (1,1));
      when 7 =>
	 physicalObject.make(ladder,  
			     (6,5), 
			     light, 
			     floor);
	 monkey.make((3,3), 
                     floor, 
		     nil);
         goal.make(active, 
                   is_on, 
                   ladder, 
                   (1,1));
      when 8 =>
	 physicalObject.make(ladder,  
			     (6,5), 
			     light, 
			     floor);
	 monkey.make((6,5), 
                     ladder, 
		     nil);
         goal.make(active, 
                   is_on, 
                   ladder, 
                   (1,1));
      when 9 =>
	 monkey.make((5,5), 
                     floor, 
		     as_name("blanket"));
	 physicalObject.make(as_name("blanket"),  
			     (5,5), 
			     light, 
			     nil);
         goal.make(active, 
                   holds, 
                   nil, 
                   (1,1));
      when 10 =>
	 monkey.make((5,5), 
                     floor, 
		     nil);
         goal.make(active, 
                   holds, 
                   nil, 
                   (1,1));
      when 11 =>
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     floor);
	 physicalObject.make(as_name("bananas"),  
			     (5,5), 
			     light, 
			     ceiling);
	 monkey.make((5,5), 
                     floor, 
		     nil);
         goal.make(active, 
                   holds, 
                   as_name("bananas"), 
                   (1,1));
      when 12 =>
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     floor);
	 physicalObject.make(as_name("bananas"),  
			     (7,7), 
			     light, 
			     ceiling);
	 monkey.make((5,5), 
                     ladder, 
		     as_name("blanket"));
	 physicalObject.make(as_name("blanket"),
			     (5,5), 
			     light, 
			     nil);
         goal.make(active, 
                   holds, 
                   as_name("bananas"), 
                   (1,1));
      when 13 =>
	 physicalObject.make(ladder,  
			     (5,5), 
			     light, 
			     floor);
	 monkey.make((5,5), 
                     ladder, 
		     nil);
         goal.make(active, 
                   holds, 
                   ladder, 
                   (1,1));
      when 14 =>
	 physicalObject.make(ladder,  
			     (7,5), 
			     light, 
			     floor);
	 monkey.make((5,5), 
                     floor, 
		     nil);
         goal.make(active, 
                   holds, 
                   ladder, 
                   (1,1));
      when 15 =>
	 monkey.make((5,5), 
                     floor, 
		     as_name("bananas"));
	 physicalObject.make(as_name("bananas"),
			     (5,5), 
			     light, 
			     nil);
         goal.make(active, 
                   holds, 
                   as_name("bananas"), 
                   (1,1));
      when 16 =>
	 monkey.make((5,7), 
                     floor, 
		     nil);
	 physicalObject.make(ladder,
			     (7,7), 
			     light, 
			     floor);
         goal.make(active, 
                   is_at, 
                   nil, 
                   (7,7));
      when 17 =>
	 monkey.make((5,5), 
                     floor, 
		     as_name("blanket"));
	 physicalObject.make(as_name("blanket"),
			     (5,5), 
			     light, 
			     nil);
	 physicalObject.make(ladder,
			     (7,7), 
			     light, 
			     floor);
         goal.make(active, 
                   is_at, 
                   nil, 
                   (7,7));
      when 18 =>
	 physicalObject.make(as_name("couch"),
			     (5,5), 
			     light, 
			     floor);
	 monkey.make((5,5), 
                     as_name("couch"), 
		     nil);
	 physicalObject.make(ladder,
			     (7,7), 
			     light, 
			     floor);
         goal.make(active, 
                   is_at, 
                   nil, 
                   (7,7));
      when 19 =>
	 monkey.make((5,5), 
                     floor,
		     ladder);
	 physicalObject.make(ladder,
			     (5,5), 
			     light, 
			     nil);
	 physicalObject.make(as_name("bananas"),
			     (8,8), 
			     light, 
			     ceiling);
         goal.make(active, 
                   is_at, 
                   ladder, 
                   (8,8));
      when 20 =>
	 physicalObject.make(as_name("couch"),
			     (5,5), 
			     heavy, 
			     floor);
	 monkey.make((5,5), 
                     as_name("couch"),
		     as_name("bananas"));
	 physicalObject.make(as_name("bananas"),
			     (5,5), 
			     light, 
			     nil);
         goal.make(active, 
                   is_at, 
                   as_name("bananas"), 
                   (7,7));
      when 21 =>
	 physicalObject.make(ladder,
			     (7,5), 
			     light, 
			     floor);
	 monkey.make((5,5), 
                     floor,
		     nil);
	 physicalObject.make(as_name("bananas"),
			     (8,8), 
			     light, 
			     ceiling);
         goal.make(active, 
                   is_at, 
                   ladder, 
                   (8,8));
      when 22 =>
	 monkey.make((5,5), 
                     floor,
		     nil);
	 physicalObject.make(as_name("elephant"),
			     (8,8), 
			     heavy, 
			     floor);
         goal.make(active, 
                   is_at, 
                   as_name("elephant"), 
                   (6,7));

      when others => null;
      end case;
      end create_test;

      package lookForBananas2 is new engine(
		context_name    => "Find banan",
		resolution      => LEX,
		used_rules      => 24,
		name_1		=> "on_floor       ",
		condition_1	=> on_floor_C,
 		action_1	=> on_floor_A,
		name_2		=> "on_floor_satisf",
		condition_2	=> on_floor_satisfied_C,
		action_2	=> on_floor_satisfied_A,
		name_3		=> "on_phy_obj     ",
	 	condition_3	=> on_physical_object_C,
	 	action_3	=> on_physical_object_A,
		name_4		=> "on_phy_obj_hold",
		condition_4	=> on_physical_object_holds_C,
		action_4	=> on_physical_object_holds_A,
		name_5		=> "on_phy_obj_at_m",
		condition_5	=> on_physical_object_at_monkey_C,
		action_5	=> on_physical_object_at_monkey_A,
		name_6		=> "on_phy_obj_sati",
  		condition_6	=> on_physical_object_satisfied_C,
  		action_6	=> on_physical_object_satisfied_A,

		name_7		=> "holds_nil      ",
		condition_7	=> holds_nil_C,
		action_7	=> holds_nil_A,
		name_8		=> "holds_nil_satis",
		condition_8	=> holds_nil_satisfied_C,
		action_8	=> holds_nil_satisfied_A,
		name_9		=> "hol_obj_ceil   ",
		condition_9	=> holds_object_ceiling_C,
		action_9	=> holds_object_ceiling_A,
		name_10		=> "hol_obj_ceil_on",
		condition_10	=> holds_object_ceiling_on_C,
		action_10	=> holds_object_ceiling_on_A,
		name_11		=> "hol_obj_ceil_at",
		condition_11	=> holds_object_ceiling_at_object_C,
		action_11	=> holds_object_ceiling_at_object_A,
		name_12		=> "hol_obj_not_cei",
		condition_12	=> holds_object_not_ceiling_C,
		action_12	=> holds_object_not_ceiling_A,
		name_13		=> "hol_obj_n_ce_on",
		condition_13	=> holds_object_not_ceiling_on_C,
		action_13	=> holds_object_not_ceiling_on_A,
		name_14		=> "hol_obj_n_c_at_",
		condition_14	=> holds_object_not_ceiling_at_monkey_C,
		action_14	=> holds_object_not_ceiling_at_monkey_A,
		name_15		=> "hol_obj_holds  ",
		condition_15	=> holds_object_holds_C,
		action_15	=> holds_object_holds_A,
		name_16		=> "hol_obj_satisfi",
		condition_16	=> holds_object_satisfied_C,
		action_16	=> holds_object_satisfied_A,

		name_17		=> "at_object      ",
		condition_17	=> at_object_C,
		action_17	=> at_object_A,
		name_18		=> "at_obj_on_floor",
  		condition_18	=> at_object_on_floor_C,
		action_18	=> at_object_on_floor_A,
		name_19		=> "at_object_holds",
		condition_19	=> at_object_holds_C,
		action_19	=> at_object_holds_A,
		name_20		=> "at_obj_satisfie",
		condition_20	=> at_object_satisfied_C,
		action_20	=> at_object_satisfied_A,
		name_21		=> "at_monkey      ",
		condition_21	=> at_monkey_C,
		action_21	=> at_monkey_A,
		name_22		=> "at_monkey_objec",
		condition_22	=> at_monkey_object_C,
		action_22	=> at_monkey_object_A,
		name_23		=> "at_monkey_on   ",
		condition_23	=> at_monkey_on_C,
		action_23	=> at_monkey_on_A,
		name_24		=> "at_monkey_satis",
		condition_24	=> at_monkey_satisfied_C,
		action_24	=> at_monkey_satisfied_A);


      procedure find_the_bananas is
	result : boolean;
      begin
         put_line("-------------------------------------------------");
         for i in 1..22 loop
            put("TEST Nr "); put(i); put_line(" :");
            create_test(i);
            result:=lookForBananas2.inference(ANY);
	    if congratulations_C then
	       congratulations_A;
	    elsif impossible_C then
	       impossible_A;
            end if;
            monkey.clear;
            physicalObject.clear;
            goal.clear;
            put_line("-------------------------------------------------");
         end loop;
      end find_the_bananas;
   end monkeyAndBananas;

begin

  debugger.resetDebug(debugger.text);
  debugger.setDebugOn(debugger.completly);
  debugger.refreshDebug;
  debugger.setDebugOff(debugger.conditionEvalued);

  monkeyAndBananas.find_the_bananas;

end bananas2;