Intelligent Hinting

version 5 by Aaron Reed

Chapter - Determining the Suggested Action

To decide which stored action is the suggested action:
if Winning-The-Game is solved:
print IH message for all-puzzles-solved;
decide on the action of the person asked fake-actioning;
[we can't just assume saved endeavor because something earlier might have become incomplete.]
let puzz be next task in Winning-The-Game; [This will recurse down through required puzzles as needed.]
if puzzle-testing selection, say "(Next incomplete task: [puzz])";
if venue of puzz is not nothing and venue of puzz is not a room:
say "(Error in Intelligent Hinting puzzle definition: [puzz] has a venue of [venue of puzz], which does not seem to me to be a room.)";
decide on the action of the person asked fake-actioning;
now relevant location is venue of puzz;
let ctr be 1;
repeat with portion running through action-sequence of puzz:
if it seems portion is unfinished:
if ctr > action-position of puzz and a move is implied by portion:
decide on relevant action;
otherwise:
if puzzle-testing inferences, say "(It seems [portion] is finished; skipping)";
if action-position of puzz < ctr, increase action-position of puzz by 1;
increase ctr by 1;
if relevant location is not nothing and location is not venue of puzz:
if puzzle-testing inferences, say "([location] is not venue of [puzz] ([venue of puzz]))";
if we can move to relevant location:
decide on relevant action;
consider the red flag rules for puzz;
if the rule failed:
if puzzle-testing selection, say "(failed red flag rule)";
now relevant action is the action of the person asked waiting;
decide on relevant action;
[Deal with the command-sequence (literal strings to be tried as commands) first. To save creating a second variable to track our position in this sequence, we use negative numbers: -1 corresponds to the first command, -2 the 2nd, and so on.]
if number of entries in command-sequence of puzz > 0 and ( action-position of puzz >= number of entries in action-sequence of puzz ) or ( action-position of puzz is 0 and number of entries in action-sequence of puzz is 0 ) , now action-position of puzz is -1;
if action-position of puzz < 0 and ( -1 * action-position of puzz ) > the number of entries in command-sequence of puzz, now action-position of puzz is 0;
if action-position of puzz < 0 and the number of entries in command-sequence of puzz >= ( -1 * action-position of puzz ) :
let temppos be -1 * action-position of puzz;
if puzzle-testing selection, say "(trying step [temppos] of command-sequence)";
now relevant command is entry temppos in command-sequence of puzz;
if we are suggesting:
process appropriate action, as a command;
otherwise:
process appropriate action, as a command, actually performing;
decrease action-position of puzz by 1;
decide on the action of the person asked fake-actioning;
[If we've got a positive action-position, we must be using the more typical action-sequence.]
if action-position of puzz >= number of entries in action-sequence of puzz, now action-position of puzz is 0;
if action-position of puzz + 1 is at most the number of entries in action-sequence of puzz :
let candidate be entry ( action-position of puzz + 1 ) in action-sequence of puzz;
if candidate is entering something actionably-closed ( called portal ) :
if puzzle-testing inferences, say "(trying to enter something actionably-closed ([portal]))";
if shut portal causes surmountable difficulties:
decide on relevant action;
now relevant action is the action of the person asked opening portal;
decide on relevant action;
if candidate is inserting something into something actionably-closed ( called parent ) :
if puzzle-testing inferences, say "(trying to insert something into something actionably-closed ([portal]))";
if shut parent causes surmountable difficulties:
decide on relevant action;
now relevant action is the action of the person asked opening parent;
decide on relevant action;
if noun part of candidate is a person (called partner) and partner is not visible:
if puzzle-testing inferences, say "(trying to track down [partner])";
if we can move to location of partner:
decide on relevant action;
now relevant action is the action of the person asked waiting;
decide on relevant action;
if second noun part of candidate is a person (called partner) and partner is not visible:
if puzzle-testing inferences, say "(trying to track down [partner])";
if we can move to location of partner:
decide on relevant action;
now relevant action is the action of the person asked waiting;
decide on relevant action;
now relevant action is entry ( action-position of puzz + 1 ) in action-sequence of puzz;
unless it seems relevant action is possible:
if puzzle-testing selection, say "(it seems [relevant action] is not possible; waiting instead.)";
now relevant action is the action of the person asked waiting;
increase action-position of puzz by 1;
if puzzle-testing all, say "(action-position of [puzz] is now [action-position of puzz])";
decide on relevant action.

[ This is the good chef's rule: Before acting, ensure that we have gathered all the necessary ingredients first. If there are items we've determined are necessary to *get* the items that are necessary (like keys), deal with those first. ]

To decide whether a move is implied by (act - a stored action):
if act is going, decide no;
now relevant action is the action of the person asked fake-actioning;
now actually-down is false;
if the number of entries in macguffin-queue > 0 and steps must be taken to acquire entry ( number of entries in macguffin-queue ) of macguffin-queue, decide yes;
unless the noun part of act is nothing:
if steps must be taken to acquire noun part of act, decide yes; [Note: can't reject "taking something" at this point because steps must be taken checks for too many things held, moving to location, etc.]
unless the second noun part of act is nothing:
if steps must be taken to acquire second noun part of act, decide yes;
decide no.

[Finally, here are two routines encapsulating some common-sense knowledge about the library, used to try to guess whether something has already been solved, or whether something seems currently possible, to the best of the library's knowledge. Authors can add this knowledge for other verbs by creating new unfinished rules in their code.]

Puzz-unfinished is a rulebook.

To decide whether it seems (act - a stored action) is unfinished:
now temp-act is act;
consider the puzz-unfinished rules;
if rule failed, decide no;
decide yes.

temp-act is a stored action that varies.

A puzz-unfinished rule:
if temp-act is opening something and noun part of temp-act is open, rule fails;
if temp-act is closing something and noun part of temp-act is closed, rule fails;
if temp-act is unlocking something with something and noun part of temp-act is unlocked, rule fails;
if temp-act is locking something with something and noun part of temp-act is locked, rule fails;
if temp-act is switching on something and noun part of temp-act is switched on, rule fails;
if temp-act is switching off something and noun part of temp-act is switched off, rule fails;
if temp-act is taking something and noun part of temp-act is held, rule fails;
if temp-act is dropping something and noun part of temp-act is not held, rule fails;
if temp-act is entering something and player is enclosed by noun part of temp-act, rule fails;
if temp-act is getting off something and player is not enclosed by noun part of temp-act, rule fails;
if temp-act is trying wearing something and noun part of temp-act is worn, rule fails;
if temp-act is taking off something and noun part of temp-act is not worn, rule fails;
if temp-act is putting something on something and second noun part of temp-act encloses noun part of temp-act, rule fails;
if temp-act is removing something from something and noun part of temp-act is not enclosed by second noun part of temp-act, rule fails.

Puzz-possibility is a rulebook.

To decide whether it seems (act - a stored action) is possible:
now temp-act is act;
consider the puzz-possibility rules;
if rule failed, decide no;
decide yes.

A puzz-possibility rule:
if ( temp-act is opening something or temp-act is closing something or temp-act is switching on something or temp-act is switching off something or temp-act is taking something ) and noun part of temp-act is not touchable, rule fails;
if temp-act is unlocking something with something and ( second noun part of temp-act is not held or noun part of temp-act is not visible ) , rule fails;
if temp-act is locking something with something and ( second noun part of temp-act is not held or noun part of temp-act is not visible ) , rule fails;
if temp-act is dropping something and noun part of temp-act is not held, rule fails;
if temp-act is taking off something and noun part of temp-act is not worn, rule fails;
if temp-act is putting something on something and ( noun part of temp-act is not held or second noun part of temp-act is not visible ) , rule fails;
if temp-act is removing something from something and ( noun part of temp-act is not touchable or second noun part of temp-act is not visible ) , rule fails.