Practicas de computacion
El robot plano en un mundo cuadriculado bidimensional
Nombre: Carlos López ZarateFecha: 26/04/10
Objetivo
Conocer, utilizar y modificar la implementación de un robot reactivo plano en un mundo bidimensional en Common Lisp.
Introducción
Los agentes reactivos son aquellos que, como su nombre lo indica, sólo reaccionan a los cambios en el mundo en el que se encuentran.Realizan funciones de percepción, con el fin de determinar las condiciones actuales de medio ambiente, y funciones de actuación, que determinan qué acciones debe ejecutar el agente ante diferentes situaciones del mundo.
En esta práctica utilizaremos una implementación en Common Lisp del robot plano en un mundo bidimensional propuesto por Nilsson en el capítulo 2, Sistemas Reactivos, de su librode texto Inteligencia Artificial, Una Nueva Síntesis.
Actividades
1. Captura el siguiente código de Common Lisp:
;; Archivo: mundo_plano.lsp
;; Implementa un agente reactivo en un mundo plano bidimensional.
;; Se define un mundo de 6 renglones x 8 columnas.
(setq *alto* 6)
(setq *ancho* 8)
;; Se indica la posición inicial del robot plano
(setq *x* 1)
(setq *y* 1)
(defundefine-mundo ()
(setf *mundo* (make-array (list *alto* *ancho*) :initial-contents
'( (0 0 0 0 0 0 0 0)
(0 0 0 1 0 0 0 0)
(0 0 1 1 1 0 0 0)
(0 1 1 1 1 1 0 0)
(0 0 0 1 1 0 0 0)
(0 0 0 0 0 0 0 0))
) )
)
(defun despliega-mundo()
(format t "~% 0 1 2 3 4 5 6 7")
(format t "~%0 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref *mundo* 0 0) (aref *mundo* 01) (aref *mundo* 0 2) (aref *mundo* 0 3) (aref *mundo* 0 4) (aref *mundo* 0 5) (aref *mundo* 0 6) (aref *mundo* 0 7))
(format t "~%1 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref *mundo* 1 0) (aref *mundo* 1 1) (aref *mundo* 1 2) (aref *mundo* 1 3) (aref *mundo* 1 4) (aref *mundo* 1 5) (aref *mundo* 1 6) (aref *mundo* 1 7))
(format t "~%2 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref *mundo* 2 0)(aref *mundo* 2 1) (aref *mundo* 2 2) (aref *mundo* 2 3) (aref *mundo* 2 4) (aref *mundo* 2 5) (aref *mundo* 2 6) (aref *mundo* 2 7))
(format t "~%3 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref *mundo* 3 0) (aref *mundo* 3 1) (aref *mundo* 3 2) (aref *mundo* 3 3) (aref *mundo* 3 4) (aref *mundo* 3 5) (aref *mundo* 3 6) (aref *mundo* 3 7))
(format t "~%4 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref*mundo* 4 0) (aref *mundo* 4 1) (aref *mundo* 4 2) (aref *mundo* 4 3) (aref *mundo* 4 4) (aref *mundo* 4 5) (aref *mundo* 4 6) (aref *mundo* 4 7))
(format t "~%5 ~a ~a ~a ~a ~a ~a ~a ~a"
(aref *mundo* 5 0) (aref *mundo* 5 1) (aref *mundo* 5 2) (aref *mundo* 5 3) (aref *mundo* 5 4) (aref *mundo* 5 5) (aref *mundo* 5 6) (aref *mundo* 5 7))
(terpri)
)
;; Funciones para "sensar"las celdas que rodean una celda dada.
(defun s1 (x y)
(cond ((or (= x 0) (= y 0) ) -1)
(t (aref *mundo* (1- x) (1- y))) ) )
(defun s2 (x y)
(cond ((= x 0) -1)
(t (aref *mundo* (1- x) y)) ) )
(defun s3 (x y)
(cond ((or (= x 0) (= y (1- *ancho*))) -1)
(t (aref *mundo* (1- x) (1+ y))) ) )
(defun s4 (x y)
(cond ((= y 0) -1)
(t (aref *mundo* x (1- y))) ) )(defun s5 (x y)
(cond ((= x (1- *alto*)) -1)
(t (aref *mundo* x (1+ y))) ) )
(defun s6 (x y)
(cond ((or (= x (1- *alto*)) (= y 0)) -1)
(t (aref *mundo* (1+ x) (1- y))) ) )
(defun s7 (x y)
(cond ((= x (1- *alto*)) -1)
(t (aref *mundo* (1+ x) y)) ) )
(defun s8 (x y)
(cond ((or (= x (1- *alto*)) (= y (1- *ancho*))) -1)
(t (aref *mundo* (1+ x) (1+ y))) ) )
;;Funciones que agrupan la información del ambiente para facilitar la
;; decisión de la acción a realizar.
(defun x1 (x y)
(or (= (s2 x y) 1) (= (s3 x y) 1)) )
(defun x2 (x y)
(or (= (s5 x y) 1) (= (s8 x y) 1)) )
(defun x3 (x y)
(or (= (s6 x y) 1) (= (s7 x y) 1)) )
(defun x4 (x y)
(or (= (s1 x y) 1) (= (s4 x y) 1)) )
;; Funciones que implementan las acciones del robot
(defun...
Regístrate para leer el documento completo.