Advertisement
logicmoo

Guncho

Dec 22nd, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 35.99 KB | None | 0 0
  1.     "Boxworld" by Nate Cull
  2.  
  3. The story headline is "An interactive laboratory".
  4.  
  5. [A Planner test/demonstration realm for Guncho, based on Planner and Alchemy by Nate Cull, incorporating bug fixes and suggestions from Josh Lawrence. Feel free to steal code, this is an open demo.
  6.  
  7. The major changes so far from Planner v1 (some caused by changes to I7 since 2006, some needed for Guncho):
  8. * 'Carry out someone trying something' changed to 'Instead of someone trying something' to avoid a compile syntax error
  9. * the object 'no-token' as an initial value in the goal table to avoid compile type error (the 'plan' column needs to be able to take any kind of planning-token, not just planning-relations).
  10. * angle brackets in comments removed to avoid Guncho compile errors (Guncho)
  11. * DOCUMENTATION sections removed (Guncho)
  12. * Includes and version stamps for library modules removed (Guncho)
  13. * Library modules changed to Volumes within a single source file (Guncho)
  14. * Sections used as standard unit within Volumes (Guncho)
  15. * ECHO command imported from Fairhaven (Guncho)
  16. * PLANS JUSTIFY added - tracks back goal chain from action (assuming the goal fired is in fact the last line in the goal table) to toplevel goal
  17. * real-time events added (Guncho)
  18. * debugging real-time events
  19. * west portal back to Fairhaven Library
  20.  
  21. Todo:
  22. * bug: Bob doesn't cope with being given the basket - he senses things inside it as not being touchable.
  23. * bug: reporting Bob opening the cupboard doesn't work with 'for the first time'
  24.  
  25. ]
  26.  
  27. Volume 1 - Planner
  28.  
  29. Section - Definitions and Globals
  30.  
  31.  
  32. Planning-token is a kind.
  33.  
  34. No-token is a planning-token.
  35.  
  36. Planning-relation is a kind of planning-token.
  37.  
  38. Planning-action is a kind of planning-token.
  39.  
  40. No-action is a planning-action.
  41. Success-action is a planning-action.
  42.  
  43. Planning-marker is a kind of planning-token.
  44.  
  45. No-plan is a planning-marker.
  46. No-step is a planning-marker.
  47. Plan-pending is a planning-marker.
  48.  
  49. No-object is a thing.
  50.  
  51. Table of Goals
  52. Parent  Plan    Step    Token   Param1  Param2
  53. 0   0   0   no-token    no-object   no-object
  54. with 20 blank rows
  55.  
  56.  
  57. The planning actor is a person that varies.
  58.  
  59. The requested relation is a planning-relation that varies.
  60. The requested param1 is an object that varies.
  61. The requested param2 is an object that varies.
  62.  
  63. The planned action is a planning-action that varies.
  64. The planned param1 is an object that varies.
  65. The planned param2 is an object that varies.
  66.  
  67. The desired plan is a number that varies.
  68. The desired step is a number that varies.
  69. The desired relation is a planning-relation that varies.
  70. The desired param1 is an object that varies.
  71. The desired param2 is an object that varies.
  72.  
  73. The suggested token is a planning-token that varies.
  74. The suggested param1 is an object that varies.
  75. The suggested param2 is an object that varies.
  76.  
  77. The working plan is a number that varies.
  78. The working step is a number that varies.
  79.  
  80. Planner verbosity is a number that varies. Planner verbosity is 0.
  81.  
  82. The action success flag is a number that varies.
  83.  
  84.  
  85.  
  86. Section - Main Routines
  87.  
  88. [This is the main entry point for calling Planner. It will find an action that satisfies the desired relation/object/object triad, and then attempt to execute that action.]
  89.  
  90. To have (A - a person) plan an action for (C - a planning-relation) with (P1 - an object) and (P2 - an object):
  91.     if debugging planner, say "Planner: starting planning for [A].";
  92.     if debugging planner, say "Planner: testing goal 1: [C] [P1] [P2]: [run paragraph on]";
  93.     change the planning actor to A;
  94.     change the requested relation to C;
  95.     change the requested param1 to P1;
  96.     change the requested param2 to P2;
  97.     change the planned action to no-action;
  98.     change the planned param1 to no-object;
  99.     change the planned param2 to no-object;
  100.     if goal C with P1 and P2 is true begin;
  101.         change the planned action to success-action;
  102.         if debugging planner, say "true, no work to do[line break]";
  103.     otherwise;
  104.         if debugging planner, say "false, generating plans [run paragraph on]";
  105.         clear the goal table;
  106.         choose row 1 in the Table of Goals;
  107.         change the Token entry to the requested relation;
  108.         change the Param1 entry to the requested param1;
  109.         change the Param2 entry to the requested param2;
  110.         change the Parent entry to 0;
  111.         change the Plan entry to 0;
  112.         change the Step entry to 0;
  113.         expand goal 1;
  114.         advance all goals;
  115.     end if;
  116.     if debugging planner begin;
  117.         if the planned action is no-action, say "Planner: no action chosen";
  118.         otherwise announce "Planner: say [the planned action] [the planned param1] [the planned param2]";
  119.         say "[paragraph break]";
  120.     end if;
  121.     execute the planned action;
  122.  
  123.  
  124.  
  125. [The core loop. Fill up the goal table line by line, reading goals as we come to them, considering each one, and if we can't satisfy it then spawning new subgoals and adding them to the end of the table. If we can fully satisfy a goal, then we end and return the action of that one as our chosen action.
  126.  
  127. My terminology is a little confusing as I sometimes use the words 'plan' and 'goal' apparently interchangeably. That's because of the way the data is stored. Let's have some definitions:
  128.  
  129. A Goal is a triad of Relation, Object, Object. (The Cat Is-on The Mat). It represents a piece of world state that we are actively trying to make true. Goals are related to one another in a tree structure. There is a top-level Goal which may have multiple child goals, and so on.
  130.  
  131. A Plan is a set of (Goal, Goal, Goal... Action). If every goal, evaluated in sequence from left to right, is true, then the actor should take the suggested Action.
  132.  
  133. So every Goal can have multiple Plans, and every Plan can have multiple Goals.
  134.  
  135. You'd think the best way to store this would be with a tree structure: Goals spawning Plans spawning Goals and so on. And you'd probably be right. But since we don't have dynamic memory allocation and can't easily do trees, we use a table instead. And each row of that table indicates *both* a Goal *and* a Plan, depending on context. Somewhat confusing. That is to say:
  136.  
  137. * The top row indicates the top-level Goal.
  138. * All new rows added to the table indicate separate Plans which are suggested as ways of satisfying outstanding Goals.
  139. * We examine each Plan, checking each of its Goals, and eventually we either return an Action, or stop at a Goal which is blocking us. When that happens, we mark up the table row to now indicate a *Goal*, and continue on.
  140.  
  141. So as we go on, each line in the table that we've visited consists of a Goal. Lines that we've added but not yet visited indicate unevaluated Plans.
  142.  
  143. Each row has:
  144. * Parent -the Goalrow which this is a plan or goal for
  145. * Plan - the Plan number of the Parent goal which this is a plan for
  146. * Step - (once we've turned from a Plan to a Goal) the Step number of this Plan at which we stopped evaluating because we found a not-currently-true Goal or an Action
  147. * Token - either an Action or a Relation, or else a Marker (a kind of note-to-self used for internal communication between the Planner routines)
  148. * Param1 - the first Object of the Action or Relation - only set once we have a Goal or Action
  149. * Param2 - the second Object of the Action or Relation - only set once we have a Goal or Action
  150.  
  151. Adding new Plans for a Goal I have called Expanding.
  152. Scanning a Plan, checking each of its subgoals, I have called Advancing.
  153.  
  154. ]
  155.  
  156. To advance all goals:
  157.     repeat with G running from 2 to the number of filled rows in the Table of Goals begin;
  158.         advance goal G;
  159.         if an action was planned, change G to 9999;
  160.     end repeat;
  161.  
  162.  
  163. [Advancing a Goal: Here we're scanning through each item in the current plan, checking what we've got, and if it's a subgoal, testing if it's true or not. If it's false, then we check if it's unique (ie, not listed as one of our prior goals). This prevents endless recursive loops - we deal with each goal once and only once, regardless of how many parent goals need it. If it's an action, we return that as our choice - this means we pick the first action that we find, ie, the action with the smallest number of goal-expansion steps. This should generally mean we take the shortest path toward getting our way.
  164.  
  165. To read each Step, we call the 'planning' rulebook, passing the desired relation/object/object and the desired Plan and Step through the 'desired...' global variable block. We increment Step each time. We stop once we don't get a response from the rulebook. This means that plans need to use consecutive Step numbers starting from 1. The rulebook will be hit once for every Step, plus once for counting Steps, of every Plan, plus one more for counting Plans. So if a plan requires expensive calculations, it is a good idea to test that 'desired plan' is set to the plan number before you run the calculation, or you'll be running it lots of times and throwing the result away.
  166.  
  167. ]
  168.  
  169. To advance goal (G - a number):
  170.     choose row G in the Table of Goals;
  171.     let our parent be the Parent entry;
  172.     let our plan be the Plan entry;
  173.     change the suggested token to the Token entry;
  174.     change the suggested param1 to the Param1 entry;
  175.     change the suggested param2 to the Param2 entry;
  176.     choose row our parent in the Table of Goals;
  177.     let our relation be the Token entry;
  178.     let our param1 be the Param1 entry;
  179.     let our param2 be the Param2 entry;
  180.     let the final step be 0;
  181.     if debugging planner, say "Planner: reading goal [G] (plan [our plan] for goal [our parent])[line break]";
  182.     repeat with Sx running from 1 to 9 begin;
  183.         suggest a goal for our relation with our param1 and our param2 for plan our plan at step Sx;
  184.         if the suggested token is a planning-marker begin;
  185.             change Sx to 9999;
  186.             choose row G in the Table of Goals;
  187.             change the Token entry to no-plan;
  188.             change the Param1 entry to no-object;
  189.             change the Param2 entry to no-object;
  190.         end if;
  191.         if the suggested token is a planning-relation begin;
  192.             if debugging planner, say "Planner: testing step [Sx]: [suggested token] [suggested param1] [suggested param2]: [run paragraph on]";
  193.             if goal suggested token with suggested param1 and suggested param2 is false begin;
  194.                 if debugging planner, say "false ";
  195.                 if goal the suggested token with the suggested param1 and the suggested param2 is unique begin;
  196.                     if debugging planner, say "and unique, generating plans [run paragraph on]";
  197.                     choose row G in the Table of Goals;
  198.                     change the Token entry to the suggested token;
  199.                     change the Param1 entry to the suggested param1;   
  200.                     change the Param2 entry to the suggested param2;
  201.                     change the Step entry to Sx;
  202.                     change the final step to Sx;
  203.                     change Sx to 9999;
  204.                     expand goal G;                     
  205.                 otherwise;
  206.                     if debugging planner, say "but duplicate, cancelling plan[line break]";
  207.                     choose row G in the Table of Goals;
  208.                     change the Token entry to no-plan;
  209.                     change the Param1 entry to no-object;  
  210.                     change the Param2 entry to no-object;
  211.                     change the Step entry to Sx;
  212.                     change the final step to Sx;
  213.                     change Sx to 9999;
  214.                 end if;
  215.             otherwise;
  216.                 if debugging planner, say "true";
  217.             end if;
  218.         end if;
  219.         if the suggested token is a planning-action begin;
  220.             if debugging planner, say "Planner: testing step [Sx]: [the suggested token] [the suggested param1] [the suggested param2]: action[line break]";
  221.             change the planned action to the suggested token;
  222.             change the planned param1 to the suggested param1;
  223.             change the planned param2 to the suggested param2;
  224.             choose row G in the Table of Goals;
  225.             change the Token entry to the suggested token;
  226.             change the Param1 entry to the suggested param1;
  227.             change the Param2 entry to the suggested param2;
  228.             change the Step entry to Sx;
  229.             change the final step to Sx;
  230.             change Sx to 9999;
  231.         end if;
  232.     end repeat;
  233.  
  234.  
  235. [Expanding a Goal: Here we are just dropping new empty lines onto the goal table to indicate Plans we have yet to explore. About all the information we need is the Parent and Plan entries. The rest we will look up in the Parent row once we get there.]
  236.  
  237.  
  238. To expand goal (G - a number):
  239.     choose row G in the Table of Goals;
  240.     let our relation be the Token entry;
  241.     let our param1 be the Param1 entry;
  242.     let our param2 be the Param2 entry;
  243.     repeat with P running from 1 to 9 begin;
  244.         suggest a goal for our relation with our param1 and our param2 for plan P at step 1;
  245.         if the suggested token is no-plan begin;
  246.             [we've run out of plans]
  247.             change P to 9999;
  248.         otherwise;
  249.             [add new goal, checking for out of space]
  250.             if the number of blank rows in the Table of Goals is greater than 0 begin;
  251.                 [add a new goal, as just a parent/plan/step entry]
  252.                 let the last row be the number of filled rows in the Table of Goals;
  253.                 increase the last row by 1;
  254.                 choose row the last row in the Table of Goals;
  255.                 change the Parent entry to G;
  256.                 change the Plan entry to P;
  257.                 change the Step entry to 1;
  258.                 change the Token entry to plan-pending;
  259.                 change the Param1 entry to no-object;
  260.                 change the Param2 entry to no-object;
  261.                 if debugging planner, say "[P] [run paragraph on]";
  262.             otherwise;
  263.                 if debugging planner, say "Planner: goal table is full, ignoring new goal.";
  264.             end if;
  265.         end if;
  266.     end repeat;
  267.     if debugging planner, say "[line break]";
  268.  
  269.  
  270.  
  271.  
  272. Section - Rulebooks
  273.  
  274.  
  275. [This is where you put rules to generate plans. Sample rules for general situations are defined in 'Basic Plans'. You may need to use procedural rules to override basic rules with more specific ones for your game. IE, if there are particular objects that can only be obtained through solving a puzzle or manipulating a machine, you may need a specific plan for 'being-in' or 'being-touchable' for that object.]
  276.  
  277. Planning rules is a rulebook.
  278.  
  279.  
  280. [This is where you put rules to test goals. Normally this would be a simple check against an I7 relation or property, and does not often need to be overridden.]
  281.  
  282. Planning-testing rules is a rulebook.
  283.  
  284.  
  285. [This is where you put rules to execute actions. Normally this would be a simple call of 'try the planning actor trying .action.'. Then you would create 'report .actor. trying .action.' rules to have custom descriptions of what your particular actor is doing.]
  286.  
  287. Planning-acting rules is a rulebook.
  288.  
  289.  
  290. [If the top-level goal tests as true, a 'success-action' action gets returned and this rulebook gets called. There is no more work for Planner to do, the actor has succeeded in their longest term goal. This might mean an actor needs to change their condition, or a scene change happens.]
  291.  
  292. Planning-success rules is a rulebook.
  293.  
  294.  
  295. [If no action can be suggested toward the top-level goal, a 'no-action' action gets returned and this rulebook gets called. The actor is currently frustrated, blocked or baffled somehow. Generally this indicates that something the author didn't expect happened, and a new plan needs to be written to cover this situation.]
  296.  
  297. Planning-failure rules is a rulebook.
  298.  
  299.  
  300. [If Planner returned an action, but when the actor tried to execute it (usually with 'trying...'), the I7 action failed. (Currently this condition happens if no 'Carry Out' rule ran.) This also generally indicates an incomplete set of plans, or an unexpected situation. ]
  301.  
  302. Planning-acting-failure rules is a rulebook.
  303.  
  304.  
  305.  
  306.  
  307. Section - Planning Routines
  308.  
  309.  
  310. To suggest a goal for (C - a planning-relation) with (P1 - an object) and (P2 - an object) for plan (P - a number) at step (Sx - a number):
  311.     change the desired relation to C;
  312.     change the desired param1 to P1;
  313.     change the desired param2 to P2;
  314.     change the desired plan to P;
  315.     change the desired step to Sx;
  316.     change the suggested token to no-plan;
  317.     change the suggested param1 to no-object;
  318.     change the suggested param2 to no-object;
  319.     follow the planning rulebook;
  320.  
  321. To really suggest (T - a planning-token) with (P1 - an object) and (P2 - an object):
  322.     change the suggested token to T;
  323.     change the suggested param1 to P1;
  324.     change the suggested param2 to P2;
  325.  
  326. To plan (P - a number):
  327.     change the working plan to P;
  328.     change the working step to 0;
  329.     if the desired plan is the working plan, change the suggested token to no-step;
  330.  
  331. To suggest (T - a planning-token) with (P1 - an object) and (P2 - an object):
  332.     increase the working step by 1;
  333.     if the desired plan is the working plan and the desired step is the working step, really suggest T with P1 and P2;
  334.  
  335. To suggest (T - a planning-token) with (P1 - an object):
  336.     suggest T with P1 and no-object;
  337.  
  338. To suggest (T - a planning-token):
  339.     suggest T with no-object and no-object;
  340.  
  341.  
  342.  
  343.  
  344. Section - Executing Actions
  345.  
  346.  
  347. The successful-action rule is listed after the check stage rule in the specific action-processing rules.
  348.  
  349. This is the successful-action rule:
  350.       if the actor is not the player, change the action success flag to 1.
  351.  
  352. [Instead of someone trying doing something:
  353.     change the action success flag to 1;
  354.     continue the action.]
  355.  
  356. To execute the planned action:
  357.     if the planned action is no-action begin;
  358.         follow the planning-failure rules;
  359.     otherwise;
  360.         if the planned action is success-action begin;
  361.             follow the planning-success rules;
  362.         otherwise; 
  363.             change the action success flag to 0;
  364.             follow the planning-acting rules;
  365.             if the action success flag is 0, follow the planning-acting-failure rules;
  366.         end if;
  367.     end if;
  368.  
  369.  
  370. Section - Utility Routines
  371.  
  372.        
  373. To decide whether goal (C - a planning-relation) with (P1 - an object) and (P2 - an object) is unique:
  374.     repeat through the Table of Goals begin;
  375.         if the Token entry is C and the Param1 entry is P1 and the Param2 entry is P2, decide no;
  376.     end repeat;
  377.     decide yes;
  378.  
  379. To decide whether an action was planned:
  380.     if the planned action is no-action, decide no;
  381.     decide yes;
  382.  
  383. To decide whether a goal was suggested:
  384.     if the suggested token is a planning-marker, decide no;
  385.     decide yes;
  386.  
  387. To clear the goal table:
  388.     repeat through the Table of Goals begin;
  389.         blank out the whole row;
  390.     end repeat;
  391.  
  392. To decide whether goal (C - a planning-relation) with (P1 - an object) and (P2 - an object) is true:
  393.     change the desired relation to C;
  394.     change the desired param1 to P1;
  395.     change the desired param2 to P2;
  396.     consider the planning-testing rules;
  397.     if rule succeeded begin;
  398.         decide yes;
  399.     end if;
  400.     decide no;
  401.  
  402. To decide whether goal (C - a planning-relation) with (P1 - an object) and (P2 - an object) is false:
  403.     if goal C with P1 and P2 is true, decide no;
  404.     decide yes;
  405.  
  406.  
  407.  
  408. Section - Debugging Verbs
  409.  
  410. To decide if debugging planner:
  411.     if planner verbosity is 1, decide yes;
  412.     decide no;
  413.  
  414. Enabling the planner verbosity is an action out of world.
  415. Understand "plans on" as enabling the planner verbosity.
  416. Understand "plans" as enabling the planner verbosity.
  417. Carry out enabling the planner verbosity:
  418.  change the planner verbosity to 1;
  419. Report enabling the planner verbosity:
  420.  say "Planner will now show debugging messages. Type 'plans off' to run silently, or 'plans list' to show the current planning table.";
  421.  
  422. Disabling the planner verbosity is an action out of world.
  423. Understand "plans off" as disabling the planner verbosity.
  424. Carry out disabling the planner verbosity:
  425.  change the planner verbosity to 0;
  426. Report disabling the planner verbosity:
  427.  say "Planner will now run silently.";
  428.  
  429.  
  430. Dumping the planner table is an action out of world.
  431. Understand "plans list" as dumping the planner table.
  432. Carry out dumping the planner table:
  433.     let G be 0;
  434.     repeat through the Table of Goals begin;
  435.         increase G by 1;
  436.         say "Goal [G] (parent [the Parent entry] plan [the Plan entry] step [the Step entry]): [the Token entry] / [the Param1 entry] / [the Param2 entry][line break]";
  437.     end repeat;
  438.  
  439. Justifying the current goal is an action out of world.
  440. Understand "plans justify" as justifying the current goal.
  441. Carry out justifying the current goal:
  442.  let G be the number of filled rows in the Table of Goals;
  443.  while G is greater than 1 begin;
  444.    choose row G in the Table of Goals;
  445.    say "Goal [G] : [the Token entry] / [the Param1 entry] / [the Param2 entry] to make [line break]";
  446.    let G be the Parent entry;
  447.  end while;
  448.  choose row 1 in the Table of Goals;
  449.  say "Goal 1 : [the Token entry] / [the Param1 entry] / [the Param2 entry][line break]"
  450.  
  451.  
  452. Volume 2 - Basic Plans
  453.  
  454.  
  455. Section - Relations
  456.  
  457. Being-in is a planning-relation.
  458.  
  459. Planning-testing when the desired relation is being-in (this is the basic testing being in rule):
  460.     if the desired param1 is in the desired param2, rule succeeds;
  461.     rule fails;
  462.  
  463. [Using 'best route' for now. For more complex pathfinding through lockable doorways, we may need to do things the
  464. hard way.]
  465.  
  466. Planning when the desired relation is being-in and the desired param1 is the planning actor and the desired param2 is a room (this is the basic travel with best route rule):
  467.     plan 1;
  468.     let here be the location of the planning actor;
  469.     let the way be the best route from here to the desired param2;
  470.     let the next room be the room the way from here;
  471.     if the next room is a room, suggest doing-going with the way;
  472.     rule succeeds;
  473.  
  474.  
  475. Planning-testing when the desired relation is being-in and the desired param1 is a portable thing and the desired param1 is not a person and the desired param2 is a room (this is the basic dropping objects in rooms rule):
  476.     plan 1;
  477.     suggest being-carried-by with the desired param1 and the planning actor;
  478.     suggest being-in with the planning actor and the desired param2;
  479.     suggest doing-dropping with the desired param1;
  480.     rule succeeds;
  481.  
  482.  
  483. Planning when the desired relation is being-in and the desired param1 is a portable thing and the desired param2 is a container (this is the basic putting things in containers rule):
  484.     plan 1;
  485.     suggest being-carried-by with the desired param1 and the planning actor;
  486.     suggest being-open with the desired param2;
  487.     suggest being-touchable-by with the desired param2 and the planning actor;
  488.     suggest doing-putting-in with the desired param1 and the desired param2;   
  489.     rule succeeds;
  490.    
  491.  
  492.  
  493. Being-open is a planning-relation.
  494.  
  495. Planning-testing when the desired relation is being-open (this is the basic testing being open rule):
  496.     if the desired param1 is open, rule succeeds;
  497.     rule fails;
  498.  
  499. Planning when the desired relation is being-open and the desired param1 is openable (this is the basic opening rule):
  500.     plan 1;
  501.     suggest being-unlocked with the desired param1;
  502.     suggest being-touchable-by with the desired param1 and the planning actor;
  503.     suggest doing-opening with the desired param1;
  504.     rule succeeds;
  505.  
  506. Being-closed is a planning-relation.
  507.  
  508. Planning-testing when the desired relation is being-closed (this is the basic testing being closed rule):
  509.     if the desired param1 is closed, rule succeeds;
  510.     rule fails;
  511.  
  512. Planning when the desired relation is being-closed and the desired param1 is openable (this is the basic closing rule):
  513.     plan 1;
  514.     suggest being-unlocked with the desired param1;
  515.     suggest being-touchable-by with the desired param1 and the planning actor;
  516.     suggest doing-closing with the desired param1;
  517.     rule succeeds;
  518.  
  519. Being-locked is a planning-relation.
  520.  
  521. Planning-testing when the desired relation is being-locked (this is the basic testing being locked rule):
  522.     if the desired param1 is not lockable, rule fails;
  523.     if the desired param1 is locked, rule succeeds;
  524.     rule fails;
  525.  
  526. Planning when the desired relation is being-locked and the desired param1 is lockable (this is the basic locking rule):
  527.     plan 1;
  528.     suggest being-carried-by with the matching key of the desired param1 and the planning actor;
  529.     suggest being-touchable-by with the desired param1 and the planning actor;
  530.     suggest doing-locking-with with the desired param1 and the matching key of the desired param1;
  531.     rule succeeds;
  532.  
  533.  
  534. Being-unlocked is a planning-relation.
  535.  
  536. Planning-testing when the desired relation is being-unlocked (this is the basic being unlocked rule):
  537.     if the desired param1 is not lockable, rule succeeds;
  538.     if the desired param1 is unlocked, rule succeeds;
  539.     rule fails;
  540.  
  541.  
  542. Planning when the desired relation is being-unlocked and the desired param1 is lockable (this is the basic unlocking rule):
  543.     plan 1;
  544.     suggest being-carried-by with the matching key of the desired param1 and the planning actor;
  545.     suggest being-touchable-by with the desired param1 and the planning actor;
  546.     suggest doing-unlocking-with with the desired param1 and the matching key of the desired param1;
  547.     rule succeeds;
  548.  
  549.  
  550. Section - Finding Objects
  551.  
  552.  
  553. Being-visible-by is a planning-relation.
  554.  
  555. Planning-testing when the desired relation is being-visible-by (this is the basic being visible rule):
  556.     if the desired param2 can see the desired param1, rule succeeds;
  557.     rule fails;
  558.  
  559. Planning when the desired relation is being-visible-by (this is the basic finding visibility rule):
  560.     plan 1;
  561.     suggest being-touchable-by with the desired param1 and the desired param2;
  562.     rule succeeds;
  563.  
  564.  
  565. Being-touchable-by is a planning-relation.
  566.  
  567. Planning-testing when the desired relation is being-touchable-by (this is the basic being touchable rule):
  568.     if the desired param1 carries the desired param2, rule succeeds;
  569.     if the desired param2 cannot touch the desired param1, rule fails;
  570.     if a person encloses the desired param1, rule fails;
  571.     rule succeeds;
  572.  
  573. [If it's loose in a room, go to it.]
  574.  
  575. Planning when the desired relation is being-touchable-by and the holder of the desired param1 is a room (this is the basic touching loose objects rule) :
  576.     plan 1;
  577.     suggest being-in with the desired param2 and the holder of the desired param1;
  578.     rule succeeds;
  579.  
  580. [For containers and supporters, find the outermost one. Make sure containers are open. In case the triggering
  581. mechanism of a container is elsewhere or requires finding a key, require it open before finding it - the standard
  582. openability plans will require touchability anyway.]
  583.  
  584. Planning when the desired relation is being-touchable-by and the holder of the desired param1 is a container (this is the basic touching contained objects rule):
  585.     plan 1;
  586.     suggest being-open with the holder of the desired param1;
  587.     suggest being-touchable-by with the holder of the desired param1 and the desired param2;
  588.     rule succeeds;
  589.  
  590. Planning when the desired relation is being-touchable-by and the desired param1 is a thing and the holder of the desired param1 is a supporter (this is the basic touching supported objects rule):
  591.     plan 1;
  592.     suggest being-touchable-by with the holder of the desired param1 and the desired param2;
  593.     rule succeeds;
  594.  
  595. [There's always two sides to a door, so we have to run two parallel plans. Whichever side is reachable and closest
  596. will be the one we go to.]
  597.  
  598. Planning when the desired relation is being-touchable-by and the desired param1 is a door (this is the basic touching doors rule):
  599.     plan 1;
  600.     suggest being-in with the desired param2 and the front side of the desired param1;
  601.     plan 2;
  602.     suggest being-in with the desired param2 and the back side of the desired param1;
  603.     rule succeeds;
  604.  
  605. [For now we'll treat visibility like touchability, since a touchable thing is always visible.]
  606.    
  607.  
  608. Being-carried-by is a planning-relation.
  609.  
  610. Planning-testing when the desired relation is being-carried-by (this is the basic being carried rule):
  611.     if the desired param2 carries the desired param1, rule succeeds;
  612.     rule fails;
  613.  
  614. Planning when the desired relation is being-carried-by and the desired param1 is portable and the desired param2 is the planning actor (this is the basic carrying rule):
  615.     plan 1;
  616.     suggest being-touchable-by with the desired param1 and the planning actor;
  617.     suggest doing-taking with the desired param1;
  618.     rule succeeds;
  619.  
  620. Being-worn-by is a planning-relation.
  621.  
  622. Planning-testing when the desired relation is being-worn-by (this is the basic being worn rule):
  623.     if the desired param2 wears the desired param1, rule succeeds;
  624.     rule fails;
  625.  
  626. Planning when the desired relation is being-worn-by and the desired param2 is the planning actor (this is the basic wearability rule):
  627.     plan 1;
  628.     suggest being-carried-by with the desired param1 and the planning actor;
  629.     suggest doing-wearing with the desired param1;
  630.     rule succeeds;
  631.  
  632. Being-not-worn-by is a planning-relation.
  633.  
  634. Planning-testing when the desired relation is being-not-worn-by:
  635.     if the desired param1 is worn by the desired param2, rule fails;
  636.     rule succeeds;
  637.  
  638. Planning when the desired relation is being-not-worn-by and the desired param2 is the planning actor:
  639.     plan 1;
  640.     suggest doing-taking-off with the desired param1;
  641.  
  642.  
  643. Section - Actions
  644.  
  645.  
  646. Doing-going is a planning-action.
  647.  
  648. Planning-acting when the planned action is doing-going (this is the basic executing going rule):
  649.     try the planning actor trying going the planned param1;
  650.  
  651.  
  652. Doing-opening is a planning-action.
  653.  
  654. Planning-acting when the planned action is doing-opening (this is the basic executing opening rule):
  655.     try the planning actor trying opening the planned param1;
  656.  
  657.  
  658. Doing-closing is a planning-action.
  659.  
  660. Planning-acting when the planned action is doing-closing (this is the basic executing closing rule):
  661.     try the planning actor trying closing the planned param1;
  662.  
  663.  
  664. Doing-taking is a planning-action.
  665.  
  666. Planning-acting when the planned action is doing-taking (this is the basic executing taking rule):
  667.     try the planning actor trying taking the planned param1;
  668.  
  669.  
  670. Doing-dropping is a planning-action.
  671.  
  672. Planning-acting when the planned action is doing-dropping (this is the basic executing dropping rule):
  673.     try the planning actor trying dropping the planned param1;
  674.  
  675. Doing-putting-in is a planning-action.
  676.  
  677. Planning-acting when the planned action is doing-putting-in (this is the basic executing inserting rule):
  678.     try the planning actor trying inserting the planned param1 into the planned param2;
  679.  
  680. Doing-locking-with is a planning-action.
  681.  
  682. Planning-acting when the planned action is doing-locking-with (this is the basic executing locking rule):
  683.     try the planning actor trying locking the planned param1 with the planned param2;
  684.  
  685.  
  686. Doing-unlocking-with is a planning-action.
  687.  
  688. Planning-acting when the planned action is doing-unlocking-with (this is the basic executing unlocking rule):
  689.     try the planning actor trying unlocking the planned param1 with the planned param2;
  690.  
  691.  
  692. Doing-wearing is a planning-action.
  693.  
  694. Planning-acting when the planned action is doing-wearing (this is the basic executing wearing rule):
  695.     try the planning actor trying wearing the planned param1;
  696.  
  697.  
  698. Doing-taking-off is a planning-action.
  699.  
  700. Planning-acting when the planned action is doing-wearing (this is the basic executing taking off rule):
  701.     try the planning actor trying taking off the planned param1;
  702.  
  703.  
  704. Volume 3 - Game
  705.  
  706. Section - Setup
  707.  
  708.  
  709. Echoing command is a truth state that varies. Echoing command is true.
  710.  
  711. Setting command echo on is an action out of world applying to nothing.
  712. Understand "echo on" as setting command echo on.
  713. Carry out setting command echo on: now echoing command is true.
  714. Report setting command echo on: say "[bracket]Command echo is now on. Inform commands will now display >like this.[close bracket]".
  715.  
  716. Setting command echo off is an action out of world applying to nothing.
  717. Understand "echo off" as setting command echo off.
  718. Carry out setting command echo off: now echoing command is false.
  719. Report setting command echo off: say "[bracket]Command echo is now off. Presumably you have a MUD client which displays your typed lines.[close bracket]".
  720.  
  721. After reading a command: if echoing command is true, say ">[the player's command]".
  722.  
  723.  
  724. Player joining:
  725.  say "Welcome to Boxworld. This is a demonstration and testbed for Planner. Now compiled for 5Z71. Realtime support is now turned on, at the moment this means that the tracing verbs PLANS ON/OFF do not work, which is probably no great loss, but PLANS LIST (dump the plan table) and PLANS JUSTIFY (show the reasoning behind the currently chosen action) do. ECHO ON/OFF toggles Zork-like command echo.";
  726.  
  727. Player joining:
  728.  if exactly one PC is connected, request real-time events every 10 seconds.
  729.  
  730. Player leaving:
  731.  if exactly one PC is connected, stop real-time events.
  732.  
  733.  
  734. Section - World
  735.  
  736. The Factory is a room. The description of the Factory is "A pristine factory floor with gleaming robotics hardware all around. A ramp leads east and another south. A roller door labelled 'Fairhaven' is open in the west wall."
  737.  
  738. Before going west in the Factory:
  739.  say "You close the book, your research complete.";
  740.  send the player to "Fairhaven";
  741.  stop the action.
  742.  
  743. The Library is east of the Factory. The description of the Library is "Walls are stacked floor-to-ceiling with shiny data cassettes."
  744.  
  745. A metal table is a supporter in the Library.
  746.  
  747. A plastic bench is a supporter in the factory. "A plastic bench, in glowing Moonbase Retro, fills half of the room."
  748.  
  749. A bucket is an open container on the plastic bench.
  750.  
  751. A storage unit is a closed openable container in the factory. "A gleaming storage unit quietly blends into the corner."
  752.  
  753. A plastic bag is a closed transparent portable openable container on the metal table.
  754.  
  755. A Chinese puzzle box is a locked lockable closed openable portable container in the plastic bag.
  756.  
  757. A pinch of ginger is a portable thing in the puzzle box.
  758.  
  759. A wicker basket is an open container in the storage unit.
  760.  
  761. An onion, a tomato, a stick of celery, a lemon and a banana are in the wicker basket.
  762.  
  763. Nanites is a thing.
  764.  
  765. Procedural rule when the desired relation is being-in and the desired param1 is nanites and the desired param2 is the bucket:
  766.     ignore the basic putting things in containers rule;
  767.  
  768. Planning when the desired relation is being-in and the desired param1 is nanites and the desired param2 is the bucket:
  769.     plan 1;
  770.     suggest being-in with the onion and the bucket;
  771.     suggest being-in with the celery and the bucket;
  772.     suggest being-in with the banana and the bucket;
  773.     suggest being-in with the ginger and the bucket;
  774.  
  775. To decide whether soup is brewing:
  776.     if the onion is not in the bucket, decide no;
  777.     if the celery is not in the bucket, decide no;
  778.     if the banana is not in the bucket, decide no;
  779.     if the ginger is not in the bucket, decide no;
  780.     decide yes;
  781.  
  782.  
  783. Real-time event when soup is brewing:
  784.     tell "SCIENCE occurs." to everyone who can see the bucket;
  785.     repeat with item running through things in the bucket begin;
  786.         remove item from play;
  787.     end repeat;
  788.     now nanites is in the bucket;
  789.  
  790. The Alcove is a room.
  791.  
  792. The Alcove is south of the factory. The description of the Alcove is "A tiny niche lasered out of asteroid rock, which opens out to the north."
  793.  
  794. A brass hook is a supporter in the Alcove. "Screwed into the stonework with grim determination is a shiny brass hook." The brass hook has carrying capacity 1.
  795.  
  796. A silver key is on the brass hook. The matching key of the Chinese puzzle box is the silver key.
  797.  
  798.  
  799.  
  800. Bob is a person in the factory. "The robot Bob potters around his domain."
  801.  
  802. Procedural rule when the desired relation is being-in and the desired param1 is a person:
  803.     ignore the basic dropping objects in rooms rule;
  804.  
  805. Real-time event:
  806.     have Bob plan an action for being-in with nanites and the bucket;
  807.  
  808.  
  809.  
  810. Section - Custom Actions
  811.  
  812. Doing-asking-for is a planning-action.
  813.  
  814. Planning-acting when the planned action is doing-asking-for:
  815.     try the planning actor trying asking the planned param1 for the planned param2;
  816.  
  817. Planning rule when the desired relation is being-touchable-by and the desired param2 is the planning actor and a person (called the owner) encloses the desired param1:
  818.     plan 1;
  819.     suggest being-touchable-by with the owner and the planning actor;
  820.     suggest doing-asking-for with the owner and the desired param1;
  821.  
  822.  
  823. [Allow giving objects to actors.]
  824.  
  825. The block giving rule is not listed in any rulebook.
  826.  
  827.  
  828. Section - Custom Messages
  829.  
  830. Instead of Bob trying asking a PC for something:
  831.  change the action success flag to 1;
  832.  tell "Bob says: 'Request: actor: [the noun]: provide object: [the second noun].'" to everyone who can see Bob;
  833.  
  834. Planning-failure:
  835.  tell "Bob says: 'Error: no known action Malfunction! Malfunction!'" to everyone who can see Bob;
  836.  
  837. Planning-success:
  838.   end the game saying "Experiment complete";   
  839.  
  840. Planning-acting-failure:
  841.  tell "'Bob says: 'Error: unexpected response to action. Danger! Danger! My arms are flailing wildly!'" to everyone who can see Bob;
  842.  
  843. Report Bob trying opening the storage unit :
  844.   tell "Bob opens the storage unit, revealing [a list of things in the storage unit]." to everyone who can see Bob;
  845.   stop the action;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement