Assistance: Artificial Intelligence

I’m writing a story with an AI which controls the entire environment (which itself is artificial, much like the Matrix). The player character can “teleport” from environment to environment within this artificial environment through interactions with the computer. The PC can talk to the AI much like the computer in Star Trek.

I have included Inanimate Listeners by Emily Short and the unsuccessful persuasion of inanimate objects rule is not listed in the rule book.

I have struck a brickwall when it comes to asking the AI to teleport the PC with a line like:

Computer, let's go to the beach.

I was wondering if there is any work around you guys can think of; I think I am just fixated on the wrong element. I really want all actions beyond the physical interaction of the PC (such as walking in the new environment and taking objects) to be handled by the AI.

Another thing, is there a way to resent the environment back to the start of game after so many turns? So the PC has taken an apple from the table and after four turns the apple is back on the table?

Any help would be appreciated with this.

Thanks,
Sean Stark

With the AI thing, what you may want to do is make the AI an actual NPC that is a backdrop “everywhere” (if Inform allows that) or is connected to an everywhere backdrop, or even part of the player. The best route for this will depend on what you’re doing. That way the player can talk to the AI as if it were a person and Inform will handle a lot of that heavy lifting.

Then, you can direct requests to the AI to trigger rules.

[pseudocode - not tested]

[code]Shodan is a woman. Shodan is part of the player.

teleporting is an action applying to any room. Understand “teleport to [a room]” “let’s go to [a room]” “teleport us to [a room]” as teleporting.

Persuasion rule for asking shodan to try teleporting:
rule succeeds.

Check teleporting to:
say “You don’t have teleportation powers. You’ll have to ask your AI friend to do that.” instead.

Check an actor teleporting to:
if the person asked is Shodan:
say “I h-h-hear you, insec-c-c-t.”;
otherwise:
say “[The person asked] shrugs. ‘I don’t know how to do that!’” instead.

Carry out an actor teleporting to:
now the location is the noun.

Report an actor teleporting to:
say “Everything whooshes and you are now in [the location].”[/code]

As far as resetting everything…if you have a lot of moving parts that is going to be a bear of a task. When play begins you can repeat through every object in the game and give it an initial location variable, then when you want to reset, repeat through every object in the game and move it to that location. This sounds tricky and fraught with peril. (Once again, example code not tested…)

[code]A thing can have a thing called primeloc. The primeloc of a thing is usually nothing. [I think??]

When play begins:
repeat with candidate running through portable things:
now the primeloc of candidate is the container of candidate.

To reset props:
repeat with candidate running through portable things:
move candidate to the primeloc of candidate.[/code]

That could be a very hairy task, and will probably work better with a small game. I re-read your initial post and it might work okay since it sounds like you’re using small resettable environments like a holodeck. You could manually specify where everything goes and then reset the environment singly when the player exits it.

The trick I did in Baker of Shireton to reset the entire world was to literally force the game to restart without the player’s input. Then I used Emily Short’s “Recorded Endings” extension to remember certain things about what the player has done that I wanted to carry over and be “permanent”. There is a routine when play begins that looks at the recorded endings and rearranges things based on what the player has done. I also provided a GAME RESET function so the player could start completely over and wipe out the recorded endings.

For example, if the player acquired the dagger, the when play begins rules looks for the “bought dagger” ending (they’re called endings, but I was invoking them in many places where the game didn’t end) and if it exists, it moves the dagger to the player’s inventory at the beginning of the game. (This was a very specific “groundhog day” type effect that actually I patched in post release when I figured out people were more likely to undo when they died instead of starting over and it worked much better for my nefarious purposes.)

On posting: OK, Hanon already said most of this, but here’s some tested code.

What part are you hitting a brick wall with? If it’s making the computer omnipresent, you can use Inanimate Listeners to make an addressable backdrop:

[code]Include Inanimate Listeners by Emily Short.

The computer is an addressable backdrop. it is everywhere.

Persuasion rule for asking the computer to try opening a door:
persuasion succeeds.

Instead of the computer opening a door:
now the noun is unlocked;
now the noun is open;
say “The computer unseals and opens [the noun].”;
rule succeeds.

The Lab is a room. The Bridge is a room. The Bay is a room.
The Lab Gate is a closed locked door. The Lab gate is outside from the lab and inside from the bridge.
The Bay Lock is a closed locked door. The Bay Lock is outside from the bridge and inside from the bay.

Test me with “go through lab gate/open lab gate/computer, open lab gate/go through lab gate/open bay lock/computer, open bay lock/go through bay lock”.[/code]

If the problem is the “let’s go to the beach” part, you can write an After reading a command rule to cut out the word “let’s.”

If it’s making the actions be handled by the AI… well, you just to have to write rules for what the player does and what the computer does.

For the question about resetting the environment, one approach is to give a bunch of things an initial location or holder and move them back to it at the appropriate time. You could try adding this to the code I just posted:

[code]A thing has an object called the initial holder.

The table is in the Lab. The initial holder of the table is the Lab. The beaker is on the table. The initial holder of the beaker is the table. The unresettable thingy is in the Lab.

After jumping:
say “Your eyes close for a second as you land, and when you open them, things look subtly different.”;
repeat with the item running through things:
if the initial holder of the item is not nothing and the player does not enclose the item:
move the item to the initial holder of the item;
try looking.

