Surfaces: New method for examining objects

14 views
Skip to first unread message

Phil Goetz

unread,
Sep 29, 1996, 3:00:00 AM9/29/96
to

I've developed what I think is a better method of dealing with lighting,
and of determining what you can and cannot see of an object. It
treats an object as having an inside and an outside. This is important
with objects like cars that the player can be either inside or outside of.
The following excerpt from the assignment for my Prolog class explains it:


Today's assignment is to finish implementing a system for examining objects.
The goals are to develop the following predicates, in order:

los(A,B): Succeeds if A and B are in line of sight of each other.
lit(SURFACE): Succeeds if SURFACE is lit by (is LOS to) a light source.
cansee(AGENT,SURFACE): Succeeds if AGENT can see SURFACE.
dox(Actor, Obj): Prints the appropriate response when the actor tries
to view the object.

+--------------Garage----------------+
| |
| +-------+ |
| ^^ | |
| O \ \/ / |-- |
| ____|-\___ \___/ | \ |
| / \ \ +----------/ |
| +-O-----O--/ O O |
+------------------------------------+

In case the above is not perfectly clear:
Jim, the Fahrvergnugen-looking guy, is in the (open) convertible.
Reynold the fox is in an open basket which is in the (open) truck.

We want the following results from los/2:

Reynold can see the outside of himself, the inside of the basket
and the truck, the inside of the garage, the outside of the car, the inside
of the car, and the outside of Jim.
Jim can see the outside of himself, the inside of the car and the garage,
the outside of the truck, the inside of the truck, the outside of the
basket, the inside of the basket, and the outside of Reynold.

(Actually I prefer a method that does not let Jim see inside the truck,
nor Reynold inside the car, but it's a little more complicated to explain.)

We are going to use Skolem functions to talk about the inside and outside
of things. That is, instead of creating an atom outside_of_truck that
refers to the outside of the truck, we will write `outside(truck)'.
Unification will treat this about the same as it would the string
outside_of_truck, BUT we can then write rules with variables like
`outside(X)' and know we are talking about the outside of something.

The rules we will use are as follows:

1. If X is inside Y, then the inside of Y is LOS (line-of-sight) to
the outside of X. (You can see the inside of what you're in.)

2. If Y is transparent, then everything that is LOS to the outside
of Y is also LOS to the inside of Y, and vice-versa. (You can see through
open/transparent things.)

3. If Y is open, then any X that is LOS to the outside of Y is also
LOS to the inside of Y, and vice-versa, UNLESS X is in Y or in something
that is in Y (recursive `in').

4. If OBJ is inside CONTAINER, then everything that can see inside CONTAINER
can see the outside of OBJ.

... <snip> ...


(3 pts) That was awful. Let's do something easier: Write lit/1.
This predicate takes only one line to define. lit(outside(OBJ)) succeeds
if the outside of OBJ is lit by (is LOS to) something that is a light source.
Designate that a surface X is a light source by the assertion light(X).
Note that X is not an object! light(garage) is not helpful.
light(inside(garage)) is.

lit(OBJ) :-

(3 pts) Now write cansee/2. This also takes 1 line.
cansee(outside(jim),outside(reynold)) succeeds if
1. there is a line-of-sight freom outside(jim) to outside(reynold), and
2. outsisde(reynold) is lit.

To test this predicate, add the assertion

light(inside(garage)).

to the example database, or something else appropriate to your own database.

cansee(X,Y) :-

Load the file you created last class of object descriptions.
Change them so that instead of being attached to objects,
descriptions are attached to the inside or outside of objects. For example,

desc(outside(desk), "Phil's desk has an empty bottle of ginger beer,
several dirty dishes, and a huge stack of papers, books, and magazines
threatening to collapse at any moment.").
desc(inside(desk), "Phil's desk drawer is open.").


(9 pts) Now we want to write dox/2 (do examine), a predicate that prints out
the things the player sees when he/she examines an object. This is the logic:

If the (outside of the) player can see the outside of the object, print
a description of the outside of the object.

If the (outside of the) player can see the inside of the object,
print a description of the inside of the object, then print a newline,
then print the object's name followed by the object's contents.

If neither of the above rules were satisfied, print the message
"You can't see " followed by the object's name.

Ex: ?- dox(me,desk).
Phil's desk has an empty bottle of ginger beer, several dirty dishes,
and a huge stack of papers, books, and magazines threatening to
collapse at any moment.
Phil's desk drawer is open.
Phil's desk contains the Prolog final exam.

Ex: ?- dox(me,phil_office).
You are standing in Phil's office, 335 Bell.
It looks like a street person has been living in it.
Phil's office contains Phil and a desk.


Phil Go...@cs.buffalo.edu

Reply all
Reply to author
Forward
0 new messages