|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 51200 (0xc800)
Types: Ada Source
Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Monkeyandban, procedure Ctxban2, seg_00c7f3
└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000
└─⟦5a81ac88f⟧ »Space Info Vol 1«
└─⟦this⟧
with Expertsystem;
use Expertsystem;
with Monkeyobject;
use Monkeyobject;
with Monkey, Physicalobject, Goal;
procedure Ctxban2 is
package Monkeyandban is
procedure Find_The_Bananas;
end Monkeyandban;
package body Monkeyandban 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 Context_On is
new Engine (Context_Name => "context_on",
Resolution => Lex,
Used_Rules => 6,
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_physical_obj",
Condition_3 => On_Physical_Object_C,
Action_3 => On_Physical_Object_A,
Name_4 => "on_physical_obj",
Condition_4 => On_Physical_Object_Holds_C,
Action_4 => On_Physical_Object_Holds_A,
Name_5 => "on_physical_obj",
Condition_5 => On_Physical_Object_At_Monkey_C,
Action_5 => On_Physical_Object_At_Monkey_A,
Name_6 => "on_physical_obj",
Condition_6 => On_Physical_Object_Satisfied_C,
Action_6 => On_Physical_Object_Satisfied_A);
package Context_Holds is
new Engine (Context_Name => "context_ho",
Resolution => Lex,
Used_Rules => 10,
Name_1 => "holds_nil ",
Condition_1 => Holds_Nil_C,
Action_1 => Holds_Nil_A,
Name_2 => "holds_nil_satis",
Condition_2 => Holds_Nil_Satisfied_C,
Action_2 => Holds_Nil_Satisfied_A,
Name_3 => "holds_object_ce",
Condition_3 => Holds_Object_Ceiling_C,
Action_3 => Holds_Object_Ceiling_A,
Name_4 => "holds_object_ce",
Condition_4 => Holds_Object_Ceiling_On_C,
Action_4 => Holds_Object_Ceiling_On_A,
Name_5 => "holds_object_ce",
Condition_5 => Holds_Object_Ceiling_At_Object_C,
Action_5 => Holds_Object_Ceiling_At_Object_A,
Name_6 => "holds_object_no",
Condition_6 => Holds_Object_Not_Ceiling_C,
Action_6 => Holds_Object_Not_Ceiling_A,
Name_7 => "holds_object_no",
Condition_7 => Holds_Object_Not_Ceiling_On_C,
Action_7 => Holds_Object_Not_Ceiling_On_A,
Name_8 => "holds_object_no",
Condition_8 => Holds_Object_Not_Ceiling_At_Monkey_C,
Action_8 => Holds_Object_Not_Ceiling_At_Monkey_A,
Name_9 => "holds_object_ho",
Condition_9 => Holds_Object_Holds_C,
Action_9 => Holds_Object_Holds_A,
Name_10 => "holds_object_sa",
Condition_10 => Holds_Object_Satisfied_C,
Action_10 => Holds_Object_Satisfied_A);
package Context_At is new Engine (Context_Name => "context_at",
Resolution => Lex,
Used_Rules => 8,
Name_1 => "at_object ",
Condition_1 => At_Object_C,
Action_1 => At_Object_A,
Name_2 => "at_object_on_fl",
Condition_2 => At_Object_On_Floor_C,
Action_2 => At_Object_On_Floor_A,
Name_3 => "at_object_holds",
Condition_3 => At_Object_Holds_C,
Action_3 => At_Object_Holds_A,
Name_4 => "at_object_satis",
Condition_4 => At_Object_Satisfied_C,
Action_4 => At_Object_Satisfied_A,
Name_5 => "at_monkey ",
Condition_5 => At_Monkey_C,
Action_5 => At_Monkey_A,
Name_6 => "at_monkey_objec",
Condition_6 => At_Monkey_Object_C,
Action_6 => At_Monkey_Object_A,
Name_7 => "at_monkey_on ",
Condition_7 => At_Monkey_On_C,
Action_7 => At_Monkey_On_A,
Name_8 => "at_monkey_satis",
Condition_8 => At_Monkey_Satisfied_C,
Action_8 => At_Monkey_Satisfied_A);
procedure Find_The_Bananas is
begin
Put_Line ("-------------------------------------------------");
for I in 1 .. 22 loop
Put ("TEST ");
Put (I);
Put_Line (" :");
Create_Test (I);
loop
exit when not Context_On.Inference (1) and
not Context_Holds.Inference (1) and
not Context_At.Inference (1);
end loop;
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 Monkeyandban;
begin
Debugger.Setdebugoff (Debugger.Completly);
Monkeyandban.Find_The_Bananas;
Debugger.Resetdebug (Debugger.Text);
Debugger.Setdebugon (Debugger.Completly);
Debugger.Refreshdebug;
Debugger.Setdebugoff (Debugger.Conditionevalued);
Monkeyandban.Find_The_Bananas;
end Ctxban2;
nblk1=31
nid=0
hdr6=62
[0x00] rec0=24 rec1=00 rec2=01 rec3=05c
[0x01] rec0=17 rec1=00 rec2=02 rec3=05e
[0x02] rec0=19 rec1=00 rec2=03 rec3=06c
[0x03] rec0=19 rec1=00 rec2=04 rec3=036
[0x04] rec0=15 rec1=00 rec2=05 rec3=040
[0x05] rec0=16 rec1=00 rec2=06 rec3=010
[0x06] rec0=16 rec1=00 rec2=07 rec3=066
[0x07] rec0=15 rec1=00 rec2=08 rec3=03a
[0x08] rec0=15 rec1=00 rec2=09 rec3=098
[0x09] rec0=18 rec1=00 rec2=0a rec3=036
[0x0a] rec0=18 rec1=00 rec2=0b rec3=066
[0x0b] rec0=13 rec1=00 rec2=0c rec3=090
[0x0c] rec0=15 rec1=00 rec2=0d rec3=042
[0x0d] rec0=13 rec1=00 rec2=0e rec3=024
[0x0e] rec0=16 rec1=00 rec2=0f rec3=056
[0x0f] rec0=15 rec1=00 rec2=10 rec3=002
[0x10] rec0=13 rec1=00 rec2=11 rec3=010
[0x11] rec0=15 rec1=00 rec2=12 rec3=00e
[0x12] rec0=13 rec1=00 rec2=13 rec3=06c
[0x13] rec0=16 rec1=00 rec2=14 rec3=022
[0x14] rec0=17 rec1=00 rec2=15 rec3=008
[0x15] rec0=14 rec1=00 rec2=16 rec3=03a
[0x16] rec0=14 rec1=00 rec2=17 rec3=070
[0x17] rec0=17 rec1=00 rec2=18 rec3=04c
[0x18] rec0=16 rec1=00 rec2=19 rec3=00c
[0x19] rec0=18 rec1=00 rec2=1a rec3=006
[0x1a] rec0=15 rec1=00 rec2=1b rec3=03c
[0x1b] rec0=16 rec1=00 rec2=1c rec3=080
[0x1c] rec0=1a rec1=00 rec2=1d rec3=048
[0x1d] rec0=18 rec1=00 rec2=1e rec3=010
[0x1e] rec0=17 rec1=00 rec2=1f rec3=024
[0x1f] rec0=15 rec1=00 rec2=20 rec3=068
[0x20] rec0=1a rec1=00 rec2=21 rec3=02a
[0x21] rec0=1a rec1=00 rec2=22 rec3=05e
[0x22] rec0=1c rec1=00 rec2=23 rec3=032
[0x23] rec0=11 rec1=00 rec2=24 rec3=02c
[0x24] rec0=13 rec1=00 rec2=25 rec3=028
[0x25] rec0=13 rec1=00 rec2=26 rec3=00e
[0x26] rec0=10 rec1=00 rec2=27 rec3=05e
[0x27] rec0=12 rec1=00 rec2=28 rec3=064
[0x28] rec0=11 rec1=00 rec2=29 rec3=01a
[0x29] rec0=11 rec1=00 rec2=2a rec3=054
[0x2a] rec0=16 rec1=00 rec2=2b rec3=080
[0x2b] rec0=13 rec1=00 rec2=2c rec3=056
[0x2c] rec0=10 rec1=00 rec2=2d rec3=07e
[0x2d] rec0=10 rec1=00 rec2=2e rec3=09a
[0x2e] rec0=0e rec1=00 rec2=2f rec3=042
[0x2f] rec0=15 rec1=00 rec2=30 rec3=04a
[0x30] rec0=1d rec1=00 rec2=31 rec3=001
tail 0x21508e8d082074fc09bb8 0x42a00088462060003