You are to take an existing Prolog program and extend it to add new features.
blocks.pl
is a program that allows the user to manipulate a set of blocks on
a table. The user can place blocks on other blocks or on empty spots on the
table using natural language. A simple grammar can parse certain commands
such as "Please place block a on block b.
" or "I want a on b.
". The parser
converts these sentences into simple commands (e.g. on(a,b)
). There are also
limitations, because a block cannot be moved if it is under another block or
if you are trying to move it on top of a covered block or onto the table when
there are no free table positions. To start the read-eval-print loop, execute
"place_blocks.
" in Prolog after the appropriate files are loaded.
This assignment was changed slightly from the example described in section 7.3
of an extensive
Prolog tutorial. The assigned extensions are the same, while some details are
somewhat different (the tutorial works toward an animation which is not part of
this assignment).
Starting files: read_line.pl (must be loaded first) and blocks.pl.
(a) Formulate a new question idiom, one of whose scripts is
"What is block X sitting on?
".
(b) Formulate a new question idiom, one of whose scripts is
"Which blocks are on the table?
".
(c) Formulate a new command idiom, one of whose scripts is "Put all of the blocks in a single pile.
".
This is an interesting idiom, because the abstract meaning is ambiguous
-- that is, there could be more than one abstract meaning for this
idiom. Assume that one abstract meaning is no better or worse than
another; just generate one of them as "the" meaning.
(d) Formulate a new command idiom, one of whose scripts is "Put the block on top of X on top of block Y.
" (or on the table
). This will involve interpreting the definite description ("the ...
") acurately.
(e) Formulate a new command idiom, one of whose scripts is "Put the highest block on top of block y.
" (or on the table
). This will involve interpreting the definite description ("the ...
") acurately.
Implement a program that executes command or question text-based "scripts".
The user can type any commands or questions from the original grammar or
the extended grammar of Part 1. The scripts should allow access to the
most recently accessed block using the keyword "result
".
Basically, wherever "result
" is used, it should work as if "result
" was
replaced by the block letter that was last queried.
See script.eng for an example script.
If the setup before is
c b a d ---------then after the script is run you should have
b a d c ---------
Some notes: "result
" should be bound to the last valid block that is
the result of a question or command as follows.
What is on top of X?
", result
should be the block on
top of X
.
What is block X sitting on?
", result
should be the
block X
is sitting on.
Put the block on top of X on top of block Y.
", result
should be the block on top of X
.
Put the highest block on top of block Y.
", result should
be the highest block.
result
should remain fixed throughout other questions / commands.
result
has no initial value. result
should remain fixed if queries fail.
Input: (A) Initial locations of blocks, (B) Final locations of blocks
Assuming (A)->(B) is reachable by executing combinations of the
commands implemented in Part 1 and 2 (e.g., no blocks will disappear).
Output: The list of operations needed to change the locations of
the blocks to go from (A) to (B). For the example above, the output may look like: [on(c,table),on(b,d)]
Reading Material:
The assignment builds on an example from section 2.19 and chapter 7 of the tutorial at http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html. However, if you are new to Prolog, you might want to start with the tutorial at http://www.learnprolognow.org/. Be sure to read chapters 7 and 8 in the second tutorial which talk about natural language processing in Prolog.
Due Date:
Received Time | Grade Modification |
before Sunday, 09/14, 11:59PM | +10% |
before Monday, 09/15, 11:59PM | no modification (on time) |
before Tuesday, 09/16, 11:59PM | -10% |
before Thursday, 09/18, 11:59PM | -25% |
after Friday, 09/19, 12:00AM | not accepted |
Grading: The assignment will be graded mostly on correctness, but code clarity / readability will also be a factor (comment, comment, comment!). See the professor or TAs, if you have ideas for other extensions for this assignment and would like extra credit for implementing them.
Submission Requirements: Please submit a ZIP file with your code, including a README file. In the README file, place the names of each group member (up to two). Your README file should also have a list of specific features / bugs in your solution. Your ZIP file should be named with your LMS user name(s) as the filename, either userid1.zip or userid1_userid2.zip. Only submit one assignment per pair via LMS.