test reset with “take beaker/computer, open gate/enter gate/jump/i/drop beaker/l/jump/enter gate”.[/code]

The reset message is pretty bad, though, you’d want to program a better one that accounted for things suddenly appearing and disappearing.

[Thank you, Matt; my brain so couldn’t put this into absolutes earlier! - Hanon]

I did mention that I had Emily Shorts Innate Listeners enabled in the first post. Just tried out both your suggestions. The problem with the AI is that it keeps thinking I want to talk with her instead of asking her to do something. “There is no reply”.

As for the reset idea by Matt, well it doesn’t remove the item from the PC’s inventory. The idea is that the world can only be altered for a short amount of time, about a couple of turns and then resets to where it was. This artificial environment can’t be altered in significant ways for long.

Also, just to clarify. The rooms the PC will be teleporting to can only be accessed through teleportation as these are not truly rooms but in fact whole environments. There is a house, a warehouse, a beach etc.

This is probably because you aren’t putting in commands that Inform recognizes after the “computer,” part. If you type “computer, let’s open the gate” then you’ll get a “There is no reply” response, because “let’s open the gate” isn’t a valid command, so Inform treats this as an attempt to talk to the computer rather than to give it a command.

Specifically, if the first word after the comma is a valid verb, Inform will try to parse it as a command, and then try to parse it as an attempt to talk. If not, it’ll start out by parsing it as an attempt to talk. This is basically impossible to override. You could allow for the word “let’s” by including the following code, which just cuts “let’s” from the player’s command before processing:

After reading a command: if the player's command includes "let's": cut the matched text.

However, you will need to teach the player the valid command format somehow.

[code[As for the reset idea by Matt, well it doesn’t remove the item from the PC’s inventory. The idea is that the world can only be altered for a short amount of time, about a couple of turns and then resets to where it was. This artificial environment can’t be altered in significant ways for long.[/code]

Yeah, I put in a line of code that let the player keep their inventory for some reason. If you want their inventory to reset too, just change “if the initial holder of the item is not nothing and the player does not enclose the item:” to “if the initial holder of the item is not nothing:”.

Also, Hanon’s idea of automatically setting the primeloc at the beginning was better than mine–saves typing. A couple things though–you need to say “holder of” rather than “container of,” and it’s a good idea to make an adjective to keep some things from being reset–specifically, you probably don’t want the player to get reset. Also, I put in real tab stops. So we get:

[code]A thing has a object called primeloc. The primeloc of a thing is usually nothing. [I think??]
A thing can be resettable or unresettable. A thing is usually resettable. The player is unresettable.

When play begins:
repeat with candidate running through portable things:
now the primeloc of candidate is the holder of candidate.

To reset props:
repeat with candidate running through portable resettable things:
move candidate to the primeloc of candidate.[/code]

This shouldn’t be a problem. Just write a teleporting action, understood by “teleport to [any room],” and write rules to allow the computer to do it. I mostly had the computer unsealing gates because in this code example it was simpler to use a built-in action.

I’m not sure if you can do anything but talk to inanimate listeners. That’s why I suggested making the AI an NPC/scenery so it can actually carry out commands as well.

I think persons in Inform are usually not considered portable, so unless you have portable unresettable items, you might not need that if it’s just for the player.

The reset works quite well except for the implementation of it.

If the player carries something for 4 turns: say "Suddenly the world shifts and everything returns to where it was before. You are reminded you cannot alter this fake world."; reset props.
How to I fix this?

As for the asking the AI to do something instead of talking to her, I don’t think it has anything to do with the parcing of let’s. I took that out and just it changed to:

Understand "go to [a room]" as teleporting to.

And she still thinks I’m chatting to her.

This doesn’t have a proper rule heading, so Inform doesn’t know when to check this condition. Make it an “Every Turn” rule:

Every turn when the player carries something for 4 turns: say "Suddenly the world shifts and everything returns to where it was before. You are reminded you cannot alter this fake world."; reset props.

(Note that if the player drops everything and then picks it up again, it’ll reset the four-turn counter.)

The problem is that the “[a room]” token only applies to rooms that are in scope, and by default no rooms are in scope. You need to use the “[any room]” token so Inform will know to try to match the command against every single room name:

[code]Teleporting is an action applying to one visible thing. Understand “teleport me/-- to [any room]” as teleporting.

Instead of teleporting: say “You cannot do that yourself. Ask the computer to teleport you.”

Instead of the computer teleporting:
say “The computer says, ‘Acknowleged.’”;
now the player is in the noun.[/code]

See §17.7 of Writing with Inform about [any] tokens.

Hanon, I didn’t expect people to be portable, but when I tried it it reset the player, so I figured it was better to put in the flag. And in the code I have, you can get the computer to carry out commands, though I don’t know if there’s some fragility to that… though the extension documentation does specifically mention using persuasion rules to allow the inanimate listener to respond to commands, so it should be OK.

Cool. This all works now. Thanks for the help guys!

By default everything is portable unless declared otherwise, including the player. It’s a bit of an oddity, but other rules prevent taking the player or NPCs, so it seldom comes up.

You can change it if you want: A person is usually fixed in place.