Blocks World
Worksheet 2
Name ____________________
Here are the new questions:
5. Assign instance names for each object.
Two different methods to do this:
A. Assign each individually: (setf table 'table brick1 'brick1 etc)
B. Use dolist and "set" (like setf except that it evaluates both
arguments) (dolist (element *blocks*)
(set (block-name element) element))
6. Fill in the support-for and supported-by slots.
A. The table has all the objects (in a list), except for table, in
its support-for slot
B. All the objects, except table, have the table in their
supported-by slot
Use dolist on the list in which table has been removed.
Use the forms -- (push element (block-support-for table))
(setf ( . . . ) table)
7. Define a variable using defvar for *hand*. Use make-instance,
name is *hand* and position is (0 6)
8. Define a constructor , MAKE-BLOCK, that creates blocks with ordinary
arguments rather than key arguments. With your new constructor, the
following will do the same thing:
* (make-instance 'wedge:name 'w5
:width 2
:height 2
:position '(10,0))
* (make-block 'wedge 'w5 2 2 10 0)
9. The initialization of the blocks worlds is awkward because no procedures
for moving blocks have been introduced. So we must pick places on the
table for each block by hand. Anticipating the PUT-ON procedure, which
arranges for all BLOCK-SUPPORT-FOR and BLOCK-SUPPORTED-BY slots to be
properly maintained, initialize the blocks world in another way.
If you only have a hammer, you tend to see every problem as a nail.
-- Maslow
Here are the answers you had for the last worksheet.
(defclass basic-block ()
((name :accessor block-name :initarg :name)
(width :accessor block-width :initarg :width)
(height :accessor block-height :initarg :height)
(position :accessor block-position :initarg :position :initform '(0 0))
(supported-by :accessor block-supported-by :initform nil)))
(defclass movable-block (basic-block) ())
(defclass load-bearing-block (basic-block)
((support-for :accessor block-support-for :initform nil)))
(defclass brick (movable-block load-bearing-block) ())
(defclass wedge (movable-block) ())
(defclass ball (movable-block) ())
(defclass table (load-bearing-block) ())
(defclass hand ()
((name :accessor hand-name :initarg :name)
(position :accessor hand-position :initarg :position)
(grasping :accessor hand-grasping :initform nil))
)
(devar *blocks*
(list
(make-instance 'table :name 'table :width 20 :height 0 :position '(0 0))
(make-instance 'brick :name 'b1 :width 2 :height 2 :position '(0 0))
(make-instance 'brick :name 'b2 :width 2 :height 2 :position '(2 0))
(make-instance 'brick :name 'b3 :width 4 :height 4 :position '(4 0))
(make-instance 'brick :name 'b4 :width 2 :height 2 :position '(8 0))
(make-instance 'wedge :name 'w5 :width 2 :height 4 :position '(10 0))
(make-instance 'brick :name 'b6 :width 4 :height 2 :position '(12 0))
(make-instance 'wedge :name 'w7 :width 2 :height 2 :position '(16 0))
(make-instance 'ball :name 'l8 :width 2 :height 2 :position '(18 0))
)
)