Introduction to Artificial Intelligence

Homework 2
Due: Sept. 16

Contents

The Story

I turned to my guide, who was frozen with terror.

``Pasquale. Calm down. It's just a statue.''

``No sir, it's not. You don't know what you're getting yourself into. The ancient gods have been awakened.''

``Look, Pasquale, I've been awakening ancient gods all my life. It's my job. They call my service before they go to sleep and tell us when to wake them up.''

Pasquale looked at me strangely.

``Senior. This is no laughing matter. You are about to trespass into the otherworld.''

``What other world?''

``No, the otherworld. It's a place. It's guarded by demons and beasts. Terrible things happen to mortals who dare enter, and you risk wakening the ancients and threating the whole human race.''

``OK. Just point me in the right direction.''

Pasquale turned and ran. Having had some exeperience with this type of thing, I figured he was running away from the otherworld as opposed to towards it, so I proceeded in the opposite direction from Pasquale.

It didn't take long for the jungle to become nearly impassable. Pasquale had taken the machete with him, and so I was left to hacking at the undergrowth with my pocketknife, which had already become quite dull. I finally broke through a particularly thick section, and came upon a cave entrance. Over the entrance was a sign printed in heiroglyphics.

I took out my Newton and unsealed the weatherproofing. I had a nearly complete reference for this written language, and only one of the characters was unknown to me. Without it, the sign read, ``Now Entering new-symbol. Discard your soul. No smoking.'' Based on Pasquale's fears, I inferred the new symbol to be the one for ``otherworld.'' I noted it, tossed aside my cigar, and entered.

It was some time before I reached the main chamber of the cave, keeping a careful map on the screen of my Newton. I had averted numerous traps of the standard variety already, and ducked low as another pendulum swung for my head. The rotting beam that the device was suspended from broke, however, sending it crashing into the altar. This activated a series of traps at once, and as I dove and rolled to avoid the flying projectiles, I slid over a trap door and fell.

I fell for a while, and felt sure the landing would kill me, but suddenly there was an intensely strong updraft that nearly stopped my descent, and I landed on something hard. I picked myself up, and the lights came on.

I was standing in a huge chamber. On one end was a gallery teeming with numerous beasts and demons, and on the other were five huge stone thrones. Sitting in each throne was a humanoid figure that would have stood fifty feet tall. At first glance the throned figures seemed to be statues, but their eyes betrayed life.

``Welcome,'' the central figure spoke. His voice boomed and echoed through the chamber.

I pointed to myself questioningly.

``Yes, you. You have awakened us. We are the ancient gods.''

I cleared my throat. ``YOU are the ancients? '' I pointed to the demonic rabble on the other end. ``Wow, I thought they were. You guys look great. I wouldn't have guessed a day over thirty.''

``Oh, thank you. Of course, several thousand years of sleep does wonders for the complexion.''

``Ahhhh. Of course. I don't suppose a few thousand more would help?''

``I am K'thalm'g'ra'tu,'' he continued.

I hastily began jotting on my Newton, and held up my hand. ``Just hold on a second, I have to use letter by letter recognition...'' The gods looked puzzled for a moment. ``OK,'' I said. ``Do you have a Phone number?''

``We are bound by the laws of our imprisonment to offer you a challenge. If you fail, we will be released. If you succeed, we must return to our beauty rest until the next obnoxious bozo stumbles upon us.''

``Right, right. Challenge, uh-huh,'' I mumbled, still entering information on my notepad. ``There we go. What about an email address?''

``SILENCE MORTAL!'' yelled one of the other ancient gods.

``There is a labyrinth below this chamber,'' K'thalm'g'ra'tu continued, oblivious. ``We will provide you with a chariot. However, you may not leave the chariot and it only understands the ancient language L'sp. You must speak to it, command it, to find your way out. That is your challenge, but you don't have much time, the deadly Blaarnog will be chasing you."

Another trap door was opened and I fell into an odd looking vehicle. It was round, with a smaller round appendage in front. Inside there was a bizzare looking terminal screen and a keyboard with hieroglyphics on the keys. I hit a few keys and the screen came to life. I quickly ascertained that L'sp was actually a control language similar to LISP in most respects. I set about discovering the functionality of my chariot, and quickly sent off a message to the home office via my Newtons cellular email link:

The Project

Help! The world is doomed unless you can write some LISP functions to help guide my chariot through a labyrinth.

You must write a function (or functions) that implement a branch and bound search algorithm for trees (this algorithm is referred to as "GRAPHSEARCH" on page 141 of the AI book).

graphsearch initial-state expand-fn goalp-fn lessp-fn result-fn [Function]
This function should perform a branch and bound search starting at the initial-state provided. The three function parameters provide names of functions that can be used to generate the successors (children), a predicate that tests a state to see if it is a goal, a function for comparing two states to see which is better - for use with the sort or merge functions in Common LISP, and a function to be evaluated on the solution state. More complete descriptions of these functions are given below. When the solution state is found, the graphsearch function should evaluate the result-fn on the solution state, and return what that function returns. If no solution can be found, the graphsearch function should return nil.

Functions to pass in for these parameters will be provided by me:

expand-fn state lessp-fn [Function]
The expand-fn variable to the graphsearch function will be the name of a function (to be used with funcall or apply) that takes one argument, a state, and returns a list of states that represent the children or successor nodes of state. The list of states that is returned will be sorted from best to worst according to the lessp-fn described below. If the state has no children, this function should (and may) return nil.

goalp-fn state [Function]
The goalp-fn variable to the graphsearch function will be the name of a predicate function (to be used with funcall or apply) that takes one argument, a state, and returns non-nil if the state is a goal node (a solution node), and nil otherwise.

lessp-fn state1 state2 [Function]
The lessp-fn variable to the graphsearch function (and to the expand-fn) will be the name of a predicate function (to be used with sort or merge) that takes two arguments, both states, and returns T if the first state (state1) is less than (that is, from the perspective of the domain, better than) the second (state2).

result-fn state [Function]
The result-fn variable to the graphsearch function will be the name of a function that takes one argument, a state, and prints out and returns information meaningful to the domain if state is a solution node.

Deliverables

You must submit in the AI course dropbox a file named yourname-hw2.lisp. This file should contain your function or functions for the graphsearch algorithm. Your main function must be called graphsearch, and must take the parameters as defined above.

You are encouraged, but not required, to use loop in your function.

Document your function with any special characteristics, decisions you made during the implementation, etc.

Domain functions for the blaarnog domain will be provided to you to test your search function. Check here for availability.