|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 Tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: B T
Length: 46490 (0xb59a)
Types: TextFile
Names: »B«
└─⟦149519bd4⟧ Bits:30000546 8mm tape, Rational 1000, !projects 93-07-13
└─⟦124ff5788⟧ »DATA«
└─⟦this⟧
└─⟦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⟧
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 Active_Goal;
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 Active_Is_On;
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 Active_Holds;
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 Active_Is_At;
-----------------------------------------------------------------------------
-- 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 Match_1;
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 On_Floor_C;
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 On_Floor_A;
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 Match_2;
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 On_Floor_Satisfied_C;
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 On_Floor_Satisfied_A;
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 Match_3;
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 On_Physical_Object_C;
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 On_Physical_Object_A;
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 Match_4;
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 On_Physical_Object_Holds_C;
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 On_Physical_Object_Holds_A;
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 Match_5;
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 On_Physical_Object_At_Monkey_C;
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 On_Physical_Object_At_Monkey_A;
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 Match_6;
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 On_Physical_Object_Satisfied_C;
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 On_Physical_Object_Satisfied_A;
-----------------------------------------------------------------------------
-- 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 Match_7;
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 Holds_Nil_C;
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 Holds_Nil_A;
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 Match_8;
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 Holds_Nil_Satisfied_C;
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 Holds_Nil_Satisfied_A;
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 Match2;
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 Match_9;
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 Holds_Object_Ceiling_C;
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 Holds_Object_Ceiling_A;
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 Match_10;
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 Holds_Object_Ceiling_On_C;
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 Holds_Object_Ceiling_On_A;
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 Match_11;
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 Holds_Object_Ceiling_At_Object_C;
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 Holds_Object_Ceiling_At_Object_A;
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 Match2;
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 Match_12;
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 Holds_Object_Not_Ceiling_C;
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 Holds_Object_Not_Ceiling_A;
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 Match_13;
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 Holds_Object_Not_Ceiling_On_C;
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 Holds_Object_Not_Ceiling_On_A;
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 Match_14;
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 Holds_Object_Not_Ceiling_At_Monkey_C;
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 Holds_Object_Not_Ceiling_At_Monkey_A;
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 Match_15;
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 Holds_Object_Holds_C;
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 Holds_Object_Holds_A;
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 Match_16;
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 Holds_Object_Satisfied_C;
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 Holds_Object_Satisfied_A;
-----------------------------------------------------------------------------
-- 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 Match_17;
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 At_Object_C;
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 At_Object_A;
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 Match_18;
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 At_Object_On_Floor_C;
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 At_Object_On_Floor_A;
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 Match_19;
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 At_Object_Holds_C;
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 At_Object_Holds_A;
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 Match_20;
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 At_Object_Satisfied_C;
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 At_Object_Satisfied_A;
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 Match_21;
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 At_Monkey_C;
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 At_Monkey_A;
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 Match_22;
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 At_Monkey_Object_C;
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 At_Monkey_Object_A;
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 Match_23;
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 At_Monkey_On_C;
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 At_Monkey_On_A;
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 Match_24;
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 At_Monkey_Satisfied_C;
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 At_Monkey_Satisfied_A;
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 Match_25;
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 Congratulations_C;
procedure Congratulations_A is
begin
Put_Line ("CONGRATULATIONS the goals are satisfied");
end Congratulations_A;
function Impossible_C return Boolean is
begin
return not Collection.Isnull (Find_Active (Goal.Instances));
end Impossible_C;
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 Impossible_A;
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;