For Demonstration Purposes
Example 239
★★★Suppose we want to have a character who can dynamically learn new actions by observing the player performing them. We could do this by adding the actions to a list of things the character can do, but using a relation to express the same idea allows for tidier, easier-to-read code.
Thanks to Jesse McGrew for the initial design of this example.
"For Demonstration Purposes"
Section 1 - Procedure
Capability relates various people to various stored actions. The verb to be capable of means the capability relation.
Persuasion rule:
let CA be the current action with no specific actor;
if the person asked is capable of CA:
persuasion succeeds;
otherwise:
say "[The person asked] look[s] confused. Maybe a demonstration would help.";
persuasion fails.
The action requester is an object that varies. The action requester variable is defined by Inter as "act_requester".
To decide which action is the current action with no specific actor:
let old actor be the person asked;
let old requester be the action requester;
now the person asked is the player;
now the action requester is nothing;
let CA be the current action;
now the person asked is the old actor;
now the action requester is the old requester;
decide on CA.
The learning by observation rule is listed after the report stage rule in the specific action-processing rules.
Definition: a person is other if he is not the player.
This is the learning by observation rule:
repeat with the viewer running through other people who can see the player:
if the player is the actor and viewer is not capable of the current action:
say "[The viewer] watches your behavior with interest. Seems like [they] [are] learning.";
now the viewer is capable of the current action.
Section 2 - Scenario
The Daily Planet is a room. Clark is here. He is a man.
When play begins:
now Clark is capable of taking inventory.
Test me with "Clark, inventory / Clark, x me / x me / Clark, x me".
Test me with "Clark, inventory / Clark, x me / x me / Clark, x me".
Daily Planet
You can see Clark here.
Clark watches your behavior with interest. Seems like he is learning.
>(Testing.)
>[1] clark, inventory
Clark looks through his possessions.
>[2] clark, x me
Clark looks confused. Maybe a demonstration would help.
>[3] x me
As good-looking as ever.
Clark watches your behavior with interest. Seems like he is learning.
>[4] clark, x me
Clark looks closely at yourself.
You can see Clark here.
Clark watches your behavior with interest. Seems like he is learning.
>(Testing.)
>[1] clark, inventory
Clark looks through his possessions.
>[2] clark, x me
Clark looks confused. Maybe a demonstration would help.
>[3] x me
As good-looking as ever.
Clark watches your behavior with interest. Seems like he is learning.
>[4] clark, x me
Clark looks closely at yourself.