GAMELAND

Note: this assignment is structured on the excellent material prepared by Andrew Blair, from UNSW, for the cs3411 subject "Artifical Intelligence". But where as Dr. Blair uses JAVA, we will use LISP.

For this project you will be implementing an agent to play a simple text-based adventure game. The agent is required to move around a rectangular environment, collecting tools and avoiding (or removing) obstacles along the way. The obstacles and tools within the environment are represented as follows:

Obstacles  Tools
B big bad bush      a axe
-doorkkey
*wallddynamite
~waterggold

Note: bushes are impassible (big, bad, thorns, posionious).

The agent will be represented by one of the characters ^, v, <  or  >, depending on which direction it is pointing. The agent is capable of the following instructions:

L   turn left
R   turn right
F   (try to) move forward
C   (try to) chop down a bush, using an axe
O   (try to) open a door, using a key
B   (try to) blast a wall, door or bush, using dynamite

When it executes an L or R instruction, the agent remains in the same location and only its direction changes. When it executes an F instruction, the agent attempts to move a single step in whichever direction it is pointing. The F instruction will fail (have no effect) if there is a wall, bush or door directly in front of the agent; if the agent moves forward into the water, it will fall in and drown.

When the agent moves to a location occupied by a tool, it automatically picks up the tool. The agent may use a C, O or B instruction to remove an obstacle immediately in front of it, if it is carrying the appropriate tool. A bush may be removed with a C (chop) instruction, if an axe is held. A door may be removed with an O (open) instruction, if a key is held. A wall, bush or door may be removed with a B (blast) instruction, if dynamite is held.

Note:

To win the game, the agent must pick up the gold and then return to its initial location.

Running

cd trunk
make edit  # emacs starts
M-x slime ; slime starts
(load "iccle")
(make 'game) ; the game loads

Then, to test the game, use

(test-stagger)

at which point, 10 times the agent walks to a random place. You should then see something like this:

~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***     ***   ~~
~~*-*     v     *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***  v  ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   *** v   ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***  v  ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***     ***   ~~
~~*-*     v     *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***     ***   ~~
~~*-*      v    *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***   v ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***    v***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B     B   k ~~
~~   ***   v ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~     B   v B   k ~~
~~   ***     ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~v~~~~~~~~~
~~     B   ~ B   k ~~
~~   ***     ***   ~~
~~*-*           *-*~~
~~  **         **  ~~
~~ g **   d   ** a ~~
~~    BB     BB    ~~
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~

(Note that I've just drowned- that's a bug you need to fix.)

Two Modes

The code should run in two modes:

Under the hood, the two modes share the same code. If you look at lib/game/stagger.lisp we see that the actual move function is

(defun stagger1 (board)
  (move-to (any (empty-neighbors board)) board))

Breaking that down, we can guess that

So if we replace any with a function (say) what2do-batch or what2do-interactive, then you've implemented the two modes (so both modes just look at the list of current neighbors, and returns on them).

Now how that is done is up to you but here are some "might be good ideas" that you could try:

We'll call this explore, not stagger cause one day soon, this will stop roaming around drunkedly:

(defun explore (board &optional (what2do #'what2do=any))
  (move-to (funcall what2do (empty-neighbors board) board) 
           board))

(defun what2do=any (options board)
   (declare (ignore board)) ; smarter schemes would NOT ignore the board
    (any options))

(defun what2do=interactive (options board)
   (format t "Enter action: ")
   (let ((what2do (read)))
     (if (cando? what2do board)
         ; then return the right option
         ; else, print error and call this function recursively
    )))

(defun what2do=batch (options board)
  (let ((what-do-you-see    (feature-extraction     board))
        (what-can-you-do    (match what-do-you-see  board))
        (what-is-best-to-do (select what-can-you-do board)))
    (act what-is-best-to-do)))
Writing an Agent

You may assume that the environment is no larger than 80 by 80, and that it is totally surrounded by water, so there is no confusion about where the environment begins and ends.

Additional examples of input and output files will be provided in the directory lib/game/eg